r336946 - PR38141: check whether noexcept-specifications are equivalent in redeclarations

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 12 14:11:26 PDT 2018


Author: rsmith
Date: Thu Jul 12 14:11:25 2018
New Revision: 336946

URL: http://llvm.org/viewvc/llvm-project?rev=336946&view=rev
Log:
PR38141: check whether noexcept-specifications are equivalent in redeclarations

Modified:
    cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
    cfe/trunk/test/CXX/except/except.spec/p3.cpp
    cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=336946&r1=336945&r2=336946&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Thu Jul 12 14:11:25 2018
@@ -530,10 +530,16 @@ static bool CheckEquivalentExceptionSpec
     }
   }
 
-  // FIXME: We treat dependent noexcept specifications as compatible even if
-  // their expressions are not equivalent.
-  if (OldEST == EST_DependentNoexcept && NewEST == EST_DependentNoexcept)
-    return false;
+  // C++14 [except.spec]p3:
+  //   Two exception-specifications are compatible if [...] both have the form
+  //   noexcept(constant-expression) and the constant-expressions are equivalent
+  if (OldEST == EST_DependentNoexcept && NewEST == EST_DependentNoexcept) {
+    llvm::FoldingSetNodeID OldFSN, NewFSN;
+    Old->getNoexceptExpr()->Profile(OldFSN, S.Context, true);
+    New->getNoexceptExpr()->Profile(NewFSN, S.Context, true);
+    if (OldFSN == NewFSN)
+      return false;
+  }
 
   // Dynamic exception specifications with the same set of adjusted types
   // are compatible.

Modified: cfe/trunk/test/CXX/except/except.spec/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p3.cpp?rev=336946&r1=336945&r2=336946&view=diff
==============================================================================
--- cfe/trunk/test/CXX/except/except.spec/p3.cpp (original)
+++ cfe/trunk/test/CXX/except/except.spec/p3.cpp Thu Jul 12 14:11:25 2018
@@ -104,3 +104,13 @@ void* operator new(mysize_t);
 void* operator new[](mysize_t);
 void* operator new[](mysize_t) throw(std::bad_alloc);
 
+template<bool X> void equivalent() noexcept (X);
+template<bool X> void equivalent() noexcept (X);
+
+template<bool X, bool Y> void not_equivalent() noexcept (X); // expected-note {{previous}}
+template<bool X, bool Y> void not_equivalent() noexcept (Y); // expected-error {{does not match}}
+
+template<bool X> void missing() noexcept (X); // expected-note {{previous}}
+// FIXME: The missing exception specification that we report here doesn't make
+// sense in the context of this declaration.
+template<bool P> void missing(); // expected-error {{missing exception specification 'noexcept(X)'}}

Modified: cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp?rev=336946&r1=336945&r2=336946&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Thu Jul 12 14:11:25 2018
@@ -10,7 +10,7 @@ template<typename T> void redecl1() noex
 template<typename T> void redecl1() noexcept(noexcept(T())) {} // expected-error {{redefinition}}
 
 template<bool A, bool B> void redecl2() noexcept(A); // expected-note {{previous}}
-template<bool A, bool B> void redecl2() noexcept(B); // expected-error {{conflicting types}}
+template<bool A, bool B> void redecl2() noexcept(B); // expected-error {{does not match previous}}
 
 // These have the same canonical type, but are still different.
 template<typename A, typename B> void redecl3() throw(A); // expected-note {{previous}}




More information about the cfe-commits mailing list