Home | History | Annotate | Download | only in expr.prim.lambda
      1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
      2 // RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify
      3 
      4 void missing_lambda_declarator() {
      5   [](){}();
      6 }
      7 
      8 template<typename T> T get();
      9 
     10 void 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;
     21     case 2: return { 1, 2.0 }; // expected-error{{cannot deduce lambda return type from initializer list}}
     22     }
     23   }(7);
     24 }
     25 
     26 struct X { };
     27 
     28 X infer_X_return_type(X x) {
     29   return [&x](int y) {
     30     if (y > 0)
     31       return X();
     32     else
     33       return x;
     34   }(5);
     35 }
     36 
     37 X infer_X_return_type_fail(X x) {
     38   return [x](int y) {
     39     if (y > 0)
     40       return X();
     41     else
     42       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
     46   }(5);
     47 }
     48 
     49 struct Incomplete; // expected-note{{forward declaration of 'Incomplete'}}
     50 void 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 }
     56