From 5552f5c7ce304c78035f77971edb5a8acc232ad0 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 20 Oct 2015 20:49:21 +0000 Subject: [PATCH] [-fms-extensions] Allow missing exception specifications in redeclarations as an extension Microsoft's ATL headers make use of this MSVC extension, add support for it and issue a diagnostic under -Wmicrosoft-exception-spec. This fixes PR25265. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250854 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 9 ++++++--- lib/Sema/SemaExceptionSpec.cpp | 12 ++++++++---- test/SemaCXX/MicrosoftExtensions.cpp | 8 ++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 63943ccea3..4829f2b74d 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1154,11 +1154,14 @@ def err_incompatible_exception_specs : Error< "target exception specification is not superset of source">; def err_deep_exception_specs_differ : Error< "exception specifications of %select{return|argument}0 types differ">; -def ext_missing_exception_specification : ExtWarn< - "%0 is missing exception specification '%1'">, - InGroup>; def err_missing_exception_specification : Error< "%0 is missing exception specification '%1'">; +def ext_missing_exception_specification : ExtWarn< + err_missing_exception_specification.Text>, + InGroup>; +def ext_ms_missing_exception_specification : ExtWarn< + err_missing_exception_specification.Text>, + InGroup; def err_noexcept_needs_constant_expression : Error< "argument to noexcept specifier must be a constant expression">; def err_exception_spec_not_parsed : Error< diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index a4356f6941..a18824f155 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -285,10 +285,14 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { NewProto->getExtProtoInfo().withExceptionSpec(ESI))); } - // Allow missing exception specifications in redeclarations as an extension, - // when declaring a replaceable global allocation function. - if (New->isReplaceableGlobalAllocationFunction() && - ESI.Type != EST_ComputedNoexcept) { + if (getLangOpts().MicrosoftExt && ESI.Type != EST_ComputedNoexcept) { + // Allow missing exception specifications in redeclarations as an extension. + DiagID = diag::ext_ms_missing_exception_specification; + ReturnValueOnError = false; + } else if (New->isReplaceableGlobalAllocationFunction() && + ESI.Type != EST_ComputedNoexcept) { + // Allow missing exception specifications in redeclarations as an extension, + // when declaring a replaceable global allocation function. DiagID = diag::ext_missing_exception_specification; ReturnValueOnError = false; } else { diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 11f4f19556..3d11c20148 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -422,3 +422,11 @@ template struct A { }; }; } + +namespace PR25265 { +struct S { + int fn() throw(); // expected-note {{previous declaration is here}} +}; + +int S::fn() { return 0; } // expected-warning {{is missing exception specification}} +} -- 2.40.0