blob: 87d14051e92c778750e0da8bd10c0a92842eeba9 [file] [log] [blame]
Douglas Gregor7f99f432012-02-09 01:02:27 +00001// RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -verify -std=c++11 %s
Douglas Gregorae7902c2011-08-04 15:30:47 +00002
3class C {
4
5 int f() {
6 int foo, bar;
7
8 []; // expected-error {{expected body of lambda expression}}
9 [+] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
10 [foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
11 [foo,&this] {}; // expected-error {{'this' cannot be captured by reference}}
12 [&this] {}; // expected-error {{'this' cannot be captured by reference}}
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000013 [&,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
14 [=,] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
Douglas Gregorb326ca82012-02-09 08:26:42 +000015 [] {};
16 [=] (int i) {};
17 [&] (int) mutable -> void {};
18 [foo,bar] () { return 3; };
19 [=,&foo] () {};
20 [&,foo] () {};
21 [this] () {};
Douglas Gregorae7902c2011-08-04 15:30:47 +000022
Douglas Gregorc9ecec42012-02-16 21:53:36 +000023 [] -> int { return 0; }; // expected-error{{lambda requires '()' before return type}}
24 [] mutable -> int { return 0; }; // expected-error{{lambda requires '()' before 'mutable'}}
Douglas Gregorae7902c2011-08-04 15:30:47 +000025 return 1;
26 }
27
Douglas Gregorb3f323d2012-02-17 03:49:44 +000028 void designator_or_lambda() {
29 typedef int T;
30 const int b = 0;
31 const int c = 1;
32 int a1[1] = {[b] (T()) {}}; // expected-error{{no viable conversion from 'C::<lambda}}
33 int a2[1] = {[b] = 1 };
34 int a3[1] = {[b,c] = 1 }; // expected-error{{expected body of lambda expression}}
35 int a4[1] = {[&b] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'const int *'}}
36 int a5[3] = { []{return 0;}() };
37 int a6[1] = {[this] = 1 }; // expected-error{{integral constant expression must have integral or unscoped enumeration type, not 'C *'}}
38 }
Douglas Gregorae7902c2011-08-04 15:30:47 +000039};
40