[cfe-commits] r150453 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/cxx0x-defaulted-functions.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Feb 13 18:33:50 PST 2012


Author: rsmith
Date: Mon Feb 13 20:33:50 2012
New Revision: 150453

URL: http://llvm.org/viewvc/llvm-project?rev=150453&view=rev
Log:
Fix another issue introduced by the proposed wording for core issue 1358: since
the instantiation of a constexpr function temploid is now always constexpr, a
defaulted constexpr function temploid is often ill-formed by the rule in
[dcl.fct.def.default]p2 that an explicitly-defaulted constexpr function must
have a constexpr implicit definition. To avoid making loads of completely
reasonable code ill-formed, do not apply that rule to templates.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=150453&r1=150452&r2=150453&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Feb 13 20:33:50 2012
@@ -3832,7 +3832,10 @@
   // C++11 [dcl.fct.def.default]p2:
   //   An explicitly-defaulted function may be declared constexpr only if it
   //   would have been implicitly declared as constexpr,
-  if (CD->isConstexpr()) {
+  // Do not apply this rule to templates, since core issue 1358 makes such
+  // functions always instantiate to constexpr functions.
+  if (CD->isConstexpr() &&
+      CD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
     if (!CD->getParent()->defaultedDefaultConstructorIsConstexpr()) {
       Diag(CD->getLocStart(), diag::err_incorrect_defaulted_constexpr)
         << CXXDefaultConstructor;
@@ -3920,7 +3923,10 @@
   // C++11 [dcl.fct.def.default]p2:
   //   An explicitly-defaulted function may be declared constexpr only if it
   //   would have been implicitly declared as constexpr,
-  if (CD->isConstexpr()) {
+  // Do not apply this rule to templates, since core issue 1358 makes such
+  // functions always instantiate to constexpr functions.
+  if (CD->isConstexpr() &&
+      CD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
     if (!CD->getParent()->defaultedCopyConstructorIsConstexpr()) {
       Diag(CD->getLocStart(), diag::err_incorrect_defaulted_constexpr)
         << CXXCopyConstructor;
@@ -4097,7 +4103,10 @@
   // C++11 [dcl.fct.def.default]p2:
   //   An explicitly-defaulted function may be declared constexpr only if it
   //   would have been implicitly declared as constexpr,
-  if (CD->isConstexpr()) {
+  // Do not apply this rule to templates, since core issue 1358 makes such
+  // functions always instantiate to constexpr functions.
+  if (CD->isConstexpr() &&
+      CD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
     if (!CD->getParent()->defaultedMoveConstructorIsConstexpr()) {
       Diag(CD->getLocStart(), diag::err_incorrect_defaulted_constexpr)
         << CXXMoveConstructor;

Modified: cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp?rev=150453&r1=150452&r2=150453&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp Mon Feb 13 20:33:50 2012
@@ -28,7 +28,7 @@
 bar& bar::operator = (bar&) = default;
 bar::~bar() = default;
 
-// FIXME: static_assert(__is_trivial(foo), "foo should be trivial");
+static_assert(__is_trivial(foo), "foo should be trivial");
 
 static_assert(!__has_trivial_destructor(bar), "bar's destructor isn't trivial");
 static_assert(!__has_trivial_constructor(bar),
@@ -43,3 +43,11 @@
   b = c;
 }
 
+template<typename T> struct S : T {
+  constexpr S() = default;
+  constexpr S(const S&) = default;
+  constexpr S(S&&) = default;
+};
+struct lit { constexpr lit() {} };
+S<lit> s_lit; // ok
+S<bar> s_bar; // ok





More information about the cfe-commits mailing list