Trying to make use of some C++20 features in my code, I stumbled across the following behavior:
int foo(auto a)
{
auto x = [] __device__ __host__ (int b)
{
return b;
};
return x(a);
}
int main()
{
return foo(2);
}
This code results in a compiler error (Godbolt link):
<source>: In function 'int foo(auto:11)':
<source>:3:70: error: 'auto' parameter not permitted in this context
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:86: error: invalid use of 'auto' in template argument
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:97: error: template argument 2 is invalid
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:99: error: template argument 3 is invalid
3 | auto x = [] __device__ __host__ (int b)
| ^
ASM generation compiler returned: 1
<source>: In function 'int foo(auto:11)':
<source>:3:70: error: 'auto' parameter not permitted in this context
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:86: error: invalid use of 'auto' in template argument
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:97: error: template argument 2 is invalid
3 | auto x = [] __device__ __host__ (int b)
| ^
<source>:3:99: error: template argument 3 is invalid
3 | auto x = [] __device__ __host__ (int b)
| ^
Execution build compiler returned: 1
Is this a limitation of extended lambdas, or a bug in nvcc? If this is a limitation, I assume it is similar to this case here:
int main()
{
auto foo = [](auto a)
{
auto x = [] __device__ __host__ (int b)
{
return b;
};
return x(a);
};
return foo(2);
}
which results in (Godbolt):
<source>(5): error: An extended __host__ __device__ lambda cannot be defined inside a generic lambda expression("operator()").
1 error detected in the compilation of "<source>".
ASM generation compiler returned: 2
<source>(5): error: An extended __host__ __device__ lambda cannot be defined inside a generic lambda expression("operator()").
1 error detected in the compilation of "<source>".
Execution build compiler returned: 2
In that case, it would be nice to have a similarly descriptive error message, as opposed to the current one.