Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -3658,6 +3658,11 @@ "of %select{explicit instantiation|explicit specialization|" "partial specialization|redeclaration}0 of %1 does not match" " expected type %3">; +def err_mismatched_exception_spec_explicit_instantiation : Error< + "exception specification in explicit instantiation does not match instantiated one">; +def ext_mismatched_exception_spec_explicit_instantiation : ExtWarn< + "exception specification in explicit instantiation does not match instantiated one">, + InGroup; // C++ typename-specifiers def err_typename_nested_not_found : Error<"no type named %0 in %1">; Index: cfe/trunk/lib/Sema/SemaTemplate.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaTemplate.cpp +++ cfe/trunk/lib/Sema/SemaTemplate.cpp @@ -7627,6 +7627,29 @@ // Ignore access control bits, we don't need them for redeclaration checking. FunctionDecl *Specialization = cast(*Result); + // C++11 [except.spec]p4 + // In an explicit instantiation an exception-specification may be specified, + // but is not required. + // If an exception-specification is specified in an explicit instantiation + // directive, it shall be compatible with the exception-specifications of + // other declarations of that function. + if (auto *FPT = R->getAs()) + if (FPT->hasExceptionSpec()) { + unsigned DiagID = + diag::err_mismatched_exception_spec_explicit_instantiation; + if (getLangOpts().MicrosoftExt) + DiagID = diag::ext_mismatched_exception_spec_explicit_instantiation; + bool Result = CheckEquivalentExceptionSpec( + PDiag(DiagID) << Specialization->getType(), + PDiag(diag::note_explicit_instantiation_here), + Specialization->getType()->getAs(), + Specialization->getLocation(), FPT, D.getLocStart()); + // In Microsoft mode, mismatching exception specifications just cause a + // warning. + if (!getLangOpts().MicrosoftExt && Result) + return true; + } + if (Specialization->getTemplateSpecializationKind() == TSK_Undeclared) { Diag(D.getIdentifierLoc(), diag::err_explicit_instantiation_member_function_not_instantiated) Index: cfe/trunk/test/SemaTemplate/explicit-instantiation.cpp =================================================================== --- cfe/trunk/test/SemaTemplate/explicit-instantiation.cpp +++ cfe/trunk/test/SemaTemplate/explicit-instantiation.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -std=c++11 %s template void *; // expected-error{{expected unqualified-id}} @@ -13,8 +14,8 @@ T f0(T x) { return x + 1; // expected-error{{invalid operands}} - } - T* f0(T*, T*) { return T(); } // expected-warning{{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} + } + T *f0(T *, T *) { return T(); } // expected-warning 0-1 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} expected-error 0-1 {{cannot initialize return object of type 'int *' with an rvalue of type 'int'}} template T f0(T, U) { return T(); } // expected-note-re {{candidate template ignored: could not match 'int (int, U){{( __attribute__\(\(thiscall\)\))?}}' against 'int (int){{( __attribute__\(\(thiscall\)\))?}} const'}} \ // expected-note {{candidate template ignored: could not match 'int' against 'int *'}} @@ -25,7 +26,7 @@ template int X0::value; -struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} +struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}} NotDefaultConstructible(int); // expected-note{{candidate constructor}} }; @@ -149,3 +150,17 @@ template int C::b; template int D::c; } + +// expected-note@+1 3-4 {{explicit instantiation refers here}} +template void Foo(T i) throw(T) { throw i; } +// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} +template void Foo(int a) throw(char); +// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}} +template void Foo(double a) throw(); +// expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}} +template void Foo(long a) throw(long, char); +template void Foo(float a); +#if __cplusplus >= 201103L +// expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}} +template void Foo(double a) noexcept; +#endif