[PATCH] D116256: [-fms-extensions] Make some exception specification warnings/errors compatible with what cl.exe does
Amy Huang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 23 15:24:21 PST 2021
akhuang created this revision.
akhuang added reviewers: hans, thakis.
akhuang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Make clang-cl error when a function definition is missing 'noexcept',
and succeed without warnings when missing '__declspec(nothrow)' or 'throw'.
Fixes pr52860
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116256
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExceptionSpec.cpp
clang/test/SemaCXX/MicrosoftCompatibility.cpp
Index: clang/test/SemaCXX/MicrosoftCompatibility.cpp
===================================================================
--- clang/test/SemaCXX/MicrosoftCompatibility.cpp
+++ clang/test/SemaCXX/MicrosoftCompatibility.cpp
@@ -377,14 +377,14 @@
#endif
};
-}
+void f4() throw();
+void f4() {}
-namespace PR25265 {
-struct S {
- int fn() throw(); // expected-note {{previous declaration is here}}
-};
+__declspec(nothrow) void f5();
+void f5() {}
-int S::fn() { return 0; } // expected-warning {{is missing exception specification}}
+void f6() noexcept; // expected-note {{previous declaration is here}}
+void f6() {} // expected-error {{'f6' is missing exception specification 'noexcept'}}
}
namespace PR43265 {
Index: clang/lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- clang/lib/Sema/SemaExceptionSpec.cpp
+++ clang/lib/Sema/SemaExceptionSpec.cpp
@@ -391,10 +391,11 @@
NewProto->getExtProtoInfo().withExceptionSpec(ESI)));
}
- if (getLangOpts().MSVCCompat && ESI.Type != EST_DependentNoexcept) {
- // Allow missing exception specifications in redeclarations as an extension.
- DiagID = diag::ext_ms_missing_exception_specification;
- ReturnValueOnError = false;
+ if (getLangOpts().MSVCCompat &&
+ !(ESI.Type == EST_DependentNoexcept || ESI.Type == EST_BasicNoexcept)) {
+ // Allow missing exception specifications in redeclarations as an extension
+ // without a warning.
+ return false;
} else if (New->isReplaceableGlobalAllocationFunction() &&
ESI.Type != EST_DependentNoexcept) {
// Allow missing exception specifications in redeclarations as an extension,
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1695,9 +1695,6 @@
def ext_missing_exception_specification : ExtWarn<
err_missing_exception_specification.Text>,
InGroup<DiagGroup<"missing-exception-spec">>;
-def ext_ms_missing_exception_specification : ExtWarn<
- err_missing_exception_specification.Text>,
- InGroup<MicrosoftExceptionSpec>;
def err_noexcept_needs_constant_expression : Error<
"argument to noexcept specifier must be a constant expression">;
def err_exception_spec_not_parsed : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116256.396113.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211223/4ab99ccd/attachment.bin>
More information about the cfe-commits
mailing list