def note_default_arg_instantiation_here : Note<
"in instantiation of default argument for '%0' required here">;
+def note_default_function_arg_instantiation_here : Note<
+ "in instantiation of default function argument expression "
+ "for '%0' required here">;
def note_explicit_template_arg_substitution_here : Note<
"while substituting explicitly-specified template arguments into function "
"template %f, here">;
/// FIXME: Use a TemplateArgumentList
DefaultTemplateArgumentInstantiation,
+ /// We are instantiating a default argument for a function.
+ /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
+ /// provides the template arguments as specified.
+ DefaultFunctionArgumentInstantiation,
+
/// We are substituting explicit template arguments provided for
/// a function template. The entity is a FunctionTemplateDecl.
ExplicitTemplateArgumentSubstitution,
case DefaultTemplateArgumentInstantiation:
case ExplicitTemplateArgumentSubstitution:
case DeducedTemplateArgumentSubstitution:
+ case DefaultFunctionArgumentInstantiation:
return X.TemplateArgs == Y.TemplateArgs;
+
}
return true;
unsigned NumTemplateArgs,
SourceRange InstantiationRange = SourceRange());
+ InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
+ ParmVarDecl *Param,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs,
+ SourceRange InstantiationRange = SourceRange());
+
/// \brief Note that we have finished instantiating this template.
void Clear();
// Instantiate the expression.
MultiLevelTemplateArgumentList ArgList = getTemplateInstantiationArgs(FD);
-
- // FIXME: We should really make a new InstantiatingTemplate ctor
- // that has a better message - right now we're just piggy-backing
- // off the "default template argument" error message.
- InstantiatingTemplate Inst(*this, CallLoc, FD->getPrimaryTemplate(),
- ArgList.getInnermost().getFlatArgumentList(),
+
+ InstantiatingTemplate Inst(*this, CallLoc, Param,
+ ArgList.getInnermost().getFlatArgumentList(),
ArgList.getInnermost().flat_size());
OwningExprResult Result = SubstExpr(UninstExpr, ArgList);
}
}
+Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef,
+ SourceLocation PointOfInstantation,
+ ParmVarDecl *Param,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs,
+ SourceRange InstantiationRange)
+ : SemaRef(SemaRef) {
+
+ Invalid = CheckInstantiationDepth(PointOfInstantation, InstantiationRange);
+
+ if (!Invalid) {
+ ActiveTemplateInstantiation Inst;
+ Inst.Kind
+ = ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation;
+ Inst.PointOfInstantiation = PointOfInstantation;
+ Inst.Entity = reinterpret_cast<uintptr_t>(Param);
+ Inst.TemplateArgs = TemplateArgs;
+ Inst.NumTemplateArgs = NumTemplateArgs;
+ Inst.InstantiationRange = InstantiationRange;
+ SemaRef.ActiveTemplateInstantiations.push_back(Inst);
+ Invalid = false;
+ }
+}
+
void Sema::InstantiatingTemplate::Clear() {
if (!Invalid) {
SemaRef.ActiveTemplateInstantiations.pop_back();
}
break;
+ case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: {
+ ParmVarDecl *Param = cast<ParmVarDecl>((Decl *)Active->Entity);
+ FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
+ TemplateDecl *Template = FD->getPrimaryTemplate();
+
+ std::string TemplateArgsStr
+ = TemplateSpecializationType::PrintTemplateArgumentList(
+ Active->TemplateArgs,
+ Active->NumTemplateArgs,
+ Context.PrintingPolicy);
+ Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr),
+ diag::note_default_function_arg_instantiation_here)
+ << (Template->getNameAsString() + TemplateArgsStr)
+ << Active->InstantiationRange;
+ break;
+ }
+
}
}
}
switch(Active->Kind) {
case ActiveTemplateInstantiation::TemplateInstantiation:
+ case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation:
+
// This is a template instantiation, so there is no SFINAE.
return false;
void g() {
f1(10);
- f1(S()); // expected-note{{in instantiation of default argument for 'f1<struct S>' required here}}
+ f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}}
f2(10);
f2(S());
f3(10);
- f3(S()); // expected-note{{in instantiation of default argument for 'f3<struct S>' required here}}
+ f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}}
}
template<typename T> struct F {
- F(T t = 10);
+ F(T t = 10);
};
struct FD : F<int> { };
void g2() {
- F<int> f;
+ F<int> f;
FD fd;
}
template<typename T> struct G {
- G(T) {}
+ G(T) {}
};
void s(G<int> flags = 10) { }