1 // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s 2 3 enum E { e }; 4 5 class C { 6 7 int f() { 8 int foo, bar; 9 10 []; // expected-error {{expected body of lambda expression}} 11 [+] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 12 [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} 13 [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}} 14 [&this] {}; // expected-error {{'this' cannot be captured by reference}} 15 [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 16 [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 17 [] {}; 18 [=] (int i) {}; 19 [&] (int) mutable -> void {}; 20 [foo,bar] () { return 3; }; 21 [=,&foo] () {}; 22 [&,foo] () {}; 23 [this] () {}; 24 [] () -> class C { return C(); }; 25 [] () -> enum E { return e; }; 26 27 [] [[fake_ident]] { while (1) ; }; // expected-error {{lambda requires '()' before attribute specifier}} expected-warning {{unknown attribute 'fake_ident' ignored}} 28 [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}} 29 [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}} 30 [](int) -> {}; // PR13652 expected-error {{expected a type}} 31 return 1; 32 } 33 34 void designator_or_lambda() { 35 typedef int T; 36 const int b = 0; 37 const int c = 1; 38 int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from '<lambda}} 39 int a2[1] = {[b] = 1 }; 40 int a3[1] = {[b,c] = 1 }; // expected-error{{expected body of lambda expression}} 41 int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}} 42 int a5[3] = { []{return 0;}() }; 43 int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}} 44 } 45 46 void delete_lambda(int *p) { 47 delete [] p; 48 delete [] (int*) { new int }; // ok, compound-literal, not lambda 49 delete [] { return new int; } (); // expected-error{{expected expression}} 50 delete [&] { return new int; } (); // ok, lambda 51 } 52 53 // We support init-captures in C++11 as an extension. 54 int z; 55 void init_capture() { 56 [n(0)] () mutable -> int { return ++n; }; // expected-warning{{extension}} 57 [n{0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}} 58 [n = 0] { return ++n; }; // expected-error {{captured by copy in a non-mutable}} expected-warning{{extension}} 59 [n = {0}] { return; }; // expected-error {{<initializer_list>}} expected-warning{{extension}} 60 [a([&b = z]{})](){}; // expected-warning 2{{extension}} 61 62 int x = 4; 63 auto y = [&r = x, x = x + 1]() -> int { // expected-warning 2{{extension}} 64 r += 2; 65 return x + 2; 66 } (); 67 } 68 }; 69