blob: c69aa115beb5e710d8dd2b460c4feaf9e2029d0e [file] [log] [blame]
Douglas Gregor73456262012-02-09 10:18:50 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
Richard Smith9155be12013-05-12 03:09:35 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
Douglas Gregor73456262012-02-09 10:18:50 +00003
4void missing_lambda_declarator() {
5 [](){}();
6}
7
8template<typename T> T get();
9
10void infer_void_return_type(int i) {
11 if (i > 17)
12 return []() { }();
13
14 if (i > 11)
15 return []() { return; }();
16
17 return [](int x) {
18 switch (x) {
19 case 0: return get<void>();
20 case 1: return;
Douglas Gregor940a5502012-02-09 18:40:39 +000021 case 2: return { 1, 2.0 }; // expected-error{{cannot deduce lambda return type from initializer list}}
Douglas Gregor73456262012-02-09 10:18:50 +000022 }
23 }(7);
24}
25
26struct X { };
27
28X infer_X_return_type(X x) {
Aaron Ballman8d468872012-06-04 20:07:46 +000029 return [&x](int y) {
Douglas Gregor73456262012-02-09 10:18:50 +000030 if (y > 0)
31 return X();
32 else
33 return x;
34 }(5);
35}
36
Aaron Ballman8d468872012-06-04 20:07:46 +000037X infer_X_return_type_fail(X x) {
38 return [x](int y) {
Douglas Gregor73456262012-02-09 10:18:50 +000039 if (y > 0)
40 return X();
Aaron Ballman8d468872012-06-04 20:07:46 +000041 else
Richard Smith1836e602013-07-26 23:45:07 +000042 return x;
43#if __cplusplus <= 201103L
44 // expected-error@-2 {{return type 'const X' must match previous return type 'X' when lambda expression has unspecified explicit return type}}
45#endif
Douglas Gregor73456262012-02-09 10:18:50 +000046 }(5);
47}
Douglas Gregor621003e2012-02-14 21:20:44 +000048
49struct Incomplete; // expected-note{{forward declaration of 'Incomplete'}}
50void test_result_type(int N) {
51 auto l1 = [] () -> Incomplete { }; // expected-error{{incomplete result type 'Incomplete' in lambda expression}}
52
53 typedef int vla[N];
54 auto l2 = [] () -> vla { }; // expected-error{{function cannot return array type 'vla' (aka 'int [N]')}}
55}