From: Richard Smith Date: Sat, 14 Dec 2013 03:18:05 +0000 (+0000) Subject: PR18246: When performing template argument deduction to decide which template X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b300e5bbaa71a937629ab0f6034d434f75363bd6;p=clang PR18246: When performing template argument deduction to decide which template is specialized by an explicit specialization, start from the first declaration in case we've got a member of a class template (redeclarations might not number the template parameters the same way). Our recover here is still far from ideal. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197305 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index b134f6ea51..e4fa380c3d 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -6521,9 +6521,9 @@ bool Sema::CheckFunctionTemplateSpecialization( // FIXME: It is somewhat wasteful to build TemplateDeductionInfo Info(FailedCandidates.getLocation()); FunctionDecl *Specialization = 0; - if (TemplateDeductionResult TDK - = DeduceTemplateArguments(FunTmpl, ExplicitTemplateArgs, FT, - Specialization, Info)) { + if (TemplateDeductionResult TDK = DeduceTemplateArguments( + cast(FunTmpl->getFirstDecl()), + ExplicitTemplateArgs, FT, Specialization, Info)) { // Template argument deduction failed; record why it failed, so // that we can provide nifty diagnostics. FailedCandidates.addCandidate() diff --git a/test/SemaTemplate/explicit-specialization-member.cpp b/test/SemaTemplate/explicit-specialization-member.cpp index 9ddbc04953..07d7389446 100644 --- a/test/SemaTemplate/explicit-specialization-member.cpp +++ b/test/SemaTemplate/explicit-specialization-member.cpp @@ -28,3 +28,22 @@ namespace PR12331 { }; template<> struct S::U { static const int n = sizeof(int); }; // expected-error {{explicit specialization of 'U' after instantiation}} } + +namespace PR18246 { + template + class Baz { + public: + template void bar(); + }; + + template + template + void Baz::bar() { + } + + // FIXME: Don't suggest the 'template<>' correction here, because this cannot + // be an explicit specialization. + template + void Baz::bar<0>() { // expected-error {{requires 'template<>'}} + } +}