From: Erich Keane Date: Fri, 31 May 2019 14:26:19 +0000 (+0000) Subject: Fix for PR42089, regression from r362119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c8519965391cbbeadb0bc83696716ea18b1a2fa;p=clang Fix for PR42089, regression from r362119 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 --- diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index 59b919bb86..e8f559af4d 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -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."); } diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 55adb68d2e..8accc88bf3 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -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