[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / cxx2b-lambdas.cpp
blob9474dface2e3d82ae48e5befe9548f6a4af63a8c
1 // RUN: %clang_cc1 -std=c++2b %s -verify
3 auto LL0 = [] {};
4 auto LL1 = []() {};
5 auto LL2 = []() mutable {};
6 auto LL3 = []() constexpr {};
8 auto L0 = [] constexpr {};
9 auto L1 = [] mutable {};
10 auto L2 = [] noexcept {};
11 auto L3 = [] constexpr mutable {};
12 auto L4 = [] mutable constexpr {};
13 auto L5 = [] constexpr mutable noexcept {};
14 auto L6 = [s = 1] mutable {};
15 auto L7 = [s = 1] constexpr mutable noexcept {};
16 auto L8 = [] -> bool { return true; };
17 auto L9 = []<typename T> { return true; };
18 auto L10 = []<typename T> noexcept { return true; };
19 auto L11 = []<typename T> -> bool { return true; };
20 auto L12 = [] consteval {};
21 auto L13 = []() requires true {};
22 auto L14 = []<auto> requires true() requires true {};
23 auto L15 = []<auto> requires true noexcept {};
24 auto L16 = [] [[maybe_unused]]{};
26 auto XL0 = [] mutable constexpr mutable {}; // expected-error{{cannot appear multiple times}}
27 auto XL1 = [] constexpr mutable constexpr {}; // expected-error{{cannot appear multiple times}}
28 auto XL2 = []) constexpr mutable constexpr {}; // expected-error{{expected body of lambda expression}}
29 auto XL3 = []( constexpr mutable constexpr {}; // expected-error{{invalid storage class specifier}} \
30 // expected-error{{function parameter cannot be constexpr}} \
31 // expected-error{{a type specifier is required}} \
32 // expected-error{{expected ')'}} \
33 // expected-note{{to match this '('}} \
34 // expected-error{{expected body}} \
35 // expected-warning{{duplicate 'constexpr'}}
37 // http://llvm.org/PR49736
38 auto XL4 = [] requires true {}; // expected-error{{expected body}}
39 auto XL5 = []<auto> requires true requires true {}; // expected-error{{expected body}}
40 auto XL6 = []<auto> requires true noexcept requires true {}; // expected-error{{expected body}}
42 auto XL7 = []() static static {}; // expected-error {{cannot appear multiple times}}
43 auto XL8 = []() static mutable {}; // expected-error {{cannot be both mutable and static}}
44 auto XL9 = []() static consteval {};
45 auto XL10 = []() static constexpr {};
47 auto XL11 = [] static {};
48 auto XL12 = []() static {};
49 auto XL13 = []() static extern {}; // expected-error {{expected body of lambda expression}}
50 auto XL14 = []() extern {}; // expected-error {{expected body of lambda expression}}
53 void static_captures() {
54 int x;
55 auto SC1 = [&]() static {}; // expected-error {{a static lambda cannot have any captures}}
56 auto SC4 = [x]() static {}; // expected-error {{a static lambda cannot have any captures}}
57 auto SC2 = [&x]() static {}; // expected-error {{a static lambda cannot have any captures}}
58 auto SC3 = [y=x]() static {}; // expected-error {{a static lambda cannot have any captures}}
59 auto SC5 = [&y = x]() static {}; // expected-error {{a static lambda cannot have any captures}}
60 auto SC6 = [=]() static {}; // expected-error {{a static lambda cannot have any captures}}
61 struct X {
62 int z;
63 void f() {
64 [this]() static {}(); // expected-error {{a static lambda cannot have any captures}}
65 [*this]() static {}(); // expected-error {{a static lambda cannot have any captures}}