]> granicus.if.org Git - clang/commitdiff
Remove an assert in template pack deduction during nested instantiation.
authorRichard Trieu <rtrieu@google.com>
Fri, 15 Mar 2019 04:26:02 +0000 (04:26 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 15 Mar 2019 04:26:02 +0000 (04:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356231 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/pack-deduction.cpp

index eb3444e9ee22ad38fe7712901a1122cbc5f9408f..c71fa7ac57b755e56e8eb2345ad9dad20e81660b 100644 (file)
@@ -3804,25 +3804,25 @@ static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function,
     Scope.MakeInstantiatedLocalArgPack(PatternParam);
     Optional<unsigned> NumArgumentsInExpansion
       = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
-    assert(NumArgumentsInExpansion &&
-           "should only be called when all template arguments are known");
-    QualType PatternType =
-        PatternParam->getType()->castAs<PackExpansionType>()->getPattern();
-    for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
-      ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
-      FunctionParam->setDeclName(PatternParam->getDeclName());
-      if (!PatternDecl->getType()->isDependentType()) {
-        Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
-        QualType T = S.SubstType(PatternType, TemplateArgs,
-                                 FunctionParam->getLocation(),
-                                 FunctionParam->getDeclName());
-        if (T.isNull())
-          return true;
-        FunctionParam->setType(T);
-      }
+    if (NumArgumentsInExpansion) {
+      QualType PatternType =
+          PatternParam->getType()->castAs<PackExpansionType>()->getPattern();
+      for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+        ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
+        FunctionParam->setDeclName(PatternParam->getDeclName());
+        if (!PatternDecl->getType()->isDependentType()) {
+          Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
+          QualType T = S.SubstType(PatternType, TemplateArgs,
+                                   FunctionParam->getLocation(),
+                                   FunctionParam->getDeclName());
+          if (T.isNull())
+            return true;
+          FunctionParam->setType(T);
+        }
 
-      Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
-      ++FParamIdx;
+        Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
+        ++FParamIdx;
+      }
     }
   }
 
index f9309d52111ef6297ff39eb29d44aa7f45515ce0..478b19731b67a8a2c76c8335397122065f8ac649 100644 (file)
@@ -166,3 +166,22 @@ namespace substitution_vs_function_deduction {
     A<int>().g(f); // expected-error {{no match}}
   }
 }
+
+namespace Nested_Explicit_Specialization {
+template <typename>
+struct Outer {
+
+  template <int>
+  struct Inner;
+
+  template <>
+  struct Inner<0> {
+    template <typename... Args>
+    void Test(Args...) {}
+  };
+};
+
+void Run() {
+  Outer<void>::Inner<0>().Test(1,1);
+}
+}