]> granicus.if.org Git - clang/commitdiff
PR21180: Lambda closure types are neither aggregates nor literal types.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 7 Oct 2014 18:01:33 +0000 (18:01 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 7 Oct 2014 18:01:33 +0000 (18:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219222 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
test/CXX/expr/expr.const/p2-0x.cpp
test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
test/SemaCXX/cxx1y-generic-lambdas.cpp

index 7ebd0e251c780618e6128ee9735a5143770f112d..98efa6c5b6ccc8ae4d1593c1211677c4aefa812c 100644 (file)
@@ -538,6 +538,12 @@ class CXXRecordDecl : public RecordDecl {
         ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
         MethodTyInfo(Info) {
       IsLambda = true;
+
+      // C++11 [expr.prim.lambda]p3:
+      //   This class type is neither an aggregate nor a literal type.
+      Aggregate = false;
+      PlainOldData = false;
+      HasNonLiteralTypeFieldsOrBases = true;
     }
 
     /// \brief Whether this lambda is known to be dependent, even if its
index bcf45a0c05b4d92e655a5d46d90e9bd8c2513a79..249e552724384f163a855ed1751decf96791cab1 100644 (file)
@@ -277,7 +277,7 @@ namespace UndefinedBehavior {
 
 // - a lambda-expression (5.1.2);
 struct Lambda {
-  int n : []{ return 1; }(); // expected-error {{constant expression}} expected-error {{integral constant expression}}
+  int n : []{ return 1; }(); // expected-error {{constant expression}} expected-error {{integral constant expression}} expected-note {{non-literal type}}
 };
 
 // - an lvalue-to-rvalue conversion (4.1) unless it is applied to
index 562f92a78bbccb71326a5947d39d9c31a501de93..c0fa72ba42fbedb24f1be29f57676bc40e53266d 100644 (file)
@@ -3,4 +3,9 @@
 void test_nonaggregate(int i) {
   auto lambda = [i]() -> void {}; // expected-note 3{{candidate constructor}}
   decltype(lambda) foo = { 1 }; // expected-error{{no matching constructor}}
+  static_assert(!__is_literal(decltype(lambda)), "");
+
+  auto lambda2 = []{}; // expected-note {{lambda}}
+  decltype(lambda2) bar = {}; // expected-error{{call to implicitly-deleted default constructor}}
+  static_assert(!__is_literal(decltype(lambda2)), "");
 }
index dc8574825dd98f95d0b8cea28ac49d0e8339511f..8e07b806b1c07d0b79dd2953fad62aab9480b469 100644 (file)
@@ -859,11 +859,13 @@ namespace ns1 {
 struct X1 {  
   struct X2 {
     enum { E = [](auto i) { return i; }(3) }; //expected-error{{inside of a constant expression}}\
-                                          //expected-error{{not an integral constant}}
+                                          //expected-error{{not an integral constant}}\
+                                          //expected-note{{non-literal type}}
     int L = ([] (int i) { return i; })(2);
     void foo(int i = ([] (int i) { return i; })(2)) { }
     int B : ([](int i) { return i; })(3); //expected-error{{inside of a constant expression}}\
-                                          //expected-error{{not an integral constant}}
+                                          //expected-error{{not an integral constant}}\
+                                          //expected-note{{non-literal type}}
     int arr[([](int i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
                                            //expected-error{{must have a constant size}}
     int (*fp)(int) = [](int i) { return i; };
@@ -871,9 +873,10 @@ struct X1 {
     int L2 = ([](auto i) { return i; })(2);
     void fooG(int i = ([] (auto i) { return i; })(2)) { }
     int BG : ([](auto i) { return i; })(3); //expected-error{{inside of a constant expression}}  \
-                                             //expected-error{{not an integral constant}}
+                                            //expected-error{{not an integral constant}}\
+                                            //expected-note{{non-literal type}}
     int arrG[([](auto i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
-                                           //expected-error{{must have a constant size}}
+                                             //expected-error{{must have a constant size}}
     int (*fpG)(int) = [](auto i) { return i; };
     void fooptrG(int (*fp)(char) = [](auto c) { return 0; }) { }
   };
@@ -887,14 +890,16 @@ struct X1 {
     int L = ([] (T i) { return i; })(2);
     void foo(int i = ([] (int i) { return i; })(2)) { }
     int B : ([](T i) { return i; })(3); //expected-error{{inside of a constant expression}}\
-                                          //expected-error{{not an integral constant}}
+                                        //expected-error{{not an integral constant}}\
+                                        //expected-note{{non-literal type}}
     int arr[([](T i) { return i; })(3)]; //expected-error{{inside of a constant expression}}\
-                                           //expected-error{{must have a constant size}}
+                                         //expected-error{{must have a constant size}}
     int (*fp)(T) = [](T i) { return i; };
     void fooptr(T (*fp)(char) = [](char c) { return 0; }) { }
     int L2 = ([](auto i) { return i; })(2);
     void fooG(T i = ([] (auto i) { return i; })(2)) { }
-    int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}
+    int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}\
+                                            //expected-note{{non-literal type}}
     int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}}
     int (*fpG)(T) = [](auto i) { return i; };
     void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }