r197305 - PR18246: When performing template argument deduction to decide which template

Richard Smith richard-llvm at metafoo.co.uk
Fri Dec 13 19:18:05 PST 2013


Author: rsmith
Date: Fri Dec 13 21:18:05 2013
New Revision: 197305

URL: http://llvm.org/viewvc/llvm-project?rev=197305&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=197305&r1=197304&r2=197305&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Dec 13 21:18:05 2013
@@ -6521,9 +6521,9 @@ bool Sema::CheckFunctionTemplateSpeciali
       // 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<FunctionTemplateDecl>(FunTmpl->getFirstDecl()),
+              ExplicitTemplateArgs, FT, Specialization, Info)) {
         // Template argument deduction failed; record why it failed, so
         // that we can provide nifty diagnostics.
         FailedCandidates.addCandidate()

Modified: cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp?rev=197305&r1=197304&r2=197305&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp (original)
+++ cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp Fri Dec 13 21:18:05 2013
@@ -28,3 +28,22 @@ namespace PR12331 {
   };
   template<> struct S<int>::U { static const int n = sizeof(int); }; // expected-error {{explicit specialization of 'U' after instantiation}}
 }
+
+namespace PR18246 {
+  template<typename T>
+  class Baz {
+  public:
+    template<int N> void bar();
+  };
+
+  template<typename T>
+  template<int N>
+  void Baz<T>::bar() {
+  }
+
+  // FIXME: Don't suggest the 'template<>' correction here, because this cannot
+  // be an explicit specialization.
+  template<typename T>
+  void Baz<T>::bar<0>() { // expected-error {{requires 'template<>'}}
+  }
+}





More information about the cfe-commits mailing list