]> granicus.if.org Git - clang/commitdiff
Fix for PR42089, regression from r362119
authorErich Keane <erich.keane@intel.com>
Fri, 31 May 2019 14:26:19 +0000 (14:26 +0000)
committerErich Keane <erich.keane@intel.com>
Fri, 31 May 2019 14:26:19 +0000 (14:26 +0000)
The implementation of the NoThrow ExceptionSpecificationType missed a
switch statement for forming the diagnostic when an out-of-line member
redeclaration misses the exception specification.  This patch adds the
correct case statement.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362225 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExceptionSpec.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 59b919bb86ce3eed058d492c8671e10c9c0b5063..e8f559af4da8afdbd93a60ed275d394e51e5fed9 100644 (file)
@@ -381,6 +381,11 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
     // when declaring a replaceable global allocation function.
     DiagID = diag::ext_missing_exception_specification;
     ReturnValueOnError = false;
+  } else if (ESI.Type == EST_NoThrow) {
+    // Allow missing attribute 'nothrow' in redeclarations, since this is a very
+    // common omission.
+    DiagID = diag::ext_missing_exception_specification;
+    ReturnValueOnError = false;
   } else {
     DiagID = diag::err_missing_exception_specification;
     ReturnValueOnError = true;
@@ -421,7 +426,9 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
     OldProto->getNoexceptExpr()->printPretty(OS, nullptr, getPrintingPolicy());
     OS << ")";
     break;
-
+  case EST_NoThrow:
+    OS <<"__attribute__((nothrow))";
+    break;
   default:
     llvm_unreachable("This spec type is compatible with none.");
   }
index 55adb68d2e4f610eaf7ad778f360f882e3c9675a..8accc88bf37f3f1991d8e84317bbe83f74534814 100644 (file)
@@ -517,6 +517,15 @@ void PR34109(int* a) {
   delete a;
 }
 
+namespace PR42089 {
+  struct S {
+    __attribute__((nothrow)) void Foo(); // expected-note {{previous declaration is here}}
+    __attribute__((nothrow)) void Bar();
+  };
+  void S::Foo(){} // expected-warning {{is missing exception specification}}
+  __attribute__((nothrow)) void S::Bar(){}
+}
+
 #elif TEST2
 
 // Check that __unaligned is not recognized if MS extensions are not enabled