126f4b32fSDouglas Gregor // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s 2db0b9f12SDouglas Gregor 3bfdb108fSRichard Smith enum E { e }; 4bfdb108fSRichard Smith 5db0b9f12SDouglas Gregor class C { 6db0b9f12SDouglas Gregor 7db0b9f12SDouglas Gregor int f() { 8db0b9f12SDouglas Gregor int foo, bar; 9db0b9f12SDouglas Gregor 10db0b9f12SDouglas Gregor []; // expected-error {{expected body of lambda expression}} 11db0b9f12SDouglas Gregor [+] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 12db0b9f12SDouglas Gregor [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}} 13db0b9f12SDouglas Gregor [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}} 14db0b9f12SDouglas Gregor [&this] {}; // expected-error {{'this' cannot be captured by reference}} 15db0b9f12SDouglas Gregor [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 16db0b9f12SDouglas Gregor [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} 17656bc62aSDouglas Gregor [] {}; 18656bc62aSDouglas Gregor [=] (int i) {}; 19656bc62aSDouglas Gregor [&] (int) mutable -> void {}; 20656bc62aSDouglas Gregor [foo,bar] () { return 3; }; 21656bc62aSDouglas Gregor [=,&foo] () {}; 22656bc62aSDouglas Gregor [&,foo] () {}; 23656bc62aSDouglas Gregor [this] () {}; 24bfdb108fSRichard Smith [] () -> class C { return C(); }; 25bfdb108fSRichard Smith [] () -> enum E { return e; }; 26db0b9f12SDouglas Gregor 276746c5d4SDouglas Gregor [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}} 286746c5d4SDouglas Gregor [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}} 29*b3afa6c4SRichard Smith [](int) -> {}; // PR13652 expected-error {{expected a type}} 30db0b9f12SDouglas Gregor return 1; 31db0b9f12SDouglas Gregor } 32db0b9f12SDouglas Gregor 33a80cae11SDouglas Gregor void designator_or_lambda() { 34a80cae11SDouglas Gregor typedef int T; 35a80cae11SDouglas Gregor const int b = 0; 36a80cae11SDouglas Gregor const int c = 1; 37a80cae11SDouglas Gregor int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from 'C::<lambda}} 38a80cae11SDouglas Gregor int a2[1] = {[b] = 1 }; 39a80cae11SDouglas Gregor int a3[1] = {[b,c] = 1 }; // expected-error{{expected body of lambda expression}} 40a80cae11SDouglas Gregor int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}} 41a80cae11SDouglas Gregor int a5[3] = { []{return 0;}() }; 42a80cae11SDouglas Gregor int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}} 43a80cae11SDouglas Gregor } 4410c6072dSRichard Smith 4510c6072dSRichard Smith void delete_lambda(int *p) { 4610c6072dSRichard Smith delete [] p; 4710c6072dSRichard Smith delete [] (int*) { new int }; // ok, compound-literal, not lambda 4810c6072dSRichard Smith delete [] { return new int; } (); // expected-error{{expected expression}} 4910c6072dSRichard Smith delete [&] { return new int; } (); // ok, lambda 5010c6072dSRichard Smith } 51db0b9f12SDouglas Gregor }; 52