r223953 - DR1891, PR21787: a lambda closure type has no default constructor, rather than

Richard Smith richard-llvm at metafoo.co.uk
Wed Dec 10 12:04:48 PST 2014


Author: rsmith
Date: Wed Dec 10 14:04:48 2014
New Revision: 223953

URL: http://llvm.org/viewvc/llvm-project?rev=223953&view=rev
Log:
DR1891, PR21787: a lambda closure type has no default constructor, rather than
having a deleted default constructor.

Added:
    cfe/trunk/test/CXX/drs/dr18xx.cpp
Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=223953&r1=223952&r2=223953&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Dec 10 14:04:48 2014
@@ -826,7 +826,11 @@ public:
   /// This value is used for lazy creation of default constructors.
   bool needsImplicitDefaultConstructor() const {
     return !data().UserDeclaredConstructor &&
-           !(data().DeclaredSpecialMembers & SMF_DefaultConstructor);
+           !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
+           // C++14 [expr.prim.lambda]p20:
+           //   The closure type associated with a lambda-expression has no
+           //   default constructor.
+           !isLambda();
   }
 
   /// \brief Determine whether this class has any user-declared constructors.

Added: cfe/trunk/test/CXX/drs/dr18xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr18xx.cpp?rev=223953&view=auto
==============================================================================
--- cfe/trunk/test/CXX/drs/dr18xx.cpp (added)
+++ cfe/trunk/test/CXX/drs/dr18xx.cpp Wed Dec 10 14:04:48 2014
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+
+#if __cplusplus < 201103L
+// expected-no-diagnostics
+#endif
+
+void dr1891() { // dr1891: yes
+#if __cplusplus >= 201103L
+  int n;
+  auto a = []{}; // expected-note 2{{candidate}}
+  auto b = [=]{ return n; }; // expected-note 2{{candidate}}
+  typedef decltype(a) A;
+  typedef decltype(b) B;
+
+  static_assert(!__has_trivial_constructor(A), "");
+  static_assert(!__has_trivial_constructor(B), "");
+
+  A x; // expected-error {{no matching constructor}}
+  B y; // expected-error {{no matching constructor}}
+#endif
+}

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp?rev=223953&r1=223952&r2=223953&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp Wed Dec 10 14:04:48 2014
@@ -7,10 +7,10 @@ struct MoveOnly {
 
 template<typename T> T &&move(T&);
 void test_special_member_functions(MoveOnly mo, int i) {
-  auto lambda1 = [i]() { }; // expected-note 2 {{lambda expression begins here}}
+  auto lambda1 = [i]() { }; // expected-note {{lambda expression begins here}} expected-note 2{{candidate}}
 
   // Default constructor
-  decltype(lambda1) lambda2; // expected-error{{call to implicitly-deleted default constructor of 'decltype(lambda1)' (aka '(lambda}}
+  decltype(lambda1) lambda2; // expected-error{{no matching constructor}}
 
   // Copy assignment operator
   lambda1 = lambda1; // expected-error{{copy assignment operator is implicitly deleted}}

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp?rev=223953&r1=223952&r2=223953&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p3.cpp Wed Dec 10 14:04:48 2014
@@ -1,11 +1,11 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
 
 void test_nonaggregate(int i) {
-  auto lambda = [i]() -> void {}; // expected-note 3{{candidate constructor}}
+  auto lambda = [i]() -> void {}; // expected-note 2{{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}}
+  auto lambda2 = []{}; // expected-note 2{{candidate constructor}}
+  decltype(lambda2) bar = {}; // expected-error{{no matching constructor}}
   static_assert(!__is_literal(decltype(lambda2)), "");
 }





More information about the cfe-commits mailing list