r178103 - PR15597: Fix a confusion between the implicit exception specification and the

Richard Smith richard-llvm at metafoo.co.uk
Tue Mar 26 17:22:47 PDT 2013


Author: rsmith
Date: Tue Mar 26 19:22:47 2013
New Revision: 178103

URL: http://llvm.org/viewvc/llvm-project?rev=178103&view=rev
Log:
PR15597: Fix a confusion between the implicit exception specification and the
uninstantiated exception specification when a special member within a class
template is both defaulted and given an exception specification on its first
declaration.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExceptionSpec.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=178103&r1=178102&r2=178103&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Mar 26 19:22:47 2013
@@ -4372,9 +4372,15 @@ void Sema::CheckExplicitlyDefaultedSpeci
   if (Type->hasExceptionSpec()) {
     // Delay the check if this is the first declaration of the special member,
     // since we may not have parsed some necessary in-class initializers yet.
-    if (First)
+    if (First) {
+      // If the exception specification needs to be instantiated, do so now,
+      // before we clobber it with an EST_Unevaluated specification below.
+      if (Type->getExceptionSpecType() == EST_Uninstantiated) {
+        InstantiateExceptionSpec(MD->getLocStart(), MD);
+        Type = MD->getType()->getAs<FunctionProtoType>();
+      }
       DelayedDefaultedMemberExceptionSpecs.push_back(std::make_pair(MD, Type));
-    else
+    } else
       CheckExplicitlyDefaultedMemberExceptionSpec(MD, Type);
   }
 
@@ -11018,6 +11024,9 @@ void Sema::SetDeclDefaulted(Decl *Dcl, S
       // on it.
       Pattern->isDefined(Primary);
 
+    // If the method was defaulted on its first declaration, we will have
+    // already performed the checking in CheckCompletedCXXClass. Such a
+    // declaration doesn't trigger an implicit definition.
     if (Primary == Primary->getCanonicalDecl())
       return;
 

Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=178103&r1=178102&r2=178103&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Tue Mar 26 19:22:47 2013
@@ -124,7 +124,7 @@ Sema::ResolveExceptionSpec(SourceLocatio
     return SourceFPT;
 
   // Compute or instantiate the exception specification now.
-  if (FPT->getExceptionSpecType() == EST_Unevaluated)
+  if (SourceFPT->getExceptionSpecType() == EST_Unevaluated)
     EvaluateImplicitExceptionSpec(Loc, cast<CXXMethodDecl>(SourceDecl));
   else
     InstantiateExceptionSpec(Loc, SourceDecl);

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=178103&r1=178102&r2=178103&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp Tue Mar 26 19:22:47 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fcxx-exceptions %s
 
 void fn() = default; // expected-error {{only special member}}
 struct foo {
@@ -175,3 +175,16 @@ extern "C" {
  template<typename _Tp> // expected-error {{templates must have C++ linkage}}
  void PR13573(const _Tp&) = delete; // expected-error {{only functions can have deleted definitions}}
 }
+
+namespace PR15597 {
+  template<typename T> struct A {
+    A() noexcept(true) = default;
+    ~A() noexcept(true) = default;
+  };
+  template<typename T> struct B {
+    B() noexcept(false) = default; // expected-error {{does not match the calculated one}}
+    ~B() noexcept(false) = default; // expected-error {{does not match the calculated one}}
+  };
+  A<int> a;
+  B<int> b; // expected-note {{here}}
+}





More information about the cfe-commits mailing list