SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
const MultiLevelTemplateArgumentList &TemplateArgs);
TemplateName
- SubstTemplateName(TemplateName Name, SourceLocation Loc,
+ SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
+ SourceLocation Loc,
const MultiLevelTemplateArgumentList &TemplateArgs);
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
TemplateArgumentListInfo &Result,
///
/// \param Converted the list of template arguments provided for template
/// parameters that precede \p Param in the template parameter list.
-///
/// \returns the substituted template argument, or NULL if an error occurred.
static TypeSourceInfo *
SubstDefaultTemplateArgument(Sema &SemaRef,
/// \param Converted the list of template arguments provided for template
/// parameters that precede \p Param in the template parameter list.
///
-/// \param QualifierLoc The nested-name-specifier, with source-location
-/// information, which will also be instantiated and updated.
+/// \param QualifierLoc Will be set to the nested-name-specifier (with
+/// source-location information) that precedes the template name.
///
/// \returns the substituted template argument, or NULL if an error occurred.
static TemplateName
SourceRange(TemplateLoc, RAngleLoc));
// Substitute into the nested-name-specifier first,
+ QualifierLoc = Param->getDefaultArgument().getTemplateQualifierLoc();
if (QualifierLoc) {
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
AllTemplateArgs);
return TemplateName();
}
- return SemaRef.SubstTemplateName(
+ return SemaRef.SubstTemplateName(QualifierLoc,
Param->getDefaultArgument().getArgument().getAsTemplate(),
Param->getDefaultArgument().getTemplateNameLoc(),
AllTemplateArgs);
return TemplateArgumentLoc();
- NestedNameSpecifierLoc QualifierLoc
- = TempTempParm->getDefaultArgument().getTemplateQualifierLoc();
+ NestedNameSpecifierLoc QualifierLoc;
TemplateName TName = SubstDefaultTemplateArgument(*this, Template,
TemplateLoc,
RAngleLoc,
break;
}
- NestedNameSpecifierLoc QualifierLoc
- = TempParm->getDefaultArgument().getTemplateQualifierLoc();
+ NestedNameSpecifierLoc QualifierLoc;
TemplateName Name = SubstDefaultTemplateArgument(*this, Template,
TemplateLoc,
RAngleLoc,
NestedNameSpecifierLoc QualifierLoc,
QualType T);
- TemplateName TransformTemplateName(TemplateName Name,
- QualType ObjectType = QualType(),
- NamedDecl *FirstQualifierInScope = 0);
-
TemplateName TransformTemplateName(CXXScopeSpec &SS,
TemplateName Name,
SourceLocation NameLoc,
T);
}
-TemplateName TemplateInstantiator::TransformTemplateName(TemplateName Name,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope) {
- if (TemplateTemplateParmDecl *TTP
- = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
- if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
- // If the corresponding template argument is NULL or non-existent, it's
- // because we are performing instantiation from explicitly-specified
- // template arguments in a function template, but there were some
- // arguments left unspecified.
- if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
- TTP->getPosition()))
- return Name;
-
- TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
-
- if (TTP->isParameterPack()) {
- assert(Arg.getKind() == TemplateArgument::Pack &&
- "Missing argument pack");
-
- if (getSema().ArgumentPackSubstitutionIndex == -1) {
- // We have the template argument pack to substitute, but we're not
- // actually expanding the enclosing pack expansion yet. So, just
- // keep the entire argument pack.
- return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
- }
-
- assert(getSema().ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
- Arg = Arg.pack_begin()[getSema().ArgumentPackSubstitutionIndex];
- }
-
- TemplateName Template = Arg.getAsTemplate();
- assert(!Template.isNull() && Template.getAsTemplateDecl() &&
- "Wrong kind of template template argument");
- return Template;
- }
- }
-
- if (SubstTemplateTemplateParmPackStorage *SubstPack
- = Name.getAsSubstTemplateTemplateParmPack()) {
- if (getSema().ArgumentPackSubstitutionIndex == -1)
- return Name;
-
- const TemplateArgument &ArgPack = SubstPack->getArgumentPack();
- assert(getSema().ArgumentPackSubstitutionIndex < (int)ArgPack.pack_size() &&
- "Pack substitution index out-of-range");
- return ArgPack.pack_begin()[getSema().ArgumentPackSubstitutionIndex]
- .getAsTemplate();
- }
-
- return inherited::TransformTemplateName(Name, ObjectType,
- FirstQualifierInScope);
-}
-
TemplateName TemplateInstantiator::TransformTemplateName(CXXScopeSpec &SS,
TemplateName Name,
SourceLocation NameLoc,
}
TemplateName
-Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc,
+Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc,
+ TemplateName Name, SourceLocation Loc,
const MultiLevelTemplateArgumentList &TemplateArgs) {
TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
DeclarationName());
- return Instantiator.TransformTemplateName(Name);
+ CXXScopeSpec SS;
+ SS.Adopt(QualifierLoc);
+ return Instantiator.TransformTemplateName(SS, Name, Loc);
}
bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
DeclarationNameInfo
TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
- /// \brief Transform the given template name.
- ///
- /// By default, transforms the template name by transforming the declarations
- /// and nested-name-specifiers that occur within the template name.
- /// Subclasses may override this function to provide alternate behavior.
- TemplateName TransformTemplateName(TemplateName Name,
- QualType ObjectType = QualType(),
- NamedDecl *FirstQualifierInScope = 0);
-
/// \brief Transform the given template name.
///
/// \param SS The nested-name-specifier that qualifies the template
return DeclarationNameInfo();
}
-template<typename Derived>
-TemplateName
-TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope) {
- // FIXME: This routine needs to go away.
- SourceLocation Loc = getDerived().getBaseLocation();
-
- if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
- NestedNameSpecifier *NNS
- = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
- /*FIXME*/ SourceRange(Loc),
- ObjectType,
- FirstQualifierInScope);
- if (!NNS)
- return TemplateName();
-
- if (TemplateDecl *Template = QTN->getTemplateDecl()) {
- TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
- if (!TransTemplate)
- return TemplateName();
-
- if (!getDerived().AlwaysRebuild() &&
- NNS == QTN->getQualifier() &&
- TransTemplate == Template)
- return Name;
-
- CXXScopeSpec SS;
- SS.MakeTrivial(SemaRef.Context, NNS, Loc);
- return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
- TransTemplate);
- }
-
- // These should be getting filtered out before they make it into the AST.
- llvm_unreachable("overloaded template name survived to here");
- }
-
- if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
- NestedNameSpecifier *NNS = DTN->getQualifier();
- if (NNS) {
- NNS = getDerived().TransformNestedNameSpecifier(NNS,
- /*FIXME:*/SourceRange(Loc),
- ObjectType,
- FirstQualifierInScope);
- if (!NNS) return TemplateName();
-
- // These apply to the scope specifier, not the template.
- ObjectType = QualType();
- FirstQualifierInScope = 0;
- }
-
- if (!getDerived().AlwaysRebuild() &&
- NNS == DTN->getQualifier() &&
- ObjectType.isNull())
- return Name;
-
- // FIXME: Bad source-location information all around.
- CXXScopeSpec SS;
- SS.MakeTrivial(SemaRef.Context, NNS, getDerived().getBaseLocation());
- if (DTN->isIdentifier()) {
- return getDerived().RebuildTemplateName(SS,
- *DTN->getIdentifier(),
- getDerived().getBaseLocation(),
- ObjectType,
- FirstQualifierInScope);
- }
-
- return getDerived().RebuildTemplateName(SS, DTN->getOperator(),
- getDerived().getBaseLocation(),
- ObjectType);
- }
-
- if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
- TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
- if (!TransTemplate)
- return TemplateName();
-
- if (!getDerived().AlwaysRebuild() &&
- TransTemplate == Template)
- return Name;
-
- return TemplateName(TransTemplate);
- }
-
- if (SubstTemplateTemplateParmPackStorage *SubstPack
- = Name.getAsSubstTemplateTemplateParmPack()) {
- TemplateTemplateParmDecl *TransParam
- = cast_or_null<TemplateTemplateParmDecl>(
- getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
- if (!TransParam)
- return TemplateName();
-
- if (!getDerived().AlwaysRebuild() &&
- TransParam == SubstPack->getParameterPack())
- return Name;
-
- return getDerived().RebuildTemplateName(TransParam,
- SubstPack->getArgumentPack());
- }
-
- // These should be getting filtered out before they reach the AST.
- llvm_unreachable("overloaded function decl survived to here");
- return TemplateName();
-}
-
template<typename Derived>
TemplateName
TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
return true;
}
- TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
+ CXXScopeSpec SS;
+ SS.Adopt(QualifierLoc);
TemplateName Template
- = getDerived().TransformTemplateName(Arg.getAsTemplate());
+ = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
+ Input.getTemplateNameLoc());
if (Template.isNull())
return true;
TemplateSpecializationTypeLoc TL) {
const TemplateSpecializationType *T = TL.getTypePtr();
+ // The nested-name-specifier never matters in a TemplateSpecializationType,
+ // because we can't have a dependent nested-name-specifier anyway.
+ CXXScopeSpec SS;
TemplateName Template
- = getDerived().TransformTemplateName(T->getTemplateName());
+ = getDerived().TransformTemplateName(SS, T->getTemplateName(),
+ TL.getTemplateNameLoc());
if (Template.isNull())
return QualType();