aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp186
1 files changed, 90 insertions, 96 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 28925cc..681bfe0 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1506,17 +1506,17 @@ TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
bool IsTypeAlias) {
bool Invalid = false;
- TypeSourceInfo *DI = D->getTypeSourceInfo();
- if (DI->getType()->isInstantiationDependentType() ||
- DI->getType()->isVariablyModifiedType()) {
- DI = SemaRef.SubstType(DI, TemplateArgs,
- D->getLocation(), D->getDeclName());
- if (!DI) {
+ TypeSourceInfo *TSI = D->getTypeSourceInfo();
+ if (TSI->getType()->isInstantiationDependentType() ||
+ TSI->getType()->isVariablyModifiedType()) {
+ TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(),
+ D->getDeclName());
+ if (!TSI) {
Invalid = true;
- DI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy);
+ TSI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy);
}
} else {
- SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
+ SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType());
}
// HACK: 2012-10-23 g++ has a bug where it gets the value kind of ?: wrong.
@@ -1525,7 +1525,7 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
// semantics. See LWG issue 2141 for more information on the bug. The bugs
// are fixed in g++ and libstdc++ 4.9.0 (2014-04-22).
if (SemaRef.getPreprocessor().NeedsStdLibCxxWorkaroundBefore(2014'04'22)) {
- const DecltypeType *DT = DI->getType()->getAs<DecltypeType>();
+ const DecltypeType *DT = TSI->getType()->getAs<DecltypeType>();
CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
if (DT && RD && isa<ConditionalOperator>(DT->getUnderlyingExpr()) &&
DT->isReferenceType() &&
@@ -1534,18 +1534,18 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
D->getIdentifier() && D->getIdentifier()->isStr("type") &&
SemaRef.getSourceManager().isInSystemHeader(D->getBeginLoc()))
// Fold it to the (non-reference) type which g++ would have produced.
- DI = SemaRef.Context.getTrivialTypeSourceInfo(
- DI->getType().getNonReferenceType());
+ TSI = SemaRef.Context.getTrivialTypeSourceInfo(
+ TSI->getType().getNonReferenceType());
}
// Create the new typedef
TypedefNameDecl *Typedef;
if (IsTypeAlias)
Typedef = TypeAliasDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(),
- D->getLocation(), D->getIdentifier(), DI);
+ D->getLocation(), D->getIdentifier(), TSI);
else
Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(),
- D->getLocation(), D->getIdentifier(), DI);
+ D->getLocation(), D->getIdentifier(), TSI);
if (Invalid)
Typedef->setInvalidDecl();
@@ -1554,7 +1554,7 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
if (const TagType *oldTagType = D->getUnderlyingType()->getAs<TagType>()) {
TagDecl *oldTag = oldTagType->getDecl();
if (oldTag->getTypedefNameForAnonDecl() == D && !Invalid) {
- TagDecl *newTag = DI->getType()->castAs<TagType>()->getDecl();
+ TagDecl *newTag = TSI->getType()->castAs<TagType>()->getDecl();
assert(!newTag->hasNameForLinkage());
newTag->setTypedefNameForAnonDecl(Typedef);
}
@@ -1719,15 +1719,15 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
ArrayRef<BindingDecl*> *Bindings) {
// Do substitution on the type of the declaration
- TypeSourceInfo *DI = SemaRef.SubstType(
+ TypeSourceInfo *TSI = SemaRef.SubstType(
D->getTypeSourceInfo(), TemplateArgs, D->getTypeSpecStartLoc(),
- D->getDeclName(), /*AllowDeducedTST*/true);
- if (!DI)
+ D->getDeclName(), /*AllowDeducedTST*/ true);
+ if (!TSI)
return nullptr;
- if (DI->getType()->isFunctionType()) {
+ if (TSI->getType()->isFunctionType()) {
SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
- << D->isStaticDataMember() << DI->getType();
+ << D->isStaticDataMember() << TSI->getType();
return nullptr;
}
@@ -1739,12 +1739,12 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
VarDecl *Var;
if (Bindings)
Var = DecompositionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
- D->getLocation(), DI->getType(), DI,
+ D->getLocation(), TSI->getType(), TSI,
D->getStorageClass(), *Bindings);
else
Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
- D->getLocation(), D->getIdentifier(), DI->getType(),
- DI, D->getStorageClass());
+ D->getLocation(), D->getIdentifier(), TSI->getType(),
+ TSI, D->getStorageClass());
// In ARC, infer 'retaining' for variables of retainable type.
if (SemaRef.getLangOpts().ObjCAutoRefCount &&
@@ -1810,15 +1810,15 @@ Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) {
Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
bool Invalid = false;
- TypeSourceInfo *DI = D->getTypeSourceInfo();
- if (DI->getType()->isInstantiationDependentType() ||
- DI->getType()->isVariablyModifiedType()) {
- DI = SemaRef.SubstType(DI, TemplateArgs,
- D->getLocation(), D->getDeclName());
- if (!DI) {
- DI = D->getTypeSourceInfo();
+ TypeSourceInfo *TSI = D->getTypeSourceInfo();
+ if (TSI->getType()->isInstantiationDependentType() ||
+ TSI->getType()->isVariablyModifiedType()) {
+ TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(),
+ D->getDeclName());
+ if (!TSI) {
+ TSI = D->getTypeSourceInfo();
Invalid = true;
- } else if (DI->getType()->isFunctionType()) {
+ } else if (TSI->getType()->isFunctionType()) {
// C++ [temp.arg.type]p3:
// If a declaration acquires a function type through a type
// dependent on a template-parameter and this causes a
@@ -1826,11 +1826,11 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
// function declarator to have function type, the program is
// ill-formed.
SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
- << DI->getType();
+ << TSI->getType();
Invalid = true;
}
} else {
- SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
+ SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType());
}
Expr *BitWidth = D->getBitWidth();
@@ -1850,16 +1850,10 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
BitWidth = InstantiatedBitWidth.getAs<Expr>();
}
- FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(),
- DI->getType(), DI,
- cast<RecordDecl>(Owner),
- D->getLocation(),
- D->isMutable(),
- BitWidth,
- D->getInClassInitStyle(),
- D->getInnerLocStart(),
- D->getAccess(),
- nullptr);
+ FieldDecl *Field = SemaRef.CheckFieldDecl(
+ D->getDeclName(), TSI->getType(), TSI, cast<RecordDecl>(Owner),
+ D->getLocation(), D->isMutable(), BitWidth, D->getInClassInitStyle(),
+ D->getInnerLocStart(), D->getAccess(), nullptr);
if (!Field) {
cast<Decl>(Owner)->setInvalidDecl();
return nullptr;
@@ -1892,19 +1886,19 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) {
bool Invalid = false;
- TypeSourceInfo *DI = D->getTypeSourceInfo();
+ TypeSourceInfo *TSI = D->getTypeSourceInfo();
- if (DI->getType()->isVariablyModifiedType()) {
+ if (TSI->getType()->isVariablyModifiedType()) {
SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified)
<< D;
Invalid = true;
- } else if (DI->getType()->isInstantiationDependentType()) {
- DI = SemaRef.SubstType(DI, TemplateArgs,
- D->getLocation(), D->getDeclName());
- if (!DI) {
- DI = D->getTypeSourceInfo();
+ } else if (TSI->getType()->isInstantiationDependentType()) {
+ TSI = SemaRef.SubstType(TSI, TemplateArgs, D->getLocation(),
+ D->getDeclName());
+ if (!TSI) {
+ TSI = D->getTypeSourceInfo();
Invalid = true;
- } else if (DI->getType()->isFunctionType()) {
+ } else if (TSI->getType()->isFunctionType()) {
// C++ [temp.arg.type]p3:
// If a declaration acquires a function type through a type
// dependent on a template-parameter and this causes a
@@ -1912,16 +1906,17 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) {
// function declarator to have function type, the program is
// ill-formed.
SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
- << DI->getType();
+ << TSI->getType();
Invalid = true;
}
} else {
- SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
+ SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), TSI->getType());
}
MSPropertyDecl *Property = MSPropertyDecl::Create(
- SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(),
- DI, D->getBeginLoc(), D->getGetterId(), D->getSetterId());
+ SemaRef.Context, Owner, D->getLocation(), D->getDeclName(),
+ TSI->getType(), TSI, D->getBeginLoc(), D->getGetterId(),
+ D->getSetterId());
SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs,
StartingScope);
@@ -3584,7 +3579,7 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
SmallVector<TypeSourceInfo *, 4> ExpandedParameterPackTypesAsWritten;
SmallVector<QualType, 4> ExpandedParameterPackTypes;
bool IsExpandedParameterPack = false;
- TypeSourceInfo *DI;
+ TypeSourceInfo *TSI;
QualType T;
bool Invalid = false;
@@ -3594,24 +3589,24 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
ExpandedParameterPackTypes.reserve(D->getNumExpansionTypes());
ExpandedParameterPackTypesAsWritten.reserve(D->getNumExpansionTypes());
for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
- TypeSourceInfo *NewDI =
+ TypeSourceInfo *NewTSI =
SemaRef.SubstType(D->getExpansionTypeSourceInfo(I), TemplateArgs,
D->getLocation(), D->getDeclName());
- if (!NewDI)
+ if (!NewTSI)
return nullptr;
QualType NewT =
- SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation());
+ SemaRef.CheckNonTypeTemplateParameterType(NewTSI, D->getLocation());
if (NewT.isNull())
return nullptr;
- ExpandedParameterPackTypesAsWritten.push_back(NewDI);
+ ExpandedParameterPackTypesAsWritten.push_back(NewTSI);
ExpandedParameterPackTypes.push_back(NewT);
}
IsExpandedParameterPack = true;
- DI = D->getTypeSourceInfo();
- T = DI->getType();
+ TSI = D->getTypeSourceInfo();
+ T = TSI->getType();
} else if (D->isPackExpansion()) {
// The non-type template parameter pack's type is a pack expansion of types.
// Determine whether we need to expand this parameter pack into separate
@@ -3637,18 +3632,17 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
if (Expand) {
for (unsigned I = 0; I != *NumExpansions; ++I) {
Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
- TypeSourceInfo *NewDI = SemaRef.SubstType(Pattern, TemplateArgs,
- D->getLocation(),
- D->getDeclName());
- if (!NewDI)
+ TypeSourceInfo *NewTSI = SemaRef.SubstType(
+ Pattern, TemplateArgs, D->getLocation(), D->getDeclName());
+ if (!NewTSI)
return nullptr;
QualType NewT =
- SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation());
+ SemaRef.CheckNonTypeTemplateParameterType(NewTSI, D->getLocation());
if (NewT.isNull())
return nullptr;
- ExpandedParameterPackTypesAsWritten.push_back(NewDI);
+ ExpandedParameterPackTypesAsWritten.push_back(NewTSI);
ExpandedParameterPackTypes.push_back(NewT);
}
@@ -3656,8 +3650,8 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
// expanded parameter pack is the original expansion type, but callers
// will end up using the expanded parameter pack types for type-checking.
IsExpandedParameterPack = true;
- DI = D->getTypeSourceInfo();
- T = DI->getType();
+ TSI = D->getTypeSourceInfo();
+ T = TSI->getType();
} else {
// We cannot fully expand the pack expansion now, so substitute into the
// pattern and create a new pack expansion type.
@@ -3669,22 +3663,22 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
return nullptr;
SemaRef.CheckNonTypeTemplateParameterType(NewPattern, D->getLocation());
- DI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(),
- NumExpansions);
- if (!DI)
+ TSI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(),
+ NumExpansions);
+ if (!TSI)
return nullptr;
- T = DI->getType();
+ T = TSI->getType();
}
} else {
// Simple case: substitution into a parameter that is not a parameter pack.
- DI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
- D->getLocation(), D->getDeclName());
- if (!DI)
+ TSI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
+ D->getLocation(), D->getDeclName());
+ if (!TSI)
return nullptr;
// Check that this type is acceptable for a non-type template parameter.
- T = SemaRef.CheckNonTypeTemplateParameterType(DI, D->getLocation());
+ T = SemaRef.CheckNonTypeTemplateParameterType(TSI, D->getLocation());
if (T.isNull()) {
T = SemaRef.Context.IntTy;
Invalid = true;
@@ -3696,20 +3690,20 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
Param = NonTypeTemplateParmDecl::Create(
SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
- D->getPosition(), D->getIdentifier(), T, DI, ExpandedParameterPackTypes,
- ExpandedParameterPackTypesAsWritten);
+ D->getPosition(), D->getIdentifier(), T, TSI,
+ ExpandedParameterPackTypes, ExpandedParameterPackTypesAsWritten);
else
Param = NonTypeTemplateParmDecl::Create(
SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
- D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), DI);
+ D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), TSI);
- if (AutoTypeLoc AutoLoc = DI->getTypeLoc().getContainedAutoTypeLoc())
+ if (AutoTypeLoc AutoLoc = TSI->getTypeLoc().getContainedAutoTypeLoc())
if (AutoLoc.isConstrained()) {
SourceLocation EllipsisLoc;
if (IsExpandedParameterPack)
EllipsisLoc =
- DI->getTypeLoc().getAs<PackExpansionTypeLoc>().getEllipsisLoc();
+ TSI->getTypeLoc().getAs<PackExpansionTypeLoc>().getEllipsisLoc();
else if (auto *Constraint = dyn_cast_if_present<CXXFoldExpr>(
D->getPlaceholderTypeConstraint()))
EllipsisLoc = Constraint->getEllipsisLoc();
@@ -4642,22 +4636,22 @@ TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
VarTemplateSpecializationDecl *PrevDecl) {
// Do substitution on the type of the declaration
- TypeSourceInfo *DI =
+ TypeSourceInfo *TSI =
SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
D->getTypeSpecStartLoc(), D->getDeclName());
- if (!DI)
+ if (!TSI)
return nullptr;
- if (DI->getType()->isFunctionType()) {
+ if (TSI->getType()->isFunctionType()) {
SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
- << D->isStaticDataMember() << DI->getType();
+ << D->isStaticDataMember() << TSI->getType();
return nullptr;
}
// Build the instantiated declaration
VarTemplateSpecializationDecl *Var = VarTemplateSpecializationDecl::Create(
SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
- VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted);
+ VarTemplate, TSI->getType(), TSI, D->getStorageClass(), Converted);
if (!PrevDecl) {
void *InsertPos = nullptr;
VarTemplate->findSpecialization(Converted, InsertPos);
@@ -5005,16 +4999,16 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
InstParams, InsertPos);
// Do substitution on the type of the declaration
- TypeSourceInfo *DI = SemaRef.SubstType(
+ TypeSourceInfo *TSI = SemaRef.SubstType(
PartialSpec->getTypeSourceInfo(), TemplateArgs,
PartialSpec->getTypeSpecStartLoc(), PartialSpec->getDeclName());
- if (!DI)
+ if (!TSI)
return nullptr;
- if (DI->getType()->isFunctionType()) {
+ if (TSI->getType()->isFunctionType()) {
SemaRef.Diag(PartialSpec->getLocation(),
diag::err_variable_instantiates_to_function)
- << PartialSpec->isStaticDataMember() << DI->getType();
+ << PartialSpec->isStaticDataMember() << TSI->getType();
return nullptr;
}
@@ -5022,8 +5016,8 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
VarTemplatePartialSpecializationDecl *InstPartialSpec =
VarTemplatePartialSpecializationDecl::Create(
SemaRef.Context, Owner, PartialSpec->getInnerLocStart(),
- PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(),
- DI, PartialSpec->getStorageClass(), CTAI.CanonicalConverted);
+ PartialSpec->getLocation(), InstParams, VarTemplate, TSI->getType(),
+ TSI, PartialSpec->getStorageClass(), CTAI.CanonicalConverted);
InstPartialSpec->setTemplateArgsAsWritten(InstTemplateArgs);
@@ -6026,14 +6020,14 @@ VarTemplateSpecializationDecl *Sema::CompleteVarTemplateSpecializationDecl(
"don't have a definition to instantiate from");
// Do substitution on the type of the declaration
- TypeSourceInfo *DI =
+ TypeSourceInfo *TSI =
SubstType(PatternDecl->getTypeSourceInfo(), TemplateArgs,
PatternDecl->getTypeSpecStartLoc(), PatternDecl->getDeclName());
- if (!DI)
+ if (!TSI)
return nullptr;
// Update the type of this variable template specialization.
- VarSpec->setType(DI->getType());
+ VarSpec->setType(TSI->getType());
// Convert the declaration into a definition now.
VarSpec->setCompleteDefinition();