diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3562,7 +3562,14 @@ } } - if (OldQTypeForComparison == NewQType) + if (OldQTypeForComparison == NewQType || + // In Microsoft compatibility mode, the intent is to only warn on + // mismatched exception specifiers. By this point, that warning has + // already been issued, so we should treat mismatches only in exception + // specifier as equivalent. + (getLangOpts().MSVCCompat && + Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison, + NewQType))) return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld); // If the types are imprecise (due to dependent constructs in friends or diff --git a/clang/test/SemaCXX/ms-exception-spec.cpp b/clang/test/SemaCXX/ms-exception-spec.cpp --- a/clang/test/SemaCXX/ms-exception-spec.cpp +++ b/clang/test/SemaCXX/ms-exception-spec.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions +// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions +// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions void f() throw(...) { } @@ -7,3 +8,11 @@ void fn() throw(S); // expected-warning {{incomplete type}} expected-note{{previous declaration}} void fn() throw(); // expected-warning {{does not match previous declaration}} } + +template struct FooPtr { + template FooPtr(U *p) : m_pT(nullptr) {} + template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {} // expected-warning {{exception specification in declaration does not match previous declaration}} + T *m_pT; +}; +struct Bar {}; +template struct FooPtr;