@@ -2119,8 +2119,25 @@ ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param,
2119
2119
PackedArgsBuilder.push_back (Output.pop_back_val ());
2120
2120
}
2121
2121
2122
- // FIXME: If the pack is empty and this is a template template parameter,
2123
- // we still need to substitute into the parameter itself.
2122
+ // If the pack is empty, we still need to substitute into the parameter
2123
+ // itself, in case that substitution fails. For non-type parameters, we did
2124
+ // this above. For type parameters, no substitution is ever required.
2125
+ auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param);
2126
+ if (TTP && PackedArgsBuilder.empty ()) {
2127
+ // Set up a template instantiation context.
2128
+ LocalInstantiationScope Scope (S);
2129
+ Sema::InstantiatingTemplate Inst (S, Template->getLocation (), Template,
2130
+ TTP, Output,
2131
+ Template->getSourceRange ());
2132
+ if (Inst.isInvalid ())
2133
+ return true ;
2134
+
2135
+ TemplateArgumentList TemplateArgs (TemplateArgumentList::OnStack,
2136
+ Output.data (), Output.size ());
2137
+ if (!S.SubstDecl (TTP, S.CurContext ,
2138
+ MultiLevelTemplateArgumentList (TemplateArgs)))
2139
+ return true ;
2140
+ }
2124
2141
2125
2142
// Create the resulting argument pack.
2126
2143
Output.push_back (
@@ -2808,11 +2825,22 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
2808
2825
Builder.push_back (TemplateArgument (
2809
2826
llvm::makeArrayRef (ExplicitArgs, NumExplicitArgs)));
2810
2827
2811
- // Forget the partially-substituted pack; it's substitution is now
2828
+ // Forget the partially-substituted pack; its substitution is now
2812
2829
// complete.
2813
2830
CurrentInstantiationScope->ResetPartiallySubstitutedPack ();
2814
2831
} else {
2815
- Builder.push_back (TemplateArgument::getEmptyPack ());
2832
+ // Go through the motions of checking the empty argument pack against
2833
+ // the parameter pack.
2834
+ DeducedTemplateArgument DeducedPack (TemplateArgument::getEmptyPack ());
2835
+ if (ConvertDeducedTemplateArgument (*this , Param, DeducedPack,
2836
+ FunctionTemplate, Info, true ,
2837
+ Builder)) {
2838
+ Info.Param = makeTemplateParameter (Param);
2839
+ // FIXME: These template arguments are temporary. Free them!
2840
+ Info.reset (TemplateArgumentList::CreateCopy (Context, Builder.data (),
2841
+ Builder.size ()));
2842
+ return TDK_SubstitutionFailure;
2843
+ }
2816
2844
}
2817
2845
continue ;
2818
2846
}
0 commit comments