1 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s
5 constexpr int id(int n) { return n; }
12 []; // expected-error {{expected body of lambda expression}}
13 [+] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
14 [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
15 [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}}
16 [&this] {}; // expected-error {{'this' cannot be captured by reference}}
17 [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
18 [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
21 [&] (int) mutable -> void {};
22 [foo,bar] () { return 3; };
26 [] () -> class C { return C(); };
27 [] () -> enum E { return e; };
29 [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}}
30 [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}}
31 [](int) -> {}; // PR13652 expected-error {{expected a type}}
35 void designator_or_lambda() {
40 int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from '(lambda}}
41 int a2[1] = {[b] = 1 };
42 int a3[1] = {[b,c] = 1 }; // expected-error{{expected ']'}} expected-note {{to match}}
43 int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}}
44 int a5[3] = { []{return 0;}() };
45 int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}}
46 int a7[1] = {[d(0)] { return d; } ()}; // expected-warning{{extension}}
47 int a8[1] = {[d = 0] { return d; } ()}; // expected-warning{{extension}}
48 int a9[1] = {[d = 0] = 1}; // expected-error{{is not an integral constant expression}}
49 int a10[1] = {[id(0)] { return id; } ()}; // expected-warning{{extension}}
50 int a11[1] = {[id(0)] = 1};
53 void delete_lambda(int *p) {
55 delete [] (int*) { new int }; // ok, compound-literal, not lambda
56 delete [] { return new int; } (); // expected-error{{expected expression}}
57 delete [&] { return new int; } (); // ok, lambda
60 // We support init-captures in C++11 as an extension.
63 [n(0)] () mutable -> int { return ++n; }; // expected-warning{{extension}}
64 [n{0}] { return; }; // expected-warning{{extension}}
65 [n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}} expected-warning{{extension}}
66 [n = {0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}}
67 [a([&b = z]{})](){}; // expected-warning 2{{extension}}
70 auto y = [&r = x, x = x + 1]() -> int { // expected-warning 2{{extension}}
77 [] [[]] {}; // expected-error {{lambda requires '()' before attribute specifier}}
78 [] __attribute__((noreturn)) {}; // expected-error {{lambda requires '()' before attribute specifier}}
80 mutable {}; // expected-error {{expected body of lambda expression}}
84 []() mutable [[]] -> void {};
85 []() mutable noexcept [[]] -> void {};
87 // Testing GNU-style attributes on lambdas -- the attribute is specified
88 // before the mutable specifier instead of after (unlike C++11).
89 []() __attribute__((noreturn)) mutable { while(1); };
91 __attribute__((noreturn)) { while(1); }; // expected-error {{expected body of lambda expression}}
97 [](int) -> {}; // expected-error {{expected a type}}
100 template void PR22122<int>();
103 template <typename T>
104 void m (T x =[0); // expected-error{{expected variable name or 'this' in lambda capture list}}
108 template <typename T>
109 void m_fn1(T x = 0[0); // expected-error{{expected ']'}} expected-note{{to match this '['}}