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
4 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'int (__private int){{.*}} const __generic'
5 auto glambda = [](auto a) { return a; };
9 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
10 auto llambda = [&]() {i++;};
13 // Test lambda with default parameters
14 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
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
24 (*(__constant decltype(llambda) *)nullptr)(); //expected-error{{multiple address spaces specified for type}}
25 (*(decltype(llambda) *)nullptr)();
28 __kernel void test_qual() {
29 //CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __private'
30 auto priv1 = []() __private {};
32 //CHECK: |-CXXMethodDecl {{.*}} constexpr operator() 'void () {{.*}}const __generic'
33 auto priv2 = []() __generic {};
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))'}}
39 //expected-note@35{{conversion candidate of type 'void (*)()'}}
41 priv3(); //expected-error{{no matching function for call to object of type}}
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))'}}
47 //expected-note@43{{conversion candidate of type 'void (*)()'}}
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))'}}
54 //expected-note@50{{conversion candidate of type 'void (*)()'}}
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{};
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'}}
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}}
69 [&] () mutable __private {} ();
70 [&] () __private mutable {} (); //expected-error{{expected body of lambda expression}}