aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r--lib/Sema/SemaTemplate.cpp726
1 files changed, 362 insertions, 364 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index dc455185fe..fceac854ee 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -27,10 +27,10 @@ using namespace clang;
static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) {
if (!D)
return 0;
-
+
if (isa<TemplateDecl>(D))
return D;
-
+
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
// C++ [temp.local]p1:
// Like normal (non-template) classes, class templates have an
@@ -52,14 +52,14 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) {
= dyn_cast<ClassTemplateSpecializationDecl>(Record))
return Spec->getSpecializedTemplate();
}
-
+
return 0;
}
-
+
OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D);
if (!Ovl)
return 0;
-
+
for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(),
FEnd = Ovl->function_end();
F != FEnd; ++F) {
@@ -71,11 +71,11 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) {
if (isa<FunctionTemplateDecl>(*F))
break;
}
-
+
if (F != FEnd) {
// Build an overloaded function decl containing only the
// function templates in Ovl.
- OverloadedFunctionDecl *OvlTemplate
+ OverloadedFunctionDecl *OvlTemplate
= OverloadedFunctionDecl::Create(Context,
Ovl->getDeclContext(),
Ovl->getDeclName());
@@ -85,19 +85,19 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) {
if (isa<FunctionTemplateDecl>(*F))
OvlTemplate->addOverload(*F);
}
-
+
return OvlTemplate;
}
return FuncTmpl;
}
}
-
+
return 0;
}
TemplateNameKind Sema::isTemplateName(Scope *S,
- const IdentifierInfo &II,
+ const IdentifierInfo &II,
SourceLocation IdLoc,
const CXXScopeSpec *SS,
TypeTy *ObjectTypePtr,
@@ -109,7 +109,7 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
if (ObjectTypePtr) {
// This nested-name-specifier occurs in a member access expression, e.g.,
// x->B::f, and we are looking into the type of the object.
- assert((!SS || !SS->isSet()) &&
+ assert((!SS || !SS->isSet()) &&
"ObjectType and scope specifier cannot coexist");
QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
LookupCtx = computeDeclContext(ObjectType);
@@ -121,29 +121,29 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
LookupCtx = computeDeclContext(*SS, EnteringContext);
isDependent = isDependentScopeSpecifier(*SS);
}
-
+
LookupResult Found;
bool ObjectTypeSearchedInScope = false;
if (LookupCtx) {
// Perform "qualified" name lookup into the declaration context we
// computed, which is either the type of the base of a member access
- // expression or the declaration context associated with a prior
+ // expression or the declaration context associated with a prior
// nested-name-specifier.
// The declaration context must be complete.
if (!LookupCtx->isDependentContext() && RequireCompleteDeclContext(*SS))
return TNK_Non_template;
-
+
Found = LookupQualifiedName(LookupCtx, &II, LookupOrdinaryName);
-
+
if (ObjectTypePtr && Found.getKind() == LookupResult::NotFound) {
// C++ [basic.lookup.classref]p1:
// In a class member access expression (5.2.5), if the . or -> token is
- // immediately followed by an identifier followed by a <, the
- // identifier must be looked up to determine whether the < is the
+ // immediately followed by an identifier followed by a <, the
+ // identifier must be looked up to determine whether the < is the
// beginning of a template argument list (14.2) or a less-than operator.
- // The identifier is first looked up in the class of the object
- // expression. If the identifier is not found, it is then looked up in
+ // The identifier is first looked up in the class of the object
+ // expression. If the identifier is not found, it is then looked up in
// the context of the entire postfix-expression and shall name a class
// or function template.
//
@@ -153,15 +153,15 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
ObjectTypeSearchedInScope = true;
}
} else if (isDependent) {
- // We cannot look into a dependent object type or
+ // We cannot look into a dependent object type or
return TNK_Non_template;
} else {
// Perform unqualified name lookup in the current scope.
Found = LookupName(S, &II, LookupOrdinaryName);
}
-
+
// FIXME: Cope with ambiguous name-lookup results.
- assert(!Found.isAmbiguous() &&
+ assert(!Found.isAmbiguous() &&
"Cannot handle template name-lookup ambiguities");
NamedDecl *Template = isAcceptableTemplateName(Context, Found);
@@ -170,24 +170,24 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
if (ObjectTypePtr && !ObjectTypeSearchedInScope) {
// C++ [basic.lookup.classref]p1:
- // [...] If the lookup in the class of the object expression finds a
+ // [...] If the lookup in the class of the object expression finds a
// template, the name is also looked up in the context of the entire
// postfix-expression and [...]
//
LookupResult FoundOuter = LookupName(S, &II, LookupOrdinaryName);
// FIXME: Handle ambiguities in this lookup better
NamedDecl *OuterTemplate = isAcceptableTemplateName(Context, FoundOuter);
-
+
if (!OuterTemplate) {
- // - if the name is not found, the name found in the class of the
+ // - if the name is not found, the name found in the class of the
// object expression is used, otherwise
} else if (!isa<ClassTemplateDecl>(OuterTemplate)) {
- // - if the name is found in the context of the entire
- // postfix-expression and does not name a class template, the name
+ // - if the name is found in the context of the entire
+ // postfix-expression and does not name a class template, the name
// found in the class of the object expression is used, otherwise
} else {
// - if the name found is a class template, it must refer to the same
- // entity as the one found in the class of the object expression,
+ // entity as the one found in the class of the object expression,
// otherwise the program is ill-formed.
if (OuterTemplate->getCanonicalDecl() != Template->getCanonicalDecl()) {
Diag(IdLoc, diag::err_nested_name_member_ref_lookup_ambiguous)
@@ -195,38 +195,38 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
Diag(Template->getLocation(), diag::note_ambig_member_ref_object_type)
<< QualType::getFromOpaquePtr(ObjectTypePtr);
Diag(OuterTemplate->getLocation(), diag::note_ambig_member_ref_scope);
-
- // Recover by taking the template that we found in the object
+
+ // Recover by taking the template that we found in the object
// expression's type.
}
- }
+ }
}
-
+
if (SS && SS->isSet() && !SS->isInvalid()) {
- NestedNameSpecifier *Qualifier
+ NestedNameSpecifier *Qualifier
= static_cast<NestedNameSpecifier *>(SS->getScopeRep());
- if (OverloadedFunctionDecl *Ovl
+ if (OverloadedFunctionDecl *Ovl
= dyn_cast<OverloadedFunctionDecl>(Template))
- TemplateResult
+ TemplateResult
= TemplateTy::make(Context.getQualifiedTemplateName(Qualifier, false,
Ovl));
else
- TemplateResult
+ TemplateResult
= TemplateTy::make(Context.getQualifiedTemplateName(Qualifier, false,
- cast<TemplateDecl>(Template)));
- } else if (OverloadedFunctionDecl *Ovl
+ cast<TemplateDecl>(Template)));
+ } else if (OverloadedFunctionDecl *Ovl
= dyn_cast<OverloadedFunctionDecl>(Template)) {
TemplateResult = TemplateTy::make(TemplateName(Ovl));
} else {
TemplateResult = TemplateTy::make(
TemplateName(cast<TemplateDecl>(Template)));
}
-
- if (isa<ClassTemplateDecl>(Template) ||
+
+ if (isa<ClassTemplateDecl>(Template) ||
isa<TemplateTemplateParmDecl>(Template))
return TNK_Type_template;
-
- assert((isa<FunctionTemplateDecl>(Template) ||
+
+ assert((isa<FunctionTemplateDecl>(Template) ||
isa<OverloadedFunctionDecl>(Template)) &&
"Unhandled template kind in Sema::isTemplateName");
return TNK_Function_template;
@@ -246,7 +246,7 @@ bool Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) {
// C++ [temp.local]p4:
// A template-parameter shall not be redeclared within its
// scope (including nested scopes).
- Diag(Loc, diag::err_template_param_shadow)
+ Diag(Loc, diag::err_template_param_shadow)
<< cast<NamedDecl>(PrevDecl)->getDeclName();
Diag(PrevDecl->getLocation(), diag::note_template_param_here);
return true;
@@ -269,24 +269,24 @@ TemplateDecl *Sema::AdjustDeclIfTemplate(DeclPtrTy &D) {
/// (otherwise, "class" was used), and KeyLoc is the location of the
/// "class" or "typename" keyword. ParamName is the name of the
/// parameter (NULL indicates an unnamed template parameter) and
-/// ParamName is the location of the parameter name (if any).
+/// ParamName is the location of the parameter name (if any).
/// If the type parameter has a default argument, it will be added
/// later via ActOnTypeParameterDefault.
-Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
+Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
SourceLocation EllipsisLoc,
SourceLocation KeyLoc,
IdentifierInfo *ParamName,
SourceLocation ParamNameLoc,
unsigned Depth, unsigned Position) {
- assert(S->isTemplateParamScope() &&
- "Template type parameter not in template parameter scope!");
+ assert(S->isTemplateParamScope() &&
+ "Template type parameter not in template parameter scope!");
bool Invalid = false;
if (ParamName) {
NamedDecl *PrevDecl = LookupName(S, ParamName, LookupTagName);
if (PrevDecl && PrevDecl->isTemplateParameter())
Invalid = Invalid || DiagnoseTemplateParameterShadow(ParamNameLoc,
- PrevDecl);
+ PrevDecl);
}
SourceLocation Loc = ParamNameLoc;
@@ -294,8 +294,8 @@ Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
Loc = KeyLoc;
TemplateTypeParmDecl *Param
- = TemplateTypeParmDecl::Create(Context, CurContext, Loc,
- Depth, Position, ParamName, Typename,
+ = TemplateTypeParmDecl::Create(Context, CurContext, Loc,
+ Depth, Position, ParamName, Typename,
Ellipsis);
if (Invalid)
Param->setInvalidDecl();
@@ -310,28 +310,28 @@ Sema::DeclPtrTy Sema::ActOnTypeParameter(Scope *S, bool Typename, bool Ellipsis,
}
/// ActOnTypeParameterDefault - Adds a default argument (the type
-/// Default) to the given template type parameter (TypeParam).
-void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam,
+/// Default) to the given template type parameter (TypeParam).
+void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam,
SourceLocation EqualLoc,
- SourceLocation DefaultLoc,
+ SourceLocation DefaultLoc,
TypeTy *DefaultT) {
- TemplateTypeParmDecl *Parm
+ TemplateTypeParmDecl *Parm
= cast<TemplateTypeParmDecl>(TypeParam.getAs<Decl>());
// FIXME: Preserve type source info.
QualType Default = GetTypeFromParser(DefaultT);
// C++0x [temp.param]p9:
// A default template-argument may be specified for any kind of
- // template-parameter that is not a template parameter pack.
+ // template-parameter that is not a template parameter pack.
if (Parm->isParameterPack()) {
Diag(DefaultLoc, diag::err_template_param_pack_default_arg);
return;
}
-
+
// C++ [temp.param]p14:
// A template-parameter shall not be used in its own default argument.
// FIXME: Implement this check! Needs a recursive walk over the types.
-
+
// Check the template argument itself.
if (CheckTemplateArgument(Parm, Default, DefaultLoc)) {
Parm->setInvalidDecl();
@@ -346,7 +346,7 @@ void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam,
///
/// \returns the (possibly-promoted) parameter type if valid;
/// otherwise, produces a diagnostic and returns a NULL type.
-QualType
+QualType
Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) {
// C++ [temp.param]p4:
//
@@ -355,11 +355,11 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) {
//
// -- integral or enumeration type,
if (T->isIntegralType() || T->isEnumeralType() ||
- // -- pointer to object or pointer to function,
- (T->isPointerType() &&
+ // -- pointer to object or pointer to function,
+ (T->isPointerType() &&
(T->getAs<PointerType>()->getPointeeType()->isObjectType() ||
T->getAs<PointerType>()->getPointeeType()->isFunctionType())) ||
- // -- reference to object or reference to function,
+ // -- reference to object or reference to function,
T->isReferenceType() ||
// -- pointer to member.
T->isMemberPointerType() ||
@@ -390,7 +390,7 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) {
/// class Array") has been parsed. S is the current scope and D is
/// the parsed declarator.
Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
- unsigned Depth,
+ unsigned Depth,
unsigned Position) {
DeclaratorInfo *DInfo = 0;
QualType T = GetTypeForDeclarator(D, S, &DInfo);
@@ -432,14 +432,14 @@ Sema::DeclPtrTy Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD,
SourceLocation EqualLoc,
ExprArg DefaultE) {
- NonTypeTemplateParmDecl *TemplateParm
+ NonTypeTemplateParmDecl *TemplateParm
= cast<NonTypeTemplateParmDecl>(TemplateParamD.getAs<Decl>());
Expr *Default = static_cast<Expr *>(DefaultE.get());
-
+
// C++ [temp.param]p14:
// A template-parameter shall not be used in its own default argument.
// FIXME: Implement this check! Needs a recursive walk over the types.
-
+
// Check the well-formedness of the default template argument.
TemplateArgument Converted;
if (CheckTemplateArgument(TemplateParm, TemplateParm->getType(), Default,
@@ -461,8 +461,7 @@ Sema::DeclPtrTy Sema::ActOnTemplateTemplateParameter(Scope* S,
IdentifierInfo *Name,
SourceLocation NameLoc,
unsigned Depth,
- unsigned Position)
-{
+ unsigned Position) {
assert(S->isTemplateParamScope() &&
"Template template parameter not in template parameter scope!");
@@ -496,12 +495,12 @@ Sema::DeclPtrTy Sema::ActOnTemplateTemplateParameter(Scope* S,
void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD,
SourceLocation EqualLoc,
ExprArg DefaultE) {
- TemplateTemplateParmDecl *TemplateParm
+ TemplateTemplateParmDecl *TemplateParm
= cast<TemplateTemplateParmDecl>(TemplateParamD.getAs<Decl>());
// Since a template-template parameter's default argument is an
// id-expression, it must be a DeclRefExpr.
- DeclRefExpr *Default
+ DeclRefExpr *Default
= cast<DeclRefExpr>(static_cast<Expr *>(DefaultE.get()));
// C++ [temp.param]p14:
@@ -510,12 +509,12 @@ void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD,
// Check the well-formedness of the template argument.
if (!isa<TemplateDecl>(Default->getDecl())) {
- Diag(Default->getSourceRange().getBegin(),
+ Diag(Default->getSourceRange().getBegin(),
diag::err_template_arg_must_be_template)
<< Default->getSourceRange();
TemplateParm->setInvalidDecl();
return;
- }
+ }
if (CheckTemplateArgument(TemplateParm, Default)) {
TemplateParm->setInvalidDecl();
return;
@@ -530,7 +529,7 @@ void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD,
Sema::TemplateParamsTy *
Sema::ActOnTemplateParameterList(unsigned Depth,
SourceLocation ExportLoc,
- SourceLocation TemplateLoc,
+ SourceLocation TemplateLoc,
SourceLocation LAngleLoc,
DeclPtrTy *Params, unsigned NumParams,
SourceLocation RAngleLoc) {
@@ -548,7 +547,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
AttributeList *Attr,
TemplateParameterList *TemplateParams,
AccessSpecifier AS) {
- assert(TemplateParams && TemplateParams->size() > 0 &&
+ assert(TemplateParams && TemplateParams->size() > 0 &&
"No template parameters");
assert(TUK != TUK_Reference && "Can only declare or define class templates");
bool Invalid = false;
@@ -580,14 +579,14 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
// FIXME: Produce a reasonable diagnostic here
return true;
}
-
- Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName,
+
+ Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName,
true);
} else {
SemanticContext = CurContext;
Previous = LookupName(S, Name, LookupOrdinaryName, true);
}
-
+
assert(!Previous.isAmbiguous() && "Ambiguity in class template redecl?");
NamedDecl *PrevDecl = 0;
if (Previous.begin() != Previous.end())
@@ -595,10 +594,10 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S))
PrevDecl = 0;
-
+
// If there is a previous declaration with the same name, check
// whether this is a valid redeclaration.
- ClassTemplateDecl *PrevClassTemplate
+ ClassTemplateDecl *PrevClassTemplate
= dyn_cast_or_null<ClassTemplateDecl>(PrevDecl);
if (PrevClassTemplate) {
// Ensure that the template parameter lists are compatible.
@@ -614,9 +613,9 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
// template declaration (7.1.5.3).
RecordDecl *PrevRecordDecl = PrevClassTemplate->getTemplatedDecl();
if (!isAcceptableTagRedeclaration(PrevRecordDecl, Kind, KWLoc, *Name)) {
- Diag(KWLoc, diag::err_use_with_wrong_tag)
+ Diag(KWLoc, diag::err_use_with_wrong_tag)
<< Name
- << CodeModificationHint::CreateReplacement(KWLoc,
+ << CodeModificationHint::CreateReplacement(KWLoc,
PrevRecordDecl->getKindName());
Diag(PrevRecordDecl->getLocation(), diag::note_previous_use);
Kind = PrevRecordDecl->getTagKind();
@@ -654,13 +653,13 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
if (CheckTemplateParameterList(TemplateParams,
PrevClassTemplate? PrevClassTemplate->getTemplateParameters() : 0))
Invalid = true;
-
+
// FIXME: If we had a scope specifier, we better have a previous template
// declaration!
- CXXRecordDecl *NewClass =
+ CXXRecordDecl *NewClass =
CXXRecordDecl::Create(Context, Kind, SemanticContext, NameLoc, Name, KWLoc,
- PrevClassTemplate?
+ PrevClassTemplate?
PrevClassTemplate->getTemplatedDecl() : 0,
/*DelayTypeCreation=*/true);
@@ -671,16 +670,16 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
NewClass->setDescribedClassTemplate(NewTemplate);
// Build the type for the class template declaration now.
- QualType T =
- Context.getTypeDeclType(NewClass,
- PrevClassTemplate?
- PrevClassTemplate->getTemplatedDecl() : 0);
+ QualType T =
+ Context.getTypeDeclType(NewClass,
+ PrevClassTemplate?
+ PrevClassTemplate->getTemplatedDecl() : 0);
assert(T->isDependentType() && "Class template type is not dependent?");
(void)T;
// Set the access specifier.
SetMemberAccessSpecifier(NewTemplate, PrevClassTemplate, AS);
-
+
// Set the lexical context of these templates
NewClass->setLexicalDeclContext(CurContext);
NewTemplate->setLexicalDeclContext(CurContext);
@@ -722,7 +721,7 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
TemplateParameterList *OldParams) {
bool Invalid = false;
-
+
// C++ [temp.param]p10:
// The set of default template-arguments available for use with a
// template declaration or definition is obtained by merging the
@@ -755,7 +754,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// If a template parameter of a class template is a template parameter pack,
// it must be the last template parameter.
if (SawParameterPack) {
- Diag(ParameterPackLoc,
+ Diag(ParameterPackLoc,
diag::err_template_param_pack_must_be_last_template_parameter);
Invalid = true;
}
@@ -763,15 +762,15 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// Merge default arguments for template type parameters.
if (TemplateTypeParmDecl *NewTypeParm
= dyn_cast<TemplateTypeParmDecl>(*NewParam)) {
- TemplateTypeParmDecl *OldTypeParm
+ TemplateTypeParmDecl *OldTypeParm
= OldParams? cast<TemplateTypeParmDecl>(*OldParam) : 0;
-
+
if (NewTypeParm->isParameterPack()) {
assert(!NewTypeParm->hasDefaultArgument() &&
"Parameter packs can't have a default argument!");
SawParameterPack = true;
ParameterPackLoc = NewTypeParm->getLocation();
- } else if (OldTypeParm && OldTypeParm->hasDefaultArgument() &&
+ } else if (OldTypeParm && OldTypeParm->hasDefaultArgument() &&
NewTypeParm->hasDefaultArgument()) {
OldDefaultLoc = OldTypeParm->getDefaultArgumentLoc();
NewDefaultLoc = NewTypeParm->getDefaultArgumentLoc();
@@ -796,7 +795,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// Merge default arguments for non-type template parameters
NonTypeTemplateParmDecl *OldNonTypeParm
= OldParams? cast<NonTypeTemplateParmDecl>(*OldParam) : 0;
- if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument() &&
+ if (OldNonTypeParm && OldNonTypeParm->hasDefaultArgument() &&
NewNonTypeParm->hasDefaultArgument()) {
OldDefaultLoc = OldNonTypeParm->getDefaultArgumentLoc();
NewDefaultLoc = NewNonTypeParm->getDefaultArgumentLoc();
@@ -817,14 +816,14 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
SawDefaultArgument = true;
PreviousDefaultArgLoc = NewNonTypeParm->getDefaultArgumentLoc();
} else if (SawDefaultArgument)
- MissingDefaultArg = true;
+ MissingDefaultArg = true;
} else {
// Merge default arguments for template template parameters
TemplateTemplateParmDecl *NewTemplateParm
= cast<TemplateTemplateParmDecl>(*NewParam);
TemplateTemplateParmDecl *OldTemplateParm
= OldParams? cast<TemplateTemplateParmDecl>(*OldParam) : 0;
- if (OldTemplateParm && OldTemplateParm->hasDefaultArgument() &&
+ if (OldTemplateParm && OldTemplateParm->hasDefaultArgument() &&
NewTemplateParm->hasDefaultArgument()) {
OldDefaultLoc = OldTemplateParm->getDefaultArgumentLoc();
NewDefaultLoc = NewTemplateParm->getDefaultArgumentLoc();
@@ -844,7 +843,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
SawDefaultArgument = true;
PreviousDefaultArgLoc = NewTemplateParm->getDefaultArgumentLoc();
} else if (SawDefaultArgument)
- MissingDefaultArg = true;
+ MissingDefaultArg = true;
}
if (RedundantDefaultArg) {
@@ -859,7 +858,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// If a template-parameter has a default template-argument,
// all subsequent template-parameters shall have a default
// template-argument supplied.
- Diag((*NewParam)->getLocation(),
+ Diag((*NewParam)->getLocation(),
diag::err_template_param_default_arg_missing);
Diag(PreviousDefaultArgLoc, diag::note_template_param_prev_default_arg);
Invalid = true;
@@ -874,13 +873,13 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
return Invalid;
}
-/// \brief Match the given template parameter lists to the given scope
+/// \brief Match the given template parameter lists to the given scope
/// specifier, returning the template parameter list that applies to the
/// name.
///
/// \param DeclStartLoc the start of the declaration that has a scope
/// specifier or a template parameter list.
-///
+///
/// \param SS the scope specifier that will be matched to the given template
/// parameter lists. This scope specifier precedes a qualified name that is
/// being declared.
@@ -890,10 +889,10 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
///
/// \param NumParamLists the number of template parameter lists in ParamLists.
///
-/// \returns the template parameter list, if any, that corresponds to the
+/// \returns the template parameter list, if any, that corresponds to the
/// name that is preceded by the scope specifier @p SS. This template
/// parameter list may be have template parameters (if we're declaring a
-/// template) or may have no template parameters (if we're declaring a
+/// template) or may have no template parameters (if we're declaring a
/// template specialization), or may be NULL (if we were's declaring isn't
/// itself a template).
TemplateParameterList *
@@ -907,35 +906,35 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
TemplateIdsInSpecifier;
for (NestedNameSpecifier *NNS = (NestedNameSpecifier *)SS.getScopeRep();
NNS; NNS = NNS->getPrefix()) {
- if (const TemplateSpecializationType *SpecType
+ if (const TemplateSpecializationType *SpecType
= dyn_cast_or_null<TemplateSpecializationType>(NNS->getAsType())) {
TemplateDecl *Template = SpecType->getTemplateName().getAsTemplateDecl();
if (!Template)
continue; // FIXME: should this be an error? probably...
-
+
if (const RecordType *Record = SpecType->getAs<RecordType>()) {
ClassTemplateSpecializationDecl *SpecDecl
= cast<ClassTemplateSpecializationDecl>(Record->getDecl());
// If the nested name specifier refers to an explicit specialization,
// we don't need a template<> header.
- // FIXME: revisit this approach once we cope with specialization
+ // FIXME: revisit this approach once we cope with specialization
// properly.
if (SpecDecl->getSpecializationKind() == TSK_ExplicitSpecialization)
continue;
}
-
+
TemplateIdsInSpecifier.push_back(SpecType);
}
}
-
+
// Reverse the list of template-ids in the scope specifier, so that we can
// more easily match up the template-ids and the template parameter lists.
std::reverse(TemplateIdsInSpecifier.begin(), TemplateIdsInSpecifier.end());
-
+
SourceLocation FirstTemplateLoc = DeclStartLoc;
if (NumParamLists)
FirstTemplateLoc = ParamLists[0]->getTemplateLoc();
-
+
// Match the template-ids found in the specifier to the template parameter
// lists.
unsigned Idx = 0;
@@ -947,8 +946,8 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
// We have a template-id without a corresponding template parameter
// list.
if (DependentTemplateId) {
- // FIXME: the location information here isn't great.
- Diag(SS.getRange().getBegin(),
+ // FIXME: the location information here isn't great.
+ Diag(SS.getRange().getBegin(),
diag::err_template_spec_needs_template_parameters)
<< TemplateId
<< SS.getRange();
@@ -960,13 +959,13 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
}
return 0;
}
-
+
// Check the template parameter list against its corresponding template-id.
if (DependentTemplateId) {
- TemplateDecl *Template
+ TemplateDecl *Template
= TemplateIdsInSpecifier[Idx]->getTemplateName().getAsTemplateDecl();
- if (ClassTemplateDecl *ClassTemplate
+ if (ClassTemplateDecl *ClassTemplate
= dyn_cast<ClassTemplateDecl>(Template)) {
TemplateParameterList *ExpectedTemplateParams = 0;
// Is this template-id naming the primary template?
@@ -979,34 +978,34 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
ExpectedTemplateParams = PartialSpec->getTemplateParameters();
if (ExpectedTemplateParams)
- TemplateParameterListsAreEqual(ParamLists[Idx],
+ TemplateParameterListsAreEqual(ParamLists[Idx],
ExpectedTemplateParams,
true);
- }
+ }
} else if (ParamLists[Idx]->size() > 0)
- Diag(ParamLists[Idx]->getTemplateLoc(),
+ Diag(ParamLists[Idx]->getTemplateLoc(),
diag::err_template_param_list_matches_nontemplate)
<< TemplateId
<< ParamLists[Idx]->getSourceRange();
}
-
+
// If there were at least as many template-ids as there were template
// parameter lists, then there are no template parameter lists remaining for
// the declaration itself.
if (Idx >= NumParamLists)
return 0;
-
+
// If there were too many template parameter lists, complain about that now.
if (Idx != NumParamLists - 1) {
while (Idx < NumParamLists - 1) {
- Diag(ParamLists[Idx]->getTemplateLoc(),
+ Diag(ParamLists[Idx]->getTemplateLoc(),
diag::err_template_spec_extra_headers)
<< SourceRange(ParamLists[Idx]->getTemplateLoc(),
ParamLists[Idx]->getRAngleLoc());
++Idx;
}
}
-
+
// Return the last template parameter list, which corresponds to the
// entity being declared.
return ParamLists[NumParamLists - 1];
@@ -1014,8 +1013,8 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
/// \brief Translates template arguments as provided by the parser
/// into template arguments used by semantic analysis.
-static void
-translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn,
+static void
+translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn,
SourceLocation *TemplateArgLocs,
llvm::SmallVector<TemplateArgument, 16> &TemplateArgs) {
TemplateArgs.reserve(TemplateArgsIn.size());
@@ -1049,12 +1048,12 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// template.
TemplateArgumentListBuilder Converted(Template->getTemplateParameters(),
NumTemplateArgs);
- if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc,
+ if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc,
TemplateArgs, NumTemplateArgs, RAngleLoc,
false, Converted))
return QualType();
- assert((Converted.structuredSize() ==
+ assert((Converted.structuredSize() ==
Template->getTemplateParameters()->size()) &&
"Converted template argument list is too short!");
@@ -1071,21 +1070,21 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
//
// template<typename T, typename U = T> struct A;
TemplateName CanonName = Context.getCanonicalTemplateName(Name);
- CanonType = Context.getTemplateSpecializationType(CanonName,
+ CanonType = Context.getTemplateSpecializationType(CanonName,
Converted.getFlatArguments(),
Converted.flatSize());
-
+
// FIXME: CanonType is not actually the canonical type, and unfortunately
// it is a TemplateTypeSpecializationType that we will never use again.
// In the future, we need to teach getTemplateSpecializationType to only
// build the canonical type and return that to us.
CanonType = Context.getCanonicalType(CanonType);
- } else if (ClassTemplateDecl *ClassTemplate
+ } else if (ClassTemplateDecl *ClassTemplate
= dyn_cast<ClassTemplateDecl>(Template)) {
// Find the class template specialization declaration that
// corresponds to these arguments.
llvm::FoldingSetNodeID ID;
- ClassTemplateSpecializationDecl::Profile(ID,
+ ClassTemplateSpecializationDecl::Profile(ID,
Converted.getFlatArguments(),
Converted.flatSize(),
Context);
@@ -1096,7 +1095,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// This is the first time we have referenced this class template
// specialization. Create the canonical declaration and add it to
// the set of specializations.
- Decl = ClassTemplateSpecializationDecl::Create(Context,
+ Decl = ClassTemplateSpecializationDecl::Create(Context,
ClassTemplate->getDeclContext(),
TemplateLoc,
ClassTemplate,
@@ -1107,7 +1106,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
CanonType = Context.getTypeDeclType(Decl);
}
-
+
// Build the fully-sugared type for this class template
// specialization, which refers back to the class template
// specialization we created or found.
@@ -1118,7 +1117,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
Action::TypeResult
Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
+ SourceLocation LAngleLoc,
ASTTemplateArgsPtr TemplateArgsIn,
SourceLocation *TemplateArgLocs,
SourceLocation RAngleLoc) {
@@ -1151,7 +1150,7 @@ Sema::TypeResult Sema::ActOnTagTemplateIdType(TypeResult TypeResult,
// Verify the tag specifier.
TagDecl::TagKind TagKind = TagDecl::getTagKindForTypeSpec(TagSpec);
-
+
if (const RecordType *RT = Type->getAs<RecordType>()) {
RecordDecl *D = RT->getDecl();
@@ -1179,14 +1178,14 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(TemplateName Template,
SourceLocation RAngleLoc) {
// FIXME: Can we do any checking at this point? I guess we could check the
// template arguments that we have against the template name, if the template
- // name refers to a single template. That's not a terribly common case,
+ // name refers to a single template. That's not a terribly common case,
// though.
- return Owned(TemplateIdRefExpr::Create(Context,
+ return Owned(TemplateIdRefExpr::Create(Context,
/*FIXME: New type?*/Context.OverloadTy,
/*FIXME: Necessary?*/0,
/*FIXME: Necessary?*/SourceRange(),
Template, TemplateNameLoc, LAngleLoc,
- TemplateArgs,
+ TemplateArgs,
NumTemplateArgs, RAngleLoc));
}
@@ -1197,12 +1196,12 @@ Sema::OwningExprResult Sema::ActOnTemplateIdExpr(TemplateTy TemplateD,
SourceLocation *TemplateArgLocs,
SourceLocation RAngleLoc) {
TemplateName Template = TemplateD.getAsVal<TemplateName>();
-
+
// Translate the parser's template argument list in our AST format.
llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
TemplateArgsIn.release();
-
+
return BuildTemplateIdExpr(Template, TemplateNameLoc, LAngleLoc,
TemplateArgs.data(), TemplateArgs.size(),
RAngleLoc);
@@ -1220,7 +1219,7 @@ Sema::ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base,
SourceLocation *TemplateArgLocs,
SourceLocation RAngleLoc) {
TemplateName Template = TemplateD.getAsVal<TemplateName>();
-
+
// FIXME: We're going to end up looking up the template based on its name,
// twice!
DeclarationName Name;
@@ -1230,17 +1229,17 @@ Sema::ActOnMemberTemplateIdReferenceExpr(Scope *S, ExprArg Base,
Name = Ovl->getDeclName();
else
Name = Template.getAsDependentTemplateName()->getName();
-
+
// Translate the parser's template argument list in our AST format.
llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
TemplateArgsIn.release();
-
+
// Do we have the save the actual template name? We might need it...
return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, TemplateNameLoc,
Name, true, LAngleLoc,
TemplateArgs.data(), TemplateArgs.size(),
- RAngleLoc, DeclPtrTy(), &SS);
<