r210350 - PR14841: If partial substitution of explicitly-specified template arguments

Richard Smith richard-llvm at metafoo.co.uk
Fri Jun 6 09:00:51 PDT 2014


Author: rsmith
Date: Fri Jun  6 11:00:50 2014
New Revision: 210350

URL: http://llvm.org/viewvc/llvm-project?rev=210350&view=rev
Log:
PR14841: If partial substitution of explicitly-specified template arguments
results in a template having too many arguments, but all the trailing arguments
are packs, that's OK if we have a partial pack substitution: the trailing pack
expansions may end up empty.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/pack-deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=210350&r1=210349&r2=210350&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jun  6 11:00:50 2014
@@ -3856,6 +3856,17 @@ bool Sema::CheckTemplateArgumentList(Tem
     ++ArgIdx;
   }
 
+  // If we're performing a partial argument substitution, allow any trailing
+  // pack expansions; they might be empty. This can happen even if
+  // PartialTemplateArgs is false (the list of arguments is complete but
+  // still dependent).
+  if (ArgIdx < NumArgs && CurrentInstantiationScope &&
+      CurrentInstantiationScope->getPartiallySubstitutedPack()) {
+    while (ArgIdx < NumArgs &&
+           TemplateArgs[ArgIdx].getArgument().isPackExpansion())
+      Converted.push_back(TemplateArgs[ArgIdx++].getArgument());
+  }
+
   // If we have any leftover arguments, then there were too many arguments.
   // Complain and fail.
   if (ArgIdx < NumArgs)

Modified: cfe/trunk/test/SemaTemplate/pack-deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/pack-deduction.cpp?rev=210350&r1=210349&r2=210350&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/pack-deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/pack-deduction.cpp Fri Jun  6 11:00:50 2014
@@ -18,3 +18,15 @@ namespace Nested {
   int b1 = f2(P<X<int, double>, int>(), P<X<int, double>, double>());
   int b2 = f2(P<X<int, double>, int>(), P<X<int, double>, double>(), P<X<int, double>, char>()); // expected-error {{no matching}}
 }
+
+namespace PR14841 {
+  template<typename T, typename U> struct A {};
+  template<typename ...Ts> void f(A<Ts...>); // expected-note {{substitution failure [with Ts = <char, short, int>]: too many template arg}}
+
+  void g(A<char, short> a) {
+    f(a);
+    f<char>(a);
+    f<char, short>(a);
+    f<char, short, int>(a); // expected-error {{no matching function}}
+  }
+}





More information about the cfe-commits mailing list