Debian Codegraph @

clang/test/SemaOpenCLCXX/address-space-lambda.clcpp

raw
1 //RUN: %clang_cc1 %s -pedantic -ast-dump -verify | FileCheck %s
2 //RUN: %clang_cc1 %s -pedantic -ast-dump -verify -triple i386-windows | FileCheck %s
3
4 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'int (__private int){{.*}} const __generic'
5 auto glambda = [](auto a) { return a; };
6
7 __kernel void test() {
8 int i;
9 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
10 auto llambda = [&]() {i++;};
11 llambda();
12 glambda(1);
13 // Test lambda with default parameters
14 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
15 [&] {i++;} ();
16 __constant auto err = [&]() {}; //expected-note{{candidate function not viable: 'this' object is in address space '__constant', but method expects object in address space '__generic'}}
17 err(); //expected-error-re{{no matching function for call to object of type '__constant (lambda at {{.*}})'}}
18 // FIXME: There is very limited addr space functionality
19 // we can test when taking lambda type from the object.
20 // The limitation is due to addr spaces being added to all
21 // objects in OpenCL. Once we add metaprogramming utility
22 // for removing address spaces from a type we can enhance
23 // testing here.
24 (*(__constant decltype(llambda) *)nullptr)(); //expected-error{{multiple address spaces specified for type}}
25 (*(decltype(llambda) *)nullptr)();
26 }
27
28 __kernel void test_qual() {
29 //CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __private'
30 auto priv1 = []() __private {};
31 priv1();
32 //CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
33 auto priv2 = []() __generic {};
34 priv2();
35 auto priv3 = []() __global {}; //expected-note{{candidate function not viable: 'this' object is in address space '__private', but method expects object in address space '__global'}}
36 #if defined(_WIN32) && !defined(_WIN64)
37 //expected-note@35{{conversion candidate of type 'void (*)() __attribute__((thiscall))'}}
38 #else
39 //expected-note@35{{conversion candidate of type 'void (*)()'}}
40 #endif
41 priv3(); //expected-error{{no matching function for call to object of type}}
42
43 __constant auto const1 = []() __private{}; //expected-note{{candidate function not viable: 'this' object is in address space '__constant', but method expects object in address space '__private'}}
44 #if defined(_WIN32) && !defined(_WIN64)
45 //expected-note@43{{conversion candidate of type 'void (*)() __attribute__((thiscall))'}}
46 #else
47 //expected-note@43{{conversion candidate of type 'void (*)()'}}
48 #endif
49 const1(); //expected-error{{no matching function for call to object of type '__constant (lambda at}}
50 __constant auto const2 = []() __generic{}; //expected-note{{candidate function not viable: 'this' object is in address space '__constant', but method expects object in address space '__generic'}}
51 #if defined(_WIN32) && !defined(_WIN64)
52 //expected-note@50{{conversion candidate of type 'void (*)() __attribute__((thiscall))'}}
53 #else
54 //expected-note@50{{conversion candidate of type 'void (*)()'}}
55 #endif
56 const2(); //expected-error{{no matching function for call to object of type '__constant (lambda at}}
57 //CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __constant'
58 __constant auto const3 = []() __constant{};
59 const3();
60
61 [&] () __global {} (); //expected-error{{no matching function for call to object of type '(lambda at}} expected-note{{candidate function not viable: 'this' object is in default address space, but method expects object in address space '__global'}}
62 [&] () __private {} (); //expected-error{{no matching function for call to object of type '(lambda at}} expected-note{{candidate function not viable: 'this' object is in default address space, but method expects object in address space '__private'}}
63
64 [&] __private {} (); // expected-error{{no matching function for call to object of type '(lambda at}} expected-note{{candidate function not viable: 'this' object is in default address space, but method expects object in address space '__private'}}
65 #if __cplusplus <= 202002L
66 // expected-warning@-2{{lambda without a parameter clause is a C++23 extension}}
67 #endif
68
69 [&] () mutable __private {} ();
70 [&] () __private mutable {} (); //expected-error{{expected body of lambda expression}}
71 }
72