r201002 - PR16638, DR1552: the exception specification on an implicitly-declared

Richard Smith richard-llvm at metafoo.co.uk
Fri Feb 7 14:51:17 PST 2014


Author: rsmith
Date: Fri Feb  7 16:51:16 2014
New Revision: 201002

URL: http://llvm.org/viewvc/llvm-project?rev=201002&view=rev
Log:
PR16638, DR1552: the exception specification on an implicitly-declared
'operator delete' or 'operator delete[]' is an explicit exception
specification. Therefore we should diagnose 'void operator delete(void*)'
instead of 'void operator delete(void*) noexcept'.

This diagnostic remains an ExtWarn, since in practice people don't always
include the exception specification in such a declaration.

Modified:
    cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
    cfe/trunk/test/CXX/except/except.spec/p15.cpp
    cfe/trunk/test/SemaCXX/cxx0x-cursory-default-delete.cpp

Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=201002&r1=201001&r2=201002&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Fri Feb  7 16:51:16 2014
@@ -140,10 +140,13 @@ static bool hasImplicitExceptionSpec(Fun
       Decl->getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
     return false;
 
-  // If the user didn't declare the function, its exception specification must
-  // be implicit.
+  // For a function that the user didn't declare:
+  //  - if this is a destructor, its exception specification is implicit.
+  //  - if this is 'operator delete' or 'operator delete[]', the exception
+  //    specification is as-if an explicit exception specification was given
+  //    (per [basic.stc.dynamic]p2).
   if (!Decl->getTypeSourceInfo())
-    return true;
+    return isa<CXXDestructorDecl>(Decl);
 
   const FunctionProtoType *Ty =
     Decl->getTypeSourceInfo()->getType()->getAs<FunctionProtoType>();

Modified: cfe/trunk/test/CXX/except/except.spec/p15.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/except/except.spec/p15.cpp?rev=201002&r1=201001&r2=201002&view=diff
==============================================================================
--- cfe/trunk/test/CXX/except/except.spec/p15.cpp (original)
+++ cfe/trunk/test/CXX/except/except.spec/p15.cpp Fri Feb  7 16:51:16 2014
@@ -1,16 +1,20 @@
 // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DUSE -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
+
+// Maybe force the implicit declaration of 'operator delete' and 'operator
+// delete[]'. This should make no difference to anything!
+#ifdef USE
+void f(int *p) {
+  delete p;
+  delete [] p;
+}
+#endif
 
 // Deallocation functions are implicitly noexcept.
 // Thus, explicit specs aren't allowed to conflict.
 
-void f() {
-  // Force implicit declaration of delete.
-  delete new int;
-  delete[] new int[1];
-}
-
-void operator delete(void*);
-void operator delete[](void*);
+void operator delete(void*); // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
+void operator delete[](void*); // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
 
 static_assert(noexcept(operator delete(0)), "");
 static_assert(noexcept(operator delete[](0)), "");

Modified: cfe/trunk/test/SemaCXX/cxx0x-cursory-default-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-cursory-default-delete.cpp?rev=201002&r1=201001&r2=201002&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-cursory-default-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-cursory-default-delete.cpp Fri Feb  7 16:51:16 2014
@@ -83,4 +83,4 @@ S::S() __attribute((pure)) = default;
 
 using size_t = decltype(sizeof(0));
 void *operator new(size_t) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
-void operator delete(void *) = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}
+void operator delete(void *) noexcept = delete; // expected-error {{deleted definition must be first declaration}} expected-note {{implicit}}





More information about the cfe-commits mailing list