1 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
2 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev %s
3 
4 #include "Inputs/cuda.h"
5 
__anonc8cf527b0102() 6 auto global_lambda = [] () { return 123; };
7 
8 template<class F>
kernel(F f)9 __global__ void kernel(F f) { f(); }
10 // dev-note@-1 7{{called by 'kernel<(lambda}}
11 
12 __host__ __device__ void hd(int x);
13 
14 class A {
15   int b;
16 public:
test()17   void test() {
18     [=](){ hd(b); }();
19 
20     [&](){ hd(b); }();
21 
22     kernel<<<1,1>>>([](){ hd(0); });
23 
24     kernel<<<1,1>>>([=](){ hd(b); });
25     // dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
26 
27     kernel<<<1,1>>>([&](){ hd(b); });
28     // dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
29 
30     kernel<<<1,1>>>([&] __device__ (){ hd(b); });
31     // dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
32 
33     kernel<<<1,1>>>([&](){
34       auto f = [&]{ hd(b); };
35       // dev-error@-1 {{capture host side class data member by this pointer in device or host device lambda function}}
36       f();
37     });
38   }
39 };
40 
main(void)41 int main(void) {
42   auto lambda_kernel = [&]__global__(){};
43   // com-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
44 
45   int b;
46   [&](){ hd(b); }();
47 
48   [=, &b](){ hd(b); }();
49 
50   kernel<<<1,1>>>(global_lambda);
51 
52   kernel<<<1,1>>>([](){ hd(0); });
53 
54   kernel<<<1,1>>>([=](){ hd(b); });
55 
56   kernel<<<1,1>>>([b](){ hd(b); });
57 
58   kernel<<<1,1>>>([&](){ hd(b); });
59   // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
60 
61   kernel<<<1,1>>>([=, &b](){ hd(b); });
62   // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
63 
64   kernel<<<1,1>>>([&, b](){ hd(b); });
65 
66   kernel<<<1,1>>>([&](){
67       auto f = [&]{ hd(b); };
68       // dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
69       f();
70   });
71 
72   return 0;
73 }
74