Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generic lambda as function parameter fails to be converted to pointer to function #53836

Closed
nickhuang99 opened this issue Feb 15, 2022 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@nickhuang99
Copy link

See compiler explorer (https://www.godbolt.org/z/GGxKoYGsx) both GCC and MSVC accepts the following code. Clange rejects by giving error of conversion lambda. According to standard, generic lambda should still be convertible to function pointer which is defined by type decltype(+[](T t )->T{return t+1;})


template<typename T>
auto foo(T t, decltype(+[](T t )->T{return t+1;}) lam){
	return lam(t);
}
void test(){
	foo<int>(5, [](int t){return t+1;});
}

clang13 giving error of


:8:2: error: no matching function for call to 'foo'
        foo(5, [](int t){return t+1;});
        ^~~~~~~~
 note: candidate function [with T = int] not viable: no known conversion from '(lambda at :8:14)' to 'decltype(+[](int t) -> int {
    return t + 1;
})' for 2nd argument
auto foo(T t, decltype(+[](T t )->T{return t+1;}) lam){
     ^
1 error generated.
Compiler returned: 1
@nickhuang99 nickhuang99 changed the title lambda as function parameter fails to be converted to function pointer generic lambda as function parameter fails to be converted to pointer to function Feb 15, 2022
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Feb 15, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 15, 2022

@llvm/issue-subscribers-clang-frontend

@cor3ntin
Copy link
Contributor

This is fixed https://www.godbolt.org/z/MsThM8jdT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants