Move template type argument checking out into a separate function. No functionality change.

llvm-svn: 73275
This commit is contained in:
Anders Carlsson 2009-06-13 00:33:33 +00:00
parent 91772d1d76
commit c8cbb2d08c
2 changed files with 33 additions and 21 deletions

View File

@ -2005,6 +2005,10 @@ public:
SourceLocation RAngleLoc, SourceLocation RAngleLoc,
TemplateArgumentListBuilder &Converted); TemplateArgumentListBuilder &Converted);
bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
const TemplateArgument &Arg,
TemplateArgumentListBuilder &Converted);
bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg, bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
SourceLocation ArgLoc); SourceLocation ArgLoc);
bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg, bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,

View File

@ -975,6 +975,33 @@ Sema::ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
return TemplateTy::make(Context.getDependentTemplateName(Qualifier, &Name)); return TemplateTy::make(Context.getDependentTemplateName(Qualifier, &Name));
} }
bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
const TemplateArgument &Arg,
TemplateArgumentListBuilder &Converted) {
// Check template type parameter.
if (Arg.getKind() != TemplateArgument::Type) {
// C++ [temp.arg.type]p1:
// A template-argument for a template-parameter which is a
// type shall be a type-id.
// We have a template type parameter but the template argument
// is not a type.
Diag(Arg.getLocation(), diag::err_template_arg_must_be_type);
Diag(Param->getLocation(), diag::note_template_param_here);
return true;
}
if (CheckTemplateArgument(Param, Arg.getAsType(), Arg.getLocation()))
return true;
// Add the converted template type argument.
Converted.push_back(
TemplateArgument(Arg.getLocation(),
Context.getCanonicalType(Arg.getAsType())));
return false;
}
/// \brief Check that the given template argument list is well-formed /// \brief Check that the given template argument list is well-formed
/// for specializing the given template. /// for specializing the given template.
bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
@ -1085,26 +1112,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) { if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
// Check template type parameters. if (CheckTemplateTypeArgument(TTP, Arg, Converted))
if (Arg.getKind() == TemplateArgument::Type) {
if (CheckTemplateArgument(TTP, Arg.getAsType(), Arg.getLocation()))
Invalid = true;
// Add the converted template type argument.
Converted.push_back(
TemplateArgument(Arg.getLocation(),
Context.getCanonicalType(Arg.getAsType())));
continue;
}
// C++ [temp.arg.type]p1:
// A template-argument for a template-parameter which is a
// type shall be a type-id.
// We have a template type parameter but the template argument
// is not a type.
Diag(Arg.getLocation(), diag::err_template_arg_must_be_type);
Diag((*Param)->getLocation(), diag::note_template_param_here);
Invalid = true; Invalid = true;
} else if (NonTypeTemplateParmDecl *NTTP } else if (NonTypeTemplateParmDecl *NTTP
= dyn_cast<NonTypeTemplateParmDecl>(*Param)) { = dyn_cast<NonTypeTemplateParmDecl>(*Param)) {