Douglas Gregor | 7f99f43 | 2012-02-09 01:02:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 2 | |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 3 | enum E { e }; |
| 4 | |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 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}} |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 15 | [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} |
| 16 | [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}} |
Douglas Gregor | b326ca8 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 17 | [] {}; |
| 18 | [=] (int i) {}; |
| 19 | [&] (int) mutable -> void {}; |
| 20 | [foo,bar] () { return 3; }; |
| 21 | [=,&foo] () {}; |
| 22 | [&,foo] () {}; |
| 23 | [this] () {}; |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 24 | [] () -> class C { return C(); }; |
| 25 | [] () -> enum E { return e; }; |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 26 | |
Douglas Gregor | c9ecec4 | 2012-02-16 21:53:36 +0000 | [diff] [blame] | 27 | [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}} |
| 28 | [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}} |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 29 | return 1; |
| 30 | } |
| 31 | |
Douglas Gregor | b3f323d | 2012-02-17 03:49:44 +0000 | [diff] [blame] | 32 | void designator_or_lambda() { |
| 33 | typedef int T; |
| 34 | const int b = 0; |
| 35 | const int c = 1; |
| 36 | int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from 'C::<lambda}} |
| 37 | int a2[1] = {[b] = 1 }; |
| 38 | int a3[1] = {[b,c] = 1 }; // expected-error{{expected body of lambda expression}} |
| 39 | int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}} |
| 40 | int a5[3] = { []{return 0;}() }; |
| 41 | int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}} |
| 42 | } |
Douglas Gregor | ae7902c | 2011-08-04 15:30:47 +0000 | [diff] [blame] | 43 | }; |