I do not understand the behaviour of the following code:
template< bool b >
struct Foo {
Foo() = default;
__host__ Foo( const Foo & ) requires( b ) {}
__device__ Foo( const Foo & ) requires( !b ) {}
};
template< typename Lambda >
__global__
void kernel( Lambda ) {}
int main() {
Foo< true > foo;
auto la = [foo] __device__ (){ };
kernel<<< 1, 1 >>>( la );
}
When I compile it with nvcc 12.1 and gcc 11.3 as host compiler (nvcc main.cu -std=c++20 --expt-extended-lambda
) I get two errors
-
copy constructor for class "Foo<true>" is ambiguous auto la = [foo] __attribute__((device)) (){ }; ^
-
function "lambda []()->void::<unnamed>(const lambda []()->void &)" (declared implicitly) cannot be referenced -- it is a deleted function kernel<<< 1, 1 >>>( la ); ^
I do not understand both errors.
- Why is the copy ctor ambigious?
- Which function is deleted at all and at what place wanted the compiler use it?