2009-03-18 05:15:40 +08:00
|
|
|
//===--- SemaTemplateInstantiateDecl.cpp - C++ Template Decl Instantiation ===/
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//===----------------------------------------------------------------------===/
|
|
|
|
//
|
|
|
|
// This file implements C++ template instantiation for declarations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===/
|
2010-08-26 06:03:47 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2009-05-27 04:50:29 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
2009-03-18 05:15:40 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2014-03-23 07:33:22 +08:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
2009-03-18 05:15:40 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/DeclVisitor.h"
|
2010-03-24 13:22:00 +08:00
|
|
|
#include "clang/AST/DependentDiagnostic.h"
|
2009-03-18 05:15:40 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-12-13 02:16:41 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2010-03-11 17:03:00 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Sema/Lookup.h"
|
|
|
|
#include "clang/Sema/PrettyDeclStackTrace.h"
|
|
|
|
#include "clang/Sema/Template.h"
|
2009-03-18 05:15:40 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2013-11-27 16:20:38 +08:00
|
|
|
static bool isDeclWithinFunction(const Decl *D) {
|
|
|
|
const DeclContext *DC = D->getDeclContext();
|
|
|
|
if (DC->isFunctionOrMethod())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (DC->isRecord())
|
|
|
|
return cast<CXXRecordDecl>(DC)->isLocalClass();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-15 18:12:16 +08:00
|
|
|
bool TemplateDeclInstantiator::SubstQualifier(const DeclaratorDecl *OldDecl,
|
|
|
|
DeclaratorDecl *NewDecl) {
|
2011-02-25 10:25:35 +08:00
|
|
|
if (!OldDecl->getQualifierLoc())
|
|
|
|
return false;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc NewQualifierLoc
|
2011-10-08 19:31:46 +08:00
|
|
|
= SemaRef.SubstNestedNameSpecifierLoc(OldDecl->getQualifierLoc(),
|
2011-02-25 10:25:35 +08:00
|
|
|
TemplateArgs);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (!NewQualifierLoc)
|
2010-03-15 18:12:16 +08:00
|
|
|
return true;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NewDecl->setQualifierInfo(NewQualifierLoc);
|
2010-03-15 18:12:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TemplateDeclInstantiator::SubstQualifier(const TagDecl *OldDecl,
|
|
|
|
TagDecl *NewDecl) {
|
2011-02-25 10:25:35 +08:00
|
|
|
if (!OldDecl->getQualifierLoc())
|
|
|
|
return false;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc NewQualifierLoc
|
2011-10-08 19:31:46 +08:00
|
|
|
= SemaRef.SubstNestedNameSpecifierLoc(OldDecl->getQualifierLoc(),
|
2011-02-25 10:25:35 +08:00
|
|
|
TemplateArgs);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (!NewQualifierLoc)
|
2010-03-15 18:12:16 +08:00
|
|
|
return true;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NewDecl->setQualifierInfo(NewQualifierLoc);
|
2010-03-15 18:12:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-21 06:37:06 +08:00
|
|
|
// Include attribute instantiation code.
|
|
|
|
#include "clang/Sema/AttrTemplateInstantiate.inc"
|
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
static void instantiateDependentAlignedAttr(
|
|
|
|
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
|
|
|
|
const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion) {
|
|
|
|
if (Aligned->isAlignmentExpr()) {
|
|
|
|
// The alignment expression is a constant expression.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated);
|
|
|
|
ExprResult Result = S.SubstExpr(Aligned->getAlignmentExpr(), TemplateArgs);
|
|
|
|
if (!Result.isInvalid())
|
2014-05-29 18:55:11 +08:00
|
|
|
S.AddAlignedAttr(Aligned->getLocation(), New, Result.getAs<Expr>(),
|
2013-02-22 16:32:16 +08:00
|
|
|
Aligned->getSpellingListIndex(), IsPackExpansion);
|
|
|
|
} else {
|
|
|
|
TypeSourceInfo *Result = S.SubstType(Aligned->getAlignmentType(),
|
|
|
|
TemplateArgs, Aligned->getLocation(),
|
|
|
|
DeclarationName());
|
|
|
|
if (Result)
|
|
|
|
S.AddAlignedAttr(Aligned->getLocation(), New, Result,
|
|
|
|
Aligned->getSpellingListIndex(), IsPackExpansion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void instantiateDependentAlignedAttr(
|
|
|
|
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
|
|
|
|
const AlignedAttr *Aligned, Decl *New) {
|
|
|
|
if (!Aligned->isPackExpansion()) {
|
|
|
|
instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
if (Aligned->isAlignmentExpr())
|
|
|
|
S.collectUnexpandedParameterPacks(Aligned->getAlignmentExpr(),
|
|
|
|
Unexpanded);
|
|
|
|
else
|
|
|
|
S.collectUnexpandedParameterPacks(Aligned->getAlignmentType()->getTypeLoc(),
|
|
|
|
Unexpanded);
|
|
|
|
assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
|
|
|
|
|
|
|
|
// Determine whether we can expand this attribute pack yet.
|
|
|
|
bool Expand = true, RetainExpansion = false;
|
|
|
|
Optional<unsigned> NumExpansions;
|
|
|
|
// FIXME: Use the actual location of the ellipsis.
|
|
|
|
SourceLocation EllipsisLoc = Aligned->getLocation();
|
|
|
|
if (S.CheckParameterPacksForExpansion(EllipsisLoc, Aligned->getRange(),
|
|
|
|
Unexpanded, TemplateArgs, Expand,
|
|
|
|
RetainExpansion, NumExpansions))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!Expand) {
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, -1);
|
|
|
|
instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, true);
|
|
|
|
} else {
|
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, I);
|
|
|
|
instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-11 10:50:57 +08:00
|
|
|
static void instantiateDependentEnableIfAttr(
|
|
|
|
Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
|
|
|
|
const EnableIfAttr *A, const Decl *Tmpl, Decl *New) {
|
2014-05-26 14:22:03 +08:00
|
|
|
Expr *Cond = nullptr;
|
2014-01-11 10:50:57 +08:00
|
|
|
{
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated);
|
|
|
|
ExprResult Result = S.SubstExpr(A->getCond(), TemplateArgs);
|
|
|
|
if (Result.isInvalid())
|
|
|
|
return;
|
2014-05-29 18:55:11 +08:00
|
|
|
Cond = Result.getAs<Expr>();
|
2014-01-11 10:50:57 +08:00
|
|
|
}
|
|
|
|
if (A->getCond()->isTypeDependent() && !Cond->isTypeDependent()) {
|
|
|
|
ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
|
|
|
|
if (Converted.isInvalid())
|
|
|
|
return;
|
2014-05-29 18:55:11 +08:00
|
|
|
Cond = Converted.get();
|
2014-01-11 10:50:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<PartialDiagnosticAt, 8> Diags;
|
|
|
|
if (A->getCond()->isValueDependent() && !Cond->isValueDependent() &&
|
|
|
|
!Expr::isPotentialConstantExprUnevaluated(Cond, cast<FunctionDecl>(Tmpl),
|
|
|
|
Diags)) {
|
|
|
|
S.Diag(A->getLocation(), diag::err_enable_if_never_constant_expr);
|
|
|
|
for (int I = 0, N = Diags.size(); I != N; ++I)
|
|
|
|
S.Diag(Diags[I].first, Diags[I].second);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:03:14 +08:00
|
|
|
EnableIfAttr *EIA = new (S.getASTContext())
|
|
|
|
EnableIfAttr(A->getLocation(), S.getASTContext(), Cond,
|
|
|
|
A->getMessage(),
|
|
|
|
A->getSpellingListIndex());
|
2014-01-11 10:50:57 +08:00
|
|
|
New->addAttr(EIA);
|
|
|
|
}
|
|
|
|
|
2010-08-01 10:01:53 +08:00
|
|
|
void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
|
2012-01-21 06:50:54 +08:00
|
|
|
const Decl *Tmpl, Decl *New,
|
|
|
|
LateInstantiatedAttrVec *LateAttrs,
|
|
|
|
LocalInstantiationScope *OuterMostScope) {
|
2014-03-09 06:19:01 +08:00
|
|
|
for (const auto *TmplAttr : Tmpl->attrs()) {
|
2010-06-25 11:22:07 +08:00
|
|
|
// FIXME: This should be generalized to more than just the AlignedAttr.
|
2013-02-22 16:32:16 +08:00
|
|
|
const AlignedAttr *Aligned = dyn_cast<AlignedAttr>(TmplAttr);
|
|
|
|
if (Aligned && Aligned->isAlignmentDependent()) {
|
|
|
|
instantiateDependentAlignedAttr(*this, TemplateArgs, Aligned, New);
|
|
|
|
continue;
|
2010-06-25 11:22:07 +08:00
|
|
|
}
|
|
|
|
|
2014-01-11 10:50:57 +08:00
|
|
|
const EnableIfAttr *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr);
|
|
|
|
if (EnableIf && EnableIf->getCond()->isValueDependent()) {
|
|
|
|
instantiateDependentEnableIfAttr(*this, TemplateArgs, EnableIf, Tmpl,
|
|
|
|
New);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
assert(!TmplAttr->isPackExpansion());
|
2012-01-21 06:50:54 +08:00
|
|
|
if (TmplAttr->isLateParsed() && LateAttrs) {
|
|
|
|
// Late parsed attributes must be instantiated and attached after the
|
|
|
|
// enclosing class has been instantiated. See Sema::InstantiateClass.
|
2014-05-26 14:22:03 +08:00
|
|
|
LocalInstantiationScope *Saved = nullptr;
|
2012-01-21 06:50:54 +08:00
|
|
|
if (CurrentInstantiationScope)
|
|
|
|
Saved = CurrentInstantiationScope->cloneScopes(OuterMostScope);
|
|
|
|
LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New));
|
|
|
|
} else {
|
2013-06-07 10:33:37 +08:00
|
|
|
// Allow 'this' within late-parsed attributes.
|
|
|
|
NamedDecl *ND = dyn_cast<NamedDecl>(New);
|
|
|
|
CXXRecordDecl *ThisContext =
|
|
|
|
dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
|
|
|
|
CXXThisScopeRAII ThisScope(*this, ThisContext, /*TypeQuals*/0,
|
|
|
|
ND && ND->isCXXInstanceMember());
|
|
|
|
|
2012-02-06 19:13:08 +08:00
|
|
|
Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context,
|
|
|
|
*this, TemplateArgs);
|
2012-05-15 22:09:55 +08:00
|
|
|
if (NewAttr)
|
|
|
|
New->addAttr(NewAttr);
|
2012-01-21 06:50:54 +08:00
|
|
|
}
|
2009-11-07 14:07:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-25 23:45:12 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Translation units cannot be instantiated");
|
2009-03-25 23:45:12 +08:00
|
|
|
}
|
|
|
|
|
2011-02-18 04:34:02 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) {
|
|
|
|
LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(),
|
|
|
|
D->getIdentifier());
|
|
|
|
Owner->addDecl(Inst);
|
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
2009-03-25 23:45:12 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) {
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Namespaces cannot be instantiated");
|
2009-03-25 23:45:12 +08:00
|
|
|
}
|
|
|
|
|
2010-02-16 14:53:13 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
|
|
|
|
NamespaceAliasDecl *Inst
|
|
|
|
= NamespaceAliasDecl::Create(SemaRef.Context, Owner,
|
|
|
|
D->getNamespaceLoc(),
|
|
|
|
D->getAliasLoc(),
|
2011-02-26 01:08:07 +08:00
|
|
|
D->getIdentifier(),
|
|
|
|
D->getQualifierLoc(),
|
2010-02-16 14:53:13 +08:00
|
|
|
D->getTargetNameLoc(),
|
|
|
|
D->getNamespace());
|
|
|
|
Owner->addDecl(Inst);
|
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
2011-05-06 05:57:07 +08:00
|
|
|
Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
|
|
|
|
bool IsTypeAlias) {
|
2009-03-18 05:15:40 +08:00
|
|
|
bool Invalid = false;
|
2009-12-07 10:54:59 +08:00
|
|
|
TypeSourceInfo *DI = D->getTypeSourceInfo();
|
2011-07-01 09:22:09 +08:00
|
|
|
if (DI->getType()->isInstantiationDependentType() ||
|
2010-05-25 01:22:01 +08:00
|
|
|
DI->getType()->isVariablyModifiedType()) {
|
2009-10-24 16:00:42 +08:00
|
|
|
DI = SemaRef.SubstType(DI, TemplateArgs,
|
|
|
|
D->getLocation(), D->getDeclName());
|
|
|
|
if (!DI) {
|
2009-03-18 05:15:40 +08:00
|
|
|
Invalid = true;
|
2009-12-07 10:54:59 +08:00
|
|
|
DI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy);
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
2010-05-08 07:12:07 +08:00
|
|
|
} else {
|
|
|
|
SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-10-23 08:32:41 +08:00
|
|
|
// HACK: g++ has a bug where it gets the value kind of ?: wrong.
|
|
|
|
// libstdc++ relies upon this bug in its implementation of common_type.
|
|
|
|
// If we happen to be processing that implementation, fake up the g++ ?:
|
|
|
|
// semantics. See LWG issue 2141 for more information on the bug.
|
|
|
|
const DecltypeType *DT = DI->getType()->getAs<DecltypeType>();
|
|
|
|
CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
|
|
|
|
if (DT && RD && isa<ConditionalOperator>(DT->getUnderlyingExpr()) &&
|
|
|
|
DT->isReferenceType() &&
|
|
|
|
RD->getEnclosingNamespaceContext() == SemaRef.getStdNamespace() &&
|
|
|
|
RD->getIdentifier() && RD->getIdentifier()->isStr("common_type") &&
|
|
|
|
D->getIdentifier() && D->getIdentifier()->isStr("type") &&
|
|
|
|
SemaRef.getSourceManager().isInSystemHeader(D->getLocStart()))
|
|
|
|
// Fold it to the (non-reference) type which g++ would have produced.
|
|
|
|
DI = SemaRef.Context.getTrivialTypeSourceInfo(
|
|
|
|
DI->getType().getNonReferenceType());
|
|
|
|
|
2009-03-18 05:15:40 +08:00
|
|
|
// Create the new typedef
|
2011-04-15 22:24:37 +08:00
|
|
|
TypedefNameDecl *Typedef;
|
|
|
|
if (IsTypeAlias)
|
|
|
|
Typedef = TypeAliasDecl::Create(SemaRef.Context, Owner, D->getLocStart(),
|
|
|
|
D->getLocation(), D->getIdentifier(), DI);
|
|
|
|
else
|
|
|
|
Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocStart(),
|
|
|
|
D->getLocation(), D->getIdentifier(), DI);
|
2009-03-18 05:15:40 +08:00
|
|
|
if (Invalid)
|
|
|
|
Typedef->setInvalidDecl();
|
|
|
|
|
2011-02-01 16:20:08 +08:00
|
|
|
// If the old typedef was the name for linkage purposes of an anonymous
|
|
|
|
// tag decl, re-establish that relationship for the new typedef.
|
|
|
|
if (const TagType *oldTagType = D->getUnderlyingType()->getAs<TagType>()) {
|
|
|
|
TagDecl *oldTag = oldTagType->getDecl();
|
2013-03-09 06:15:15 +08:00
|
|
|
if (oldTag->getTypedefNameForAnonDecl() == D && !Invalid) {
|
2011-02-01 16:20:08 +08:00
|
|
|
TagDecl *newTag = DI->getType()->castAs<TagType>()->getDecl();
|
2013-03-09 08:54:27 +08:00
|
|
|
assert(!newTag->hasNameForLinkage());
|
2011-04-15 22:24:37 +08:00
|
|
|
newTag->setTypedefNameForAnonDecl(Typedef);
|
2011-02-01 16:20:08 +08:00
|
|
|
}
|
2010-04-24 00:25:07 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2012-01-15 00:38:05 +08:00
|
|
|
if (TypedefNameDecl *Prev = D->getPreviousDecl()) {
|
2010-03-01 23:56:25 +08:00
|
|
|
NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev,
|
|
|
|
TemplateArgs);
|
2011-03-05 03:46:35 +08:00
|
|
|
if (!InstPrev)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-12-27 06:42:47 +08:00
|
|
|
TypedefNameDecl *InstPrevTypedef = cast<TypedefNameDecl>(InstPrev);
|
|
|
|
|
|
|
|
// If the typedef types are not identical, reject them.
|
|
|
|
SemaRef.isIncompatibleTypedef(InstPrevTypedef, Typedef);
|
|
|
|
|
2013-10-17 23:37:26 +08:00
|
|
|
Typedef->setPreviousDecl(InstPrevTypedef);
|
2009-12-30 08:31:22 +08:00
|
|
|
}
|
|
|
|
|
2010-08-01 10:01:53 +08:00
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef);
|
2010-04-24 00:25:07 +08:00
|
|
|
|
2010-01-21 05:53:11 +08:00
|
|
|
Typedef->setAccess(D->getAccess());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-18 05:15:40 +08:00
|
|
|
return Typedef;
|
|
|
|
}
|
|
|
|
|
2011-04-15 22:24:37 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
|
2011-05-06 05:57:07 +08:00
|
|
|
Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/false);
|
|
|
|
Owner->addDecl(Typedef);
|
|
|
|
return Typedef;
|
2011-04-15 22:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) {
|
2011-05-06 05:57:07 +08:00
|
|
|
Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/true);
|
|
|
|
Owner->addDecl(Typedef);
|
|
|
|
return Typedef;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
|
|
|
|
// Create a local instantiation scope for this type alias template, which
|
|
|
|
// will contain the instantiations of the template parameters.
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
|
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-05-06 05:57:07 +08:00
|
|
|
|
|
|
|
TypeAliasDecl *Pattern = D->getTemplatedDecl();
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
TypeAliasTemplateDecl *PrevAliasTemplate = nullptr;
|
2012-01-15 00:38:05 +08:00
|
|
|
if (Pattern->getPreviousDecl()) {
|
2011-05-06 05:57:07 +08:00
|
|
|
DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
|
2012-12-19 08:45:41 +08:00
|
|
|
if (!Found.empty()) {
|
|
|
|
PrevAliasTemplate = dyn_cast<TypeAliasTemplateDecl>(Found.front());
|
2011-05-06 05:57:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeAliasDecl *AliasInst = cast_or_null<TypeAliasDecl>(
|
|
|
|
InstantiateTypedefNameDecl(Pattern, /*IsTypeAlias=*/true));
|
|
|
|
if (!AliasInst)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-05-06 05:57:07 +08:00
|
|
|
|
|
|
|
TypeAliasTemplateDecl *Inst
|
|
|
|
= TypeAliasTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(),
|
|
|
|
D->getDeclName(), InstParams, AliasInst);
|
|
|
|
if (PrevAliasTemplate)
|
2013-10-17 23:37:26 +08:00
|
|
|
Inst->setPreviousDecl(PrevAliasTemplate);
|
2011-05-06 05:57:07 +08:00
|
|
|
|
|
|
|
Inst->setAccess(D->getAccess());
|
|
|
|
|
|
|
|
if (!PrevAliasTemplate)
|
|
|
|
Inst->setInstantiatedFromMemberTemplate(D);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-05-06 05:57:07 +08:00
|
|
|
Owner->addDecl(Inst);
|
|
|
|
|
|
|
|
return Inst;
|
2011-04-15 22:24:37 +08:00
|
|
|
}
|
|
|
|
|
2009-03-26 07:32:15 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
|
2013-08-22 08:59:14 +08:00
|
|
|
return VisitVarDecl(D, /*InstantiatingVarTemplate=*/false);
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 08:59:14 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
|
|
|
|
bool InstantiatingVarTemplate) {
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2010-05-21 08:31:19 +08:00
|
|
|
// If this is the variable for an anonymous struct or union,
|
|
|
|
// instantiate the anonymous struct/union type first.
|
|
|
|
if (const RecordType *RecordTy = D->getType()->getAs<RecordType>())
|
|
|
|
if (RecordTy->getDecl()->isAnonymousStructOrUnion())
|
|
|
|
if (!VisitCXXRecordDecl(cast<CXXRecordDecl>(RecordTy->getDecl())))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-05-21 08:31:19 +08:00
|
|
|
|
2009-08-26 06:02:44 +08:00
|
|
|
// Do substitution on the type of the declaration
|
2009-12-07 10:54:59 +08:00
|
|
|
TypeSourceInfo *DI = SemaRef.SubstType(D->getTypeSourceInfo(),
|
2009-10-21 10:39:02 +08:00
|
|
|
TemplateArgs,
|
|
|
|
D->getTypeSpecStartLoc(),
|
|
|
|
D->getDeclName());
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-03-26 07:32:15 +08:00
|
|
|
|
2010-09-12 15:37:24 +08:00
|
|
|
if (DI->getType()->isFunctionType()) {
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
|
|
|
|
<< D->isStaticDataMember() << DI->getType();
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-09-12 15:37:24 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
DeclContext *DC = Owner;
|
|
|
|
if (D->isLocalExternDecl())
|
|
|
|
SemaRef.adjustContextForLocalExternDecl(DC);
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
// Build the instantiated declaration.
|
2013-09-20 09:15:31 +08:00
|
|
|
VarDecl *Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
|
2009-03-26 07:32:15 +08:00
|
|
|
D->getLocation(), D->getIdentifier(),
|
2013-08-06 09:03:05 +08:00
|
|
|
DI->getType(), DI, D->getStorageClass());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-12-10 09:22:52 +08:00
|
|
|
// In ARC, infer 'retaining' for variables of retainable type.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (SemaRef.getLangOpts().ObjCAutoRefCount &&
|
2011-12-10 09:22:52 +08:00
|
|
|
SemaRef.inferObjCARCLifetime(Var))
|
|
|
|
Var->setInvalidDecl();
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(D, Var))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-08-15 09:15:20 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
|
2013-08-22 08:59:14 +08:00
|
|
|
StartingScope, InstantiatingVarTemplate);
|
2014-05-03 08:41:18 +08:00
|
|
|
|
|
|
|
if (D->isNRVOVariable()) {
|
|
|
|
QualType ReturnType = cast<FunctionDecl>(DC)->getReturnType();
|
|
|
|
if (SemaRef.isCopyElisionCandidate(ReturnType, Var, false))
|
|
|
|
Var->setNRVOVariable(true);
|
|
|
|
}
|
|
|
|
|
2014-05-28 05:29:22 +08:00
|
|
|
Var->setImplicit(D->isImplicit());
|
|
|
|
|
2009-03-26 07:32:15 +08:00
|
|
|
return Var;
|
|
|
|
}
|
|
|
|
|
2010-06-05 13:09:32 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) {
|
|
|
|
AccessSpecDecl* AD
|
|
|
|
= AccessSpecDecl::Create(SemaRef.Context, D->getAccess(), Owner,
|
|
|
|
D->getAccessSpecifierLoc(), D->getColonLoc());
|
|
|
|
Owner->addHiddenDecl(AD);
|
|
|
|
return AD;
|
|
|
|
}
|
|
|
|
|
2009-03-18 05:15:40 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
|
|
|
|
bool Invalid = false;
|
2009-12-07 10:54:59 +08:00
|
|
|
TypeSourceInfo *DI = D->getTypeSourceInfo();
|
2011-07-01 09:22:09 +08:00
|
|
|
if (DI->getType()->isInstantiationDependentType() ||
|
2010-05-25 01:22:01 +08:00
|
|
|
DI->getType()->isVariablyModifiedType()) {
|
2009-10-23 07:33:21 +08:00
|
|
|
DI = SemaRef.SubstType(DI, TemplateArgs,
|
|
|
|
D->getLocation(), D->getDeclName());
|
|
|
|
if (!DI) {
|
2009-12-07 10:54:59 +08:00
|
|
|
DI = D->getTypeSourceInfo();
|
2009-10-23 07:33:21 +08:00
|
|
|
Invalid = true;
|
|
|
|
} else if (DI->getType()->isFunctionType()) {
|
2009-03-18 05:15:40 +08:00
|
|
|
// C++ [temp.arg.type]p3:
|
|
|
|
// If a declaration acquires a function type through a type
|
|
|
|
// dependent on a template-parameter and this causes a
|
|
|
|
// declaration that does not use the syntactic form of a
|
|
|
|
// function declarator to have function type, the program is
|
|
|
|
// ill-formed.
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
|
2009-10-23 07:33:21 +08:00
|
|
|
<< DI->getType();
|
2009-03-18 05:15:40 +08:00
|
|
|
Invalid = true;
|
|
|
|
}
|
2010-05-08 07:12:07 +08:00
|
|
|
} else {
|
|
|
|
SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr *BitWidth = D->getBitWidth();
|
|
|
|
if (Invalid)
|
2014-05-26 14:22:03 +08:00
|
|
|
BitWidth = nullptr;
|
2009-03-18 05:15:40 +08:00
|
|
|
else if (BitWidth) {
|
2011-12-20 10:08:33 +08:00
|
|
|
// The bit-width expression is a constant expression.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef,
|
|
|
|
Sema::ConstantEvaluated);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult InstantiatedBitWidth
|
2009-08-26 06:02:44 +08:00
|
|
|
= SemaRef.SubstExpr(BitWidth, TemplateArgs);
|
2009-03-18 05:15:40 +08:00
|
|
|
if (InstantiatedBitWidth.isInvalid()) {
|
|
|
|
Invalid = true;
|
2014-05-26 14:22:03 +08:00
|
|
|
BitWidth = nullptr;
|
2009-03-18 05:15:40 +08:00
|
|
|
} else
|
2014-05-29 18:55:11 +08:00
|
|
|
BitWidth = InstantiatedBitWidth.getAs<Expr>();
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
2009-10-23 07:33:21 +08:00
|
|
|
FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(),
|
|
|
|
DI->getType(), DI,
|
2009-09-09 23:08:12 +08:00
|
|
|
cast<RecordDecl>(Owner),
|
2009-03-18 05:15:40 +08:00
|
|
|
D->getLocation(),
|
|
|
|
D->isMutable(),
|
|
|
|
BitWidth,
|
2012-06-10 11:12:00 +08:00
|
|
|
D->getInClassInitStyle(),
|
2012-05-23 12:22:22 +08:00
|
|
|
D->getInnerLocStart(),
|
2009-03-18 05:15:40 +08:00
|
|
|
D->getAccess(),
|
2014-05-26 14:22:03 +08:00
|
|
|
nullptr);
|
2009-10-15 04:14:33 +08:00
|
|
|
if (!Field) {
|
|
|
|
cast<Decl>(Owner)->setInvalidDecl();
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-10-15 04:14:33 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-01-21 06:50:54 +08:00
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, D, Field, LateAttrs, StartingScope);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-02-01 16:12:08 +08:00
|
|
|
if (Field->hasAttrs())
|
|
|
|
SemaRef.CheckAlignasUnderalignment(Field);
|
|
|
|
|
2009-09-03 03:17:55 +08:00
|
|
|
if (Invalid)
|
|
|
|
Field->setInvalidDecl();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-03 03:17:55 +08:00
|
|
|
if (!Field->getDeclName()) {
|
|
|
|
// Keep track of where this decl came from.
|
|
|
|
SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D);
|
2011-10-08 19:31:46 +08:00
|
|
|
}
|
2010-05-21 08:31:19 +08:00
|
|
|
if (CXXRecordDecl *Parent= dyn_cast<CXXRecordDecl>(Field->getDeclContext())) {
|
|
|
|
if (Parent->isAnonymousStructOrUnion() &&
|
2010-08-31 08:36:30 +08:00
|
|
|
Parent->getRedeclContext()->isFunctionOrMethod())
|
2010-05-21 08:31:19 +08:00
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Field);
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-03 03:17:55 +08:00
|
|
|
Field->setImplicit(D->isImplicit());
|
2010-01-21 05:53:11 +08:00
|
|
|
Field->setAccess(D->getAccess());
|
2009-09-03 03:17:55 +08:00
|
|
|
Owner->addDecl(Field);
|
2009-03-18 05:15:40 +08:00
|
|
|
|
|
|
|
return Field;
|
|
|
|
}
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) {
|
|
|
|
bool Invalid = false;
|
|
|
|
TypeSourceInfo *DI = D->getTypeSourceInfo();
|
|
|
|
|
|
|
|
if (DI->getType()->isVariablyModifiedType()) {
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified)
|
2014-01-03 09:09:27 +08:00
|
|
|
<< D;
|
2013-04-16 15:28:30 +08:00
|
|
|
Invalid = true;
|
|
|
|
} else if (DI->getType()->isInstantiationDependentType()) {
|
|
|
|
DI = SemaRef.SubstType(DI, TemplateArgs,
|
|
|
|
D->getLocation(), D->getDeclName());
|
|
|
|
if (!DI) {
|
|
|
|
DI = D->getTypeSourceInfo();
|
|
|
|
Invalid = true;
|
|
|
|
} else if (DI->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
|
|
|
|
// declaration that does not use the syntactic form of a
|
|
|
|
// function declarator to have function type, the program is
|
|
|
|
// ill-formed.
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
|
|
|
|
<< DI->getType();
|
|
|
|
Invalid = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
|
|
|
|
}
|
|
|
|
|
2013-11-22 17:01:48 +08:00
|
|
|
MSPropertyDecl *Property = MSPropertyDecl::Create(
|
|
|
|
SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(),
|
|
|
|
DI, D->getLocStart(), D->getGetterId(), D->getSetterId());
|
2013-04-16 15:28:30 +08:00
|
|
|
|
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs,
|
|
|
|
StartingScope);
|
|
|
|
|
|
|
|
if (Invalid)
|
|
|
|
Property->setInvalidDecl();
|
|
|
|
|
|
|
|
Property->setAccess(D->getAccess());
|
|
|
|
Owner->addDecl(Property);
|
|
|
|
|
|
|
|
return Property;
|
|
|
|
}
|
|
|
|
|
2010-11-21 14:08:52 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
|
|
|
|
NamedDecl **NamedChain =
|
|
|
|
new (SemaRef.Context)NamedDecl*[D->getChainingSize()];
|
|
|
|
|
|
|
|
int i = 0;
|
2014-03-08 02:36:15 +08:00
|
|
|
for (auto *PI : D->chain()) {
|
2014-03-08 02:11:58 +08:00
|
|
|
NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), PI,
|
2011-03-05 03:46:35 +08:00
|
|
|
TemplateArgs);
|
|
|
|
if (!Next)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-03-05 03:46:35 +08:00
|
|
|
NamedChain[i++] = Next;
|
|
|
|
}
|
2010-11-21 14:08:52 +08:00
|
|
|
|
2010-12-09 18:07:54 +08:00
|
|
|
QualType T = cast<FieldDecl>(NamedChain[i-1])->getType();
|
2010-11-21 14:08:52 +08:00
|
|
|
IndirectFieldDecl* IndirectField
|
|
|
|
= IndirectFieldDecl::Create(SemaRef.Context, Owner, D->getLocation(),
|
2010-12-09 18:07:54 +08:00
|
|
|
D->getIdentifier(), T,
|
2010-11-21 14:08:52 +08:00
|
|
|
NamedChain, D->getChainingSize());
|
|
|
|
|
|
|
|
|
|
|
|
IndirectField->setImplicit(D->isImplicit());
|
|
|
|
IndirectField->setAccess(D->getAccess());
|
|
|
|
Owner->addDecl(IndirectField);
|
|
|
|
return IndirectField;
|
|
|
|
}
|
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) {
|
|
|
|
// Handle friend type expressions by simply substituting template
|
2010-04-08 01:57:12 +08:00
|
|
|
// parameters into the pattern type and checking the result.
|
2010-03-26 02:04:51 +08:00
|
|
|
if (TypeSourceInfo *Ty = D->getFriendType()) {
|
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
llvm-svn: 130628
2011-05-01 08:51:33 +08:00
|
|
|
TypeSourceInfo *InstTy;
|
|
|
|
// If this is an unsupported friend, don't bother substituting template
|
|
|
|
// arguments into it. The actual type referred to won't be used by any
|
|
|
|
// parts of Clang, and may not be valid for instantiating. Just use the
|
|
|
|
// same info for the instantiated friend.
|
|
|
|
if (D->isUnsupportedFriend()) {
|
|
|
|
InstTy = Ty;
|
|
|
|
} else {
|
|
|
|
InstTy = SemaRef.SubstType(Ty, TemplateArgs,
|
|
|
|
D->getLocation(), DeclarationName());
|
|
|
|
}
|
|
|
|
if (!InstTy)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-08-14 10:03:10 +08:00
|
|
|
|
2012-09-20 09:31:00 +08:00
|
|
|
FriendDecl *FD = SemaRef.CheckFriendTypeDecl(D->getLocStart(),
|
2011-10-30 04:52:52 +08:00
|
|
|
D->getFriendLoc(), InstTy);
|
2010-04-08 01:57:12 +08:00
|
|
|
if (!FD)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2010-04-08 01:57:12 +08:00
|
|
|
FD->setAccess(AS_public);
|
2010-10-19 09:40:49 +08:00
|
|
|
FD->setUnsupportedFriend(D->isUnsupportedFriend());
|
2010-04-08 01:57:12 +08:00
|
|
|
Owner->addDecl(FD);
|
|
|
|
return FD;
|
2011-10-08 19:31:46 +08:00
|
|
|
}
|
|
|
|
|
2010-04-08 01:57:12 +08:00
|
|
|
NamedDecl *ND = D->getFriendDecl();
|
|
|
|
assert(ND && "friend decl must be a decl or a type!");
|
2010-03-26 02:04:51 +08:00
|
|
|
|
2010-04-08 17:05:18 +08:00
|
|
|
// All of the Visit implementations for the various potential friend
|
|
|
|
// declarations have to be carefully written to work for friend
|
|
|
|
// objects, with the most important detail being that the target
|
|
|
|
// decl should almost certainly not be placed in Owner.
|
|
|
|
Decl *NewND = Visit(ND);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!NewND) return nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
FriendDecl *FD =
|
2011-10-08 19:31:46 +08:00
|
|
|
FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(),
|
2010-04-08 01:57:12 +08:00
|
|
|
cast<NamedDecl>(NewND), D->getFriendLoc());
|
2009-08-29 11:50:18 +08:00
|
|
|
FD->setAccess(AS_public);
|
2010-10-19 09:40:49 +08:00
|
|
|
FD->setUnsupportedFriend(D->isUnsupportedFriend());
|
2009-08-28 15:59:38 +08:00
|
|
|
Owner->addDecl(FD);
|
|
|
|
return FD;
|
2009-08-14 10:03:10 +08:00
|
|
|
}
|
|
|
|
|
2009-03-18 05:15:40 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) {
|
|
|
|
Expr *AssertExpr = D->getAssertExpr();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-12-20 10:08:33 +08:00
|
|
|
// The expression in a static assertion is a constant expression.
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef,
|
|
|
|
Sema::ConstantEvaluated);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-24 14:29:42 +08:00
|
|
|
ExprResult InstantiatedAssertExpr
|
2009-08-26 06:02:44 +08:00
|
|
|
= SemaRef.SubstExpr(AssertExpr, TemplateArgs);
|
2009-03-18 05:15:40 +08:00
|
|
|
if (InstantiatedAssertExpr.isInvalid())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-03-18 05:15:40 +08:00
|
|
|
|
2012-07-12 06:37:56 +08:00
|
|
|
return SemaRef.BuildStaticAssertDeclaration(D->getLocation(),
|
2010-08-24 07:25:46 +08:00
|
|
|
InstantiatedAssertExpr.get(),
|
2012-07-12 06:37:56 +08:00
|
|
|
D->getMessage(),
|
|
|
|
D->getRParenLoc(),
|
|
|
|
D->isFailed());
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
|
2014-05-26 14:22:03 +08:00
|
|
|
EnumDecl *PrevDecl = nullptr;
|
2012-03-26 12:58:10 +08:00
|
|
|
if (D->getPreviousDecl()) {
|
|
|
|
NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(),
|
|
|
|
D->getPreviousDecl(),
|
|
|
|
TemplateArgs);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!Prev) return nullptr;
|
2012-03-26 12:58:10 +08:00
|
|
|
PrevDecl = cast<EnumDecl>(Prev);
|
|
|
|
}
|
|
|
|
|
2011-03-09 22:09:51 +08:00
|
|
|
EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, D->getLocStart(),
|
2009-03-18 05:15:40 +08:00
|
|
|
D->getLocation(), D->getIdentifier(),
|
2012-03-26 12:58:10 +08:00
|
|
|
PrevDecl, D->isScoped(),
|
2010-12-04 02:54:17 +08:00
|
|
|
D->isScopedUsingClassTag(), D->isFixed());
|
2010-10-09 07:50:27 +08:00
|
|
|
if (D->isFixed()) {
|
2012-03-15 07:13:10 +08:00
|
|
|
if (TypeSourceInfo *TI = D->getIntegerTypeSourceInfo()) {
|
2010-10-09 07:50:27 +08:00
|
|
|
// If we have type source information for the underlying type, it means it
|
|
|
|
// has been explicitly set by the user. Perform substitution on it before
|
|
|
|
// moving on.
|
|
|
|
SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
|
2012-03-15 07:13:10 +08:00
|
|
|
TypeSourceInfo *NewTI = SemaRef.SubstType(TI, TemplateArgs, UnderlyingLoc,
|
|
|
|
DeclarationName());
|
|
|
|
if (!NewTI || SemaRef.CheckEnumUnderlyingType(NewTI))
|
2010-10-09 07:50:27 +08:00
|
|
|
Enum->setIntegerType(SemaRef.Context.IntTy);
|
2012-03-15 07:13:10 +08:00
|
|
|
else
|
|
|
|
Enum->setIntegerTypeSourceInfo(NewTI);
|
|
|
|
} else {
|
2010-10-09 07:50:27 +08:00
|
|
|
assert(!D->getIntegerType()->isDependentType()
|
|
|
|
&& "Dependent type without type source info");
|
|
|
|
Enum->setIntegerType(D->getIntegerType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 07:36:17 +08:00
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, D, Enum);
|
|
|
|
|
2012-03-15 07:13:10 +08:00
|
|
|
Enum->setInstantiationOfMemberEnum(D, TSK_ImplicitInstantiation);
|
2009-03-26 06:00:53 +08:00
|
|
|
Enum->setAccess(D->getAccess());
|
2013-12-04 17:01:55 +08:00
|
|
|
// Forward the mangling number from the template to the instantiated decl.
|
|
|
|
SemaRef.Context.setManglingNumber(Enum, SemaRef.Context.getManglingNumber(D));
|
2014-05-26 14:22:03 +08:00
|
|
|
if (SubstQualifier(D, Enum)) return nullptr;
|
2009-06-30 10:36:12 +08:00
|
|
|
Owner->addDecl(Enum);
|
2012-03-15 07:13:10 +08:00
|
|
|
|
2012-03-26 12:08:46 +08:00
|
|
|
EnumDecl *Def = D->getDefinition();
|
|
|
|
if (Def && Def != D) {
|
|
|
|
// If this is an out-of-line definition of an enum member template, check
|
|
|
|
// that the underlying types match in the instantiation of both
|
|
|
|
// declarations.
|
|
|
|
if (TypeSourceInfo *TI = Def->getIntegerTypeSourceInfo()) {
|
|
|
|
SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
|
|
|
|
QualType DefnUnderlying =
|
|
|
|
SemaRef.SubstType(TI->getType(), TemplateArgs,
|
|
|
|
UnderlyingLoc, DeclarationName());
|
|
|
|
SemaRef.CheckEnumRedeclaration(Def->getLocation(), Def->isScoped(),
|
|
|
|
DefnUnderlying, Enum);
|
|
|
|
}
|
|
|
|
}
|
2009-03-18 05:15:40 +08:00
|
|
|
|
2012-03-15 07:13:10 +08:00
|
|
|
// C++11 [temp.inst]p1: The implicit instantiation of a class template
|
|
|
|
// specialization causes the implicit instantiation of the declarations, but
|
|
|
|
// not the definitions of scoped member enumerations.
|
2013-11-27 16:20:38 +08:00
|
|
|
//
|
|
|
|
// DR1484 clarifies that enumeration definitions inside of a template
|
|
|
|
// declaration aren't considered entities that can be separately instantiated
|
|
|
|
// from the rest of the entity they are declared inside of.
|
|
|
|
if (isDeclWithinFunction(D) ? D == Def : Def && !Enum->isScoped()) {
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
|
2012-03-26 12:08:46 +08:00
|
|
|
InstantiateEnumDefinition(Enum, Def);
|
2013-11-27 16:20:38 +08:00
|
|
|
}
|
2012-03-15 07:13:10 +08:00
|
|
|
|
|
|
|
return Enum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TemplateDeclInstantiator::InstantiateEnumDefinition(
|
|
|
|
EnumDecl *Enum, EnumDecl *Pattern) {
|
|
|
|
Enum->startDefinition();
|
|
|
|
|
2012-03-23 11:33:32 +08:00
|
|
|
// Update the location to refer to the definition.
|
|
|
|
Enum->setLocation(Pattern->getLocation());
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Decl*, 4> Enumerators;
|
2009-03-18 05:15:40 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
EnumConstantDecl *LastEnumConst = nullptr;
|
2014-03-09 02:45:14 +08:00
|
|
|
for (auto *EC : Pattern->enumerators()) {
|
2009-03-18 05:15:40 +08:00
|
|
|
// The specified value for the enumerator.
|
2014-05-29 22:05:12 +08:00
|
|
|
ExprResult Value((Expr *)nullptr);
|
2009-06-23 04:57:11 +08:00
|
|
|
if (Expr *UninstValue = EC->getInitExpr()) {
|
2011-12-20 10:08:33 +08:00
|
|
|
// The enumerator's value expression is a constant expression.
|
2009-09-09 23:08:12 +08:00
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef,
|
2011-12-20 10:08:33 +08:00
|
|
|
Sema::ConstantEvaluated);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-26 06:02:44 +08:00
|
|
|
Value = SemaRef.SubstExpr(UninstValue, TemplateArgs);
|
2009-06-23 04:57:11 +08:00
|
|
|
}
|
2009-03-18 05:15:40 +08:00
|
|
|
|
|
|
|
// Drop the initial value and continue.
|
|
|
|
bool isInvalid = false;
|
|
|
|
if (Value.isInvalid()) {
|
2014-05-29 22:05:12 +08:00
|
|
|
Value = nullptr;
|
2009-03-18 05:15:40 +08:00
|
|
|
isInvalid = true;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
EnumConstantDecl *EnumConst
|
2009-03-18 05:15:40 +08:00
|
|
|
= SemaRef.CheckEnumConstant(Enum, LastEnumConst,
|
|
|
|
EC->getLocation(), EC->getIdentifier(),
|
2010-08-24 07:25:46 +08:00
|
|
|
Value.get());
|
2009-03-18 05:15:40 +08:00
|
|
|
|
|
|
|
if (isInvalid) {
|
|
|
|
if (EnumConst)
|
|
|
|
EnumConst->setInvalidDecl();
|
|
|
|
Enum->setInvalidDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumConst) {
|
2014-03-09 02:45:14 +08:00
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, EC, EnumConst);
|
2010-10-23 07:36:17 +08:00
|
|
|
|
2010-01-24 06:37:59 +08:00
|
|
|
EnumConst->setAccess(Enum->getAccess());
|
2009-06-30 10:36:12 +08:00
|
|
|
Enum->addDecl(EnumConst);
|
2010-08-21 17:40:31 +08:00
|
|
|
Enumerators.push_back(EnumConst);
|
2009-03-18 05:15:40 +08:00
|
|
|
LastEnumConst = EnumConst;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2012-03-15 07:13:10 +08:00
|
|
|
if (Pattern->getDeclContext()->isFunctionOrMethod() &&
|
|
|
|
!Enum->isScoped()) {
|
2010-03-02 03:00:07 +08:00
|
|
|
// If the enumeration is within a function or method, record the enum
|
|
|
|
// constant as a local.
|
2014-03-09 02:45:14 +08:00
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(EC, EnumConst);
|
2010-03-02 03:00:07 +08:00
|
|
|
}
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-03-15 07:13:10 +08:00
|
|
|
// FIXME: Fixup LBraceLoc
|
|
|
|
SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(),
|
|
|
|
Enum->getRBraceLoc(), Enum,
|
2013-04-28 04:23:52 +08:00
|
|
|
Enumerators,
|
2014-05-26 14:22:03 +08:00
|
|
|
nullptr, nullptr);
|
2009-03-18 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
2009-03-25 23:04:13 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("EnumConstantDecls can only occur within EnumDecls.");
|
2009-03-25 23:04:13 +08:00
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
|
2010-03-25 14:39:04 +08:00
|
|
|
bool isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
|
2009-11-01 01:21:17 +08:00
|
|
|
// Create a local instantiation scope for this class template, which
|
|
|
|
// will contain the instantiations of the template parameters.
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
2009-08-20 09:44:21 +08:00
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameters();
|
2009-08-26 06:02:44 +08:00
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-08-20 09:44:21 +08:00
|
|
|
|
|
|
|
CXXRecordDecl *Pattern = D->getTemplatedDecl();
|
2010-03-25 14:39:04 +08:00
|
|
|
|
|
|
|
// Instantiate the qualifier. We have to do this first in case
|
|
|
|
// we're a friend declaration, because if we are then we need to put
|
|
|
|
// the new declaration in the appropriate context.
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc = Pattern->getQualifierLoc();
|
|
|
|
if (QualifierLoc) {
|
|
|
|
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
|
|
|
|
TemplateArgs);
|
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-25 14:39:04 +08:00
|
|
|
}
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
CXXRecordDecl *PrevDecl = nullptr;
|
|
|
|
ClassTemplateDecl *PrevClassTemplate = nullptr;
|
2010-03-25 14:39:04 +08:00
|
|
|
|
2012-01-15 00:38:05 +08:00
|
|
|
if (!isFriend && Pattern->getPreviousDecl()) {
|
2010-11-09 07:29:42 +08:00
|
|
|
DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
|
2012-12-19 08:45:41 +08:00
|
|
|
if (!Found.empty()) {
|
|
|
|
PrevClassTemplate = dyn_cast<ClassTemplateDecl>(Found.front());
|
2010-11-09 07:29:42 +08:00
|
|
|
if (PrevClassTemplate)
|
|
|
|
PrevDecl = PrevClassTemplate->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-25 14:39:04 +08:00
|
|
|
// If this isn't a friend, then it's a member template, in which
|
|
|
|
// case we just want to build the instantiation in the
|
|
|
|
// specialization. If it is a friend, we want to build it in
|
|
|
|
// the appropriate context.
|
|
|
|
DeclContext *DC = Owner;
|
|
|
|
if (isFriend) {
|
2011-02-25 10:25:35 +08:00
|
|
|
if (QualifierLoc) {
|
2010-03-25 14:39:04 +08:00
|
|
|
CXXScopeSpec SS;
|
2011-02-25 10:25:35 +08:00
|
|
|
SS.Adopt(QualifierLoc);
|
2010-03-25 14:39:04 +08:00
|
|
|
DC = SemaRef.computeDeclContext(SS);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!DC) return nullptr;
|
2010-03-25 14:39:04 +08:00
|
|
|
} else {
|
|
|
|
DC = SemaRef.FindInstantiatedContext(Pattern->getLocation(),
|
|
|
|
Pattern->getDeclContext(),
|
|
|
|
TemplateArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for a previous declaration of the template in the owning
|
|
|
|
// context.
|
|
|
|
LookupResult R(SemaRef, Pattern->getDeclName(), Pattern->getLocation(),
|
|
|
|
Sema::LookupOrdinaryName, Sema::ForRedeclaration);
|
|
|
|
SemaRef.LookupQualifiedName(R, DC);
|
|
|
|
|
|
|
|
if (R.isSingleResult()) {
|
|
|
|
PrevClassTemplate = R.getAsSingle<ClassTemplateDecl>();
|
|
|
|
if (PrevClassTemplate)
|
|
|
|
PrevDecl = PrevClassTemplate->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (!PrevClassTemplate && QualifierLoc) {
|
2010-03-25 14:39:04 +08:00
|
|
|
SemaRef.Diag(Pattern->getLocation(), diag::err_not_tag_in_scope)
|
2010-04-01 07:17:41 +08:00
|
|
|
<< D->getTemplatedDecl()->getTagKind() << Pattern->getDeclName() << DC
|
2011-02-25 10:25:35 +08:00
|
|
|
<< QualifierLoc.getSourceRange();
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-25 14:39:04 +08:00
|
|
|
}
|
|
|
|
|
2010-04-09 02:16:15 +08:00
|
|
|
bool AdoptedPreviousTemplateParams = false;
|
2010-03-25 14:39:04 +08:00
|
|
|
if (PrevClassTemplate) {
|
2010-04-09 02:16:15 +08:00
|
|
|
bool Complain = true;
|
|
|
|
|
|
|
|
// HACK: libstdc++ 4.2.1 contains an ill-formed friend class
|
|
|
|
// template for struct std::tr1::__detail::_Map_base, where the
|
|
|
|
// template parameters of the friend declaration don't match the
|
|
|
|
// template parameters of the original declaration. In this one
|
|
|
|
// case, we don't complain about the ill-formed friend
|
|
|
|
// declaration.
|
2011-10-08 19:31:46 +08:00
|
|
|
if (isFriend && Pattern->getIdentifier() &&
|
2010-04-09 02:16:15 +08:00
|
|
|
Pattern->getIdentifier()->isStr("_Map_base") &&
|
|
|
|
DC->isNamespace() &&
|
|
|
|
cast<NamespaceDecl>(DC)->getIdentifier() &&
|
|
|
|
cast<NamespaceDecl>(DC)->getIdentifier()->isStr("__detail")) {
|
|
|
|
DeclContext *DCParent = DC->getParent();
|
|
|
|
if (DCParent->isNamespace() &&
|
|
|
|
cast<NamespaceDecl>(DCParent)->getIdentifier() &&
|
|
|
|
cast<NamespaceDecl>(DCParent)->getIdentifier()->isStr("tr1")) {
|
2014-05-28 10:16:01 +08:00
|
|
|
if (cast<Decl>(DCParent)->isInStdNamespace())
|
2010-04-09 02:16:15 +08:00
|
|
|
Complain = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-25 14:39:04 +08:00
|
|
|
TemplateParameterList *PrevParams
|
|
|
|
= PrevClassTemplate->getTemplateParameters();
|
|
|
|
|
|
|
|
// Make sure the parameter lists match.
|
|
|
|
if (!SemaRef.TemplateParameterListsAreEqual(InstParams, PrevParams,
|
2011-10-08 19:31:46 +08:00
|
|
|
Complain,
|
2010-04-09 02:16:15 +08:00
|
|
|
Sema::TPL_TemplateMatch)) {
|
|
|
|
if (Complain)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-04-09 02:16:15 +08:00
|
|
|
|
|
|
|
AdoptedPreviousTemplateParams = true;
|
|
|
|
InstParams = PrevParams;
|
|
|
|
}
|
2010-03-25 14:39:04 +08:00
|
|
|
|
|
|
|
// Do some additional validation, then merge default arguments
|
|
|
|
// from the existing declarations.
|
2010-04-09 02:16:15 +08:00
|
|
|
if (!AdoptedPreviousTemplateParams &&
|
|
|
|
SemaRef.CheckTemplateParameterList(InstParams, PrevParams,
|
2010-03-25 14:39:04 +08:00
|
|
|
Sema::TPC_ClassTemplate))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-25 14:39:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
CXXRecordDecl *RecordInst
|
2010-03-25 14:39:04 +08:00
|
|
|
= CXXRecordDecl::Create(SemaRef.Context, Pattern->getTagKind(), DC,
|
2011-03-09 22:09:51 +08:00
|
|
|
Pattern->getLocStart(), Pattern->getLocation(),
|
|
|
|
Pattern->getIdentifier(), PrevDecl,
|
2009-10-13 07:11:44 +08:00
|
|
|
/*DelayTypeCreation=*/true);
|
2009-08-20 09:44:21 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (QualifierLoc)
|
|
|
|
RecordInst->setQualifierInfo(QualifierLoc);
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
ClassTemplateDecl *Inst
|
2010-03-25 14:39:04 +08:00
|
|
|
= ClassTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(),
|
|
|
|
D->getIdentifier(), InstParams, RecordInst,
|
|
|
|
PrevClassTemplate);
|
2009-08-20 09:44:21 +08:00
|
|
|
RecordInst->setDescribedClassTemplate(Inst);
|
2010-04-09 04:25:50 +08:00
|
|
|
|
2010-03-25 14:39:04 +08:00
|
|
|
if (isFriend) {
|
2010-04-09 04:25:50 +08:00
|
|
|
if (PrevClassTemplate)
|
|
|
|
Inst->setAccess(PrevClassTemplate->getAccess());
|
|
|
|
else
|
|
|
|
Inst->setAccess(D->getAccess());
|
|
|
|
|
2013-07-18 07:53:16 +08:00
|
|
|
Inst->setObjectOfFriendDecl();
|
2010-03-25 14:39:04 +08:00
|
|
|
// TODO: do we want to track the instantiation progeny of this
|
|
|
|
// friend target decl?
|
|
|
|
} else {
|
2009-10-31 05:07:27 +08:00
|
|
|
Inst->setAccess(D->getAccess());
|
2010-11-09 07:29:42 +08:00
|
|
|
if (!PrevClassTemplate)
|
|
|
|
Inst->setInstantiatedFromMemberTemplate(D);
|
2010-03-25 14:39:04 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-13 07:11:44 +08:00
|
|
|
// Trigger creation of the type for the instantiation.
|
2010-03-10 11:28:59 +08:00
|
|
|
SemaRef.Context.getInjectedClassNameType(RecordInst,
|
2010-07-09 02:37:38 +08:00
|
|
|
Inst->getInjectedClassNameSpecialization());
|
2010-04-09 04:25:50 +08:00
|
|
|
|
2009-10-31 06:42:42 +08:00
|
|
|
// Finish handling of friends.
|
2010-03-25 14:39:04 +08:00
|
|
|
if (isFriend) {
|
2012-03-13 11:12:56 +08:00
|
|
|
DC->makeDeclVisibleInContext(Inst);
|
2011-11-26 21:33:46 +08:00
|
|
|
Inst->setLexicalDeclContext(Owner);
|
|
|
|
RecordInst->setLexicalDeclContext(Owner);
|
2009-10-31 05:07:27 +08:00
|
|
|
return Inst;
|
2009-10-31 06:42:42 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-11-26 21:33:46 +08:00
|
|
|
if (D->isOutOfLine()) {
|
|
|
|
Inst->setLexicalDeclContext(D->getLexicalDeclContext());
|
|
|
|
RecordInst->setLexicalDeclContext(D->getLexicalDeclContext());
|
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
Owner->addDecl(Inst);
|
2010-11-11 03:44:59 +08:00
|
|
|
|
|
|
|
if (!PrevClassTemplate) {
|
|
|
|
// Queue up any out-of-line partial specializations of this member
|
|
|
|
// class template; the client will force their instantiation once
|
|
|
|
// the enclosing class has been instantiated.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs;
|
2010-11-11 03:44:59 +08:00
|
|
|
D->getPartialSpecializations(PartialSpecs);
|
|
|
|
for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
|
2013-10-17 23:37:26 +08:00
|
|
|
if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
|
2010-11-11 03:44:59 +08:00
|
|
|
OutOfLinePartialSpecs.push_back(std::make_pair(Inst, PartialSpecs[I]));
|
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
2009-10-08 01:21:34 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
2009-10-29 08:04:11 +08:00
|
|
|
ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Lookup the already-instantiated declaration in the instantiation
|
|
|
|
// of the class template and return that.
|
|
|
|
DeclContext::lookup_result Found
|
|
|
|
= Owner->lookup(ClassTemplate->getDeclName());
|
2012-12-19 08:45:41 +08:00
|
|
|
if (Found.empty())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
ClassTemplateDecl *InstClassTemplate
|
2012-12-19 08:45:41 +08:00
|
|
|
= dyn_cast<ClassTemplateDecl>(Found.front());
|
2009-10-29 08:04:11 +08:00
|
|
|
if (!InstClassTemplate)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2010-11-11 03:44:59 +08:00
|
|
|
if (ClassTemplatePartialSpecializationDecl *Result
|
|
|
|
= InstClassTemplate->findPartialSpecInstantiatedFromMember(D))
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
return InstantiateClassTemplatePartialSpecialization(InstClassTemplate, D);
|
2009-10-08 01:21:34 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) {
|
|
|
|
assert(D->getTemplatedDecl()->isStaticDataMember() &&
|
|
|
|
"Only static data member templates are allowed.");
|
|
|
|
|
|
|
|
// Create a local instantiation scope for this variable template, which
|
|
|
|
// will contain the instantiations of the template parameters.
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
VarDecl *Pattern = D->getTemplatedDecl();
|
2014-05-26 14:22:03 +08:00
|
|
|
VarTemplateDecl *PrevVarTemplate = nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
if (Pattern->getPreviousDecl()) {
|
|
|
|
DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
|
|
|
|
if (!Found.empty())
|
|
|
|
PrevVarTemplate = dyn_cast<VarTemplateDecl>(Found.front());
|
|
|
|
}
|
|
|
|
|
2013-08-14 02:18:50 +08:00
|
|
|
VarDecl *VarInst =
|
2013-08-22 08:59:14 +08:00
|
|
|
cast_or_null<VarDecl>(VisitVarDecl(Pattern,
|
|
|
|
/*InstantiatingVarTemplate=*/true));
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
DeclContext *DC = Owner;
|
|
|
|
|
|
|
|
VarTemplateDecl *Inst = VarTemplateDecl::Create(
|
|
|
|
SemaRef.Context, DC, D->getLocation(), D->getIdentifier(), InstParams,
|
2014-01-17 07:39:20 +08:00
|
|
|
VarInst);
|
2013-08-06 09:03:05 +08:00
|
|
|
VarInst->setDescribedVarTemplate(Inst);
|
2014-01-17 07:39:20 +08:00
|
|
|
Inst->setPreviousDecl(PrevVarTemplate);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
Inst->setAccess(D->getAccess());
|
|
|
|
if (!PrevVarTemplate)
|
|
|
|
Inst->setInstantiatedFromMemberTemplate(D);
|
|
|
|
|
|
|
|
if (D->isOutOfLine()) {
|
|
|
|
Inst->setLexicalDeclContext(D->getLexicalDeclContext());
|
|
|
|
VarInst->setLexicalDeclContext(D->getLexicalDeclContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
Owner->addDecl(Inst);
|
|
|
|
|
|
|
|
if (!PrevVarTemplate) {
|
|
|
|
// Queue up any out-of-line partial specializations of this member
|
|
|
|
// variable template; the client will force their instantiation once
|
|
|
|
// the enclosing class has been instantiated.
|
|
|
|
SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs;
|
|
|
|
D->getPartialSpecializations(PartialSpecs);
|
|
|
|
for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
|
2013-10-17 23:37:26 +08:00
|
|
|
if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
|
2013-08-06 09:03:05 +08:00
|
|
|
OutOfLineVarPartialSpecs.push_back(
|
|
|
|
std::make_pair(Inst, PartialSpecs[I]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitVarTemplatePartialSpecializationDecl(
|
|
|
|
VarTemplatePartialSpecializationDecl *D) {
|
|
|
|
assert(D->isStaticDataMember() &&
|
|
|
|
"Only static data member templates are allowed.");
|
|
|
|
|
|
|
|
VarTemplateDecl *VarTemplate = D->getSpecializedTemplate();
|
|
|
|
|
|
|
|
// Lookup the already-instantiated declaration and return that.
|
|
|
|
DeclContext::lookup_result Found = Owner->lookup(VarTemplate->getDeclName());
|
|
|
|
assert(!Found.empty() && "Instantiation found nothing?");
|
|
|
|
|
|
|
|
VarTemplateDecl *InstVarTemplate = dyn_cast<VarTemplateDecl>(Found.front());
|
|
|
|
assert(InstVarTemplate && "Instantiation did not find a variable template?");
|
|
|
|
|
|
|
|
if (VarTemplatePartialSpecializationDecl *Result =
|
|
|
|
InstVarTemplate->findPartialSpecInstantiatedFromMember(D))
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
return InstantiateVarTemplatePartialSpecialization(InstVarTemplate, D);
|
|
|
|
}
|
|
|
|
|
2009-08-28 00:57:43 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
|
2009-11-01 01:21:17 +08:00
|
|
|
// Create a local instantiation scope for this function template, which
|
|
|
|
// will contain the instantiations of the template parameters and then get
|
2011-10-08 19:31:46 +08:00
|
|
|
// merged with the local instantiation scope for the function template
|
2009-11-01 01:21:17 +08:00
|
|
|
// itself.
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
2010-05-01 02:55:50 +08:00
|
|
|
|
2009-08-28 00:57:43 +08:00
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
FunctionDecl *Instantiated = nullptr;
|
2009-10-13 22:39:41 +08:00
|
|
|
if (CXXMethodDecl *DMethod = dyn_cast<CXXMethodDecl>(D->getTemplatedDecl()))
|
2011-10-08 19:31:46 +08:00
|
|
|
Instantiated = cast_or_null<FunctionDecl>(VisitCXXMethodDecl(DMethod,
|
2009-10-13 22:39:41 +08:00
|
|
|
InstParams));
|
|
|
|
else
|
|
|
|
Instantiated = cast_or_null<FunctionDecl>(VisitFunctionDecl(
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getTemplatedDecl(),
|
2009-10-13 22:39:41 +08:00
|
|
|
InstParams));
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-13 22:39:41 +08:00
|
|
|
if (!Instantiated)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-08-28 00:57:43 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// Link the instantiated function template declaration to the function
|
2009-08-28 00:57:43 +08:00
|
|
|
// template from which it was instantiated.
|
2011-10-08 19:31:46 +08:00
|
|
|
FunctionTemplateDecl *InstTemplate
|
2009-10-13 22:39:41 +08:00
|
|
|
= Instantiated->getDescribedFunctionTemplate();
|
2009-10-13 06:27:17 +08:00
|
|
|
InstTemplate->setAccess(D->getAccess());
|
2011-10-08 19:31:46 +08:00
|
|
|
assert(InstTemplate &&
|
2009-10-13 22:39:41 +08:00
|
|
|
"VisitFunctionDecl/CXXMethodDecl didn't create a template!");
|
2009-12-15 07:19:40 +08:00
|
|
|
|
2010-03-27 07:10:15 +08:00
|
|
|
bool isFriend = (InstTemplate->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
|
2009-12-15 07:19:40 +08:00
|
|
|
// Link the instantiation back to the pattern *unless* this is a
|
|
|
|
// non-definition friend declaration.
|
|
|
|
if (!InstTemplate->getInstantiatedFromMemberTemplate() &&
|
2010-03-27 07:10:15 +08:00
|
|
|
!(isFriend && !D->getTemplatedDecl()->isThisDeclarationADefinition()))
|
2009-10-13 22:39:41 +08:00
|
|
|
InstTemplate->setInstantiatedFromMemberTemplate(D);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2010-03-27 07:10:15 +08:00
|
|
|
// Make declarations visible in the appropriate context.
|
2012-08-10 11:15:35 +08:00
|
|
|
if (!isFriend) {
|
2009-10-13 22:39:41 +08:00
|
|
|
Owner->addDecl(InstTemplate);
|
2012-08-10 11:15:35 +08:00
|
|
|
} else if (InstTemplate->getDeclContext()->isRecord() &&
|
|
|
|
!D->getPreviousDecl()) {
|
|
|
|
SemaRef.CheckFriendAccess(InstTemplate);
|
|
|
|
}
|
2010-03-27 07:10:15 +08:00
|
|
|
|
2009-08-28 00:57:43 +08:00
|
|
|
return InstTemplate;
|
|
|
|
}
|
|
|
|
|
2009-03-26 05:17:03 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
|
2014-05-26 14:22:03 +08:00
|
|
|
CXXRecordDecl *PrevDecl = nullptr;
|
2009-03-26 05:17:03 +08:00
|
|
|
if (D->isInjectedClassName())
|
|
|
|
PrevDecl = cast<CXXRecordDecl>(Owner);
|
2012-01-15 00:38:05 +08:00
|
|
|
else if (D->getPreviousDecl()) {
|
2010-03-01 23:56:25 +08:00
|
|
|
NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(),
|
2012-01-15 00:38:05 +08:00
|
|
|
D->getPreviousDecl(),
|
2009-12-16 06:29:06 +08:00
|
|
|
TemplateArgs);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!Prev) return nullptr;
|
2009-12-16 06:29:06 +08:00
|
|
|
PrevDecl = cast<CXXRecordDecl>(Prev);
|
|
|
|
}
|
2009-03-26 05:17:03 +08:00
|
|
|
|
|
|
|
CXXRecordDecl *Record
|
2009-09-09 23:08:12 +08:00
|
|
|
= CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner,
|
2011-03-09 22:09:51 +08:00
|
|
|
D->getLocStart(), D->getLocation(),
|
|
|
|
D->getIdentifier(), PrevDecl);
|
2010-03-15 18:12:16 +08:00
|
|
|
|
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(D, Record))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2009-03-26 05:17:03 +08:00
|
|
|
Record->setImplicit(D->isImplicit());
|
2009-08-28 03:11:42 +08:00
|
|
|
// FIXME: Check against AS_none is an ugly hack to work around the issue that
|
|
|
|
// the tag decls introduced by friend class declarations don't have an access
|
|
|
|
// specifier. Remove once this area of the code gets sorted out.
|
|
|
|
if (D->getAccess() != AS_none)
|
|
|
|
Record->setAccess(D->getAccess());
|
2009-03-26 05:17:03 +08:00
|
|
|
if (!D->isInjectedClassName())
|
2009-10-08 23:14:33 +08:00
|
|
|
Record->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation);
|
2009-03-26 05:17:03 +08:00
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
// If the original function was part of a friend declaration,
|
|
|
|
// inherit its namespace state.
|
2013-07-18 07:53:16 +08:00
|
|
|
if (D->getFriendObjectKind())
|
|
|
|
Record->setObjectOfFriendDecl();
|
2009-08-28 15:59:38 +08:00
|
|
|
|
2010-05-21 08:31:19 +08:00
|
|
|
// Make sure that anonymous structs and unions are recorded.
|
2013-11-27 16:20:38 +08:00
|
|
|
if (D->isAnonymousStructOrUnion())
|
2010-05-21 08:31:19 +08:00
|
|
|
Record->setAnonymousStructOrUnion(true);
|
2013-11-27 16:20:38 +08:00
|
|
|
|
|
|
|
if (D->isLocalClass())
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record);
|
2009-09-01 12:26:58 +08:00
|
|
|
|
2013-12-04 17:01:55 +08:00
|
|
|
// Forward the mangling number from the template to the instantiated decl.
|
|
|
|
SemaRef.Context.setManglingNumber(Record,
|
|
|
|
SemaRef.Context.getManglingNumber(D));
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
Owner->addDecl(Record);
|
2013-11-27 16:20:38 +08:00
|
|
|
|
|
|
|
// DR1484 clarifies that the members of a local class are instantiated as part
|
|
|
|
// of the instantiation of their enclosing entity.
|
|
|
|
if (D->isCompleteDefinition() && D->isLocalClass()) {
|
2014-02-22 08:17:46 +08:00
|
|
|
SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs,
|
|
|
|
TSK_ImplicitInstantiation,
|
|
|
|
/*Complain=*/true);
|
|
|
|
SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs,
|
|
|
|
TSK_ImplicitInstantiation);
|
2013-11-27 16:20:38 +08:00
|
|
|
}
|
2009-03-26 05:17:03 +08:00
|
|
|
return Record;
|
|
|
|
}
|
|
|
|
|
2012-09-14 05:56:43 +08:00
|
|
|
/// \brief Adjust the given function type for an instantiation of the
|
|
|
|
/// given declaration, to cope with modifications to the function's type that
|
|
|
|
/// aren't reflected in the type-source information.
|
|
|
|
///
|
|
|
|
/// \param D The declaration we're instantiating.
|
|
|
|
/// \param TInfo The already-instantiated type.
|
|
|
|
static QualType adjustFunctionTypeForInstantiation(ASTContext &Context,
|
|
|
|
FunctionDecl *D,
|
|
|
|
TypeSourceInfo *TInfo) {
|
2012-09-14 06:01:49 +08:00
|
|
|
const FunctionProtoType *OrigFunc
|
|
|
|
= D->getType()->castAs<FunctionProtoType>();
|
|
|
|
const FunctionProtoType *NewFunc
|
|
|
|
= TInfo->getType()->castAs<FunctionProtoType>();
|
|
|
|
if (OrigFunc->getExtInfo() == NewFunc->getExtInfo())
|
|
|
|
return TInfo->getType();
|
|
|
|
|
|
|
|
FunctionProtoType::ExtProtoInfo NewEPI = NewFunc->getExtProtoInfo();
|
|
|
|
NewEPI.ExtInfo = OrigFunc->getExtInfo();
|
2014-01-26 00:55:45 +08:00
|
|
|
return Context.getFunctionType(NewFunc->getReturnType(),
|
2014-01-21 04:26:09 +08:00
|
|
|
NewFunc->getParamTypes(), NewEPI);
|
2012-09-14 05:56:43 +08:00
|
|
|
}
|
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
/// Normal class members are of more specific types and therefore
|
|
|
|
/// don't make it here. This function serves two purposes:
|
|
|
|
/// 1) instantiating function templates
|
|
|
|
/// 2) substituting friend declarations
|
2009-12-25 04:56:24 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
|
2009-10-13 22:39:41 +08:00
|
|
|
TemplateParameterList *TemplateParams) {
|
2009-06-30 04:59:39 +08:00
|
|
|
// Check whether there is already a function template specialization for
|
|
|
|
// this declaration.
|
|
|
|
FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate();
|
2010-03-27 13:57:59 +08:00
|
|
|
if (FunctionTemplate && !TemplateParams) {
|
2013-05-04 07:46:09 +08:00
|
|
|
ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2010-07-20 21:59:58 +08:00
|
|
|
FunctionDecl *SpecFunc
|
2014-06-26 12:58:53 +08:00
|
|
|
= FunctionTemplate->findSpecialization(Innermost, InsertPos);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-30 04:59:39 +08:00
|
|
|
// If we already have a function template specialization, return it.
|
2010-07-20 21:59:58 +08:00
|
|
|
if (SpecFunc)
|
|
|
|
return SpecFunc;
|
2009-06-30 04:59:39 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-03-27 13:57:59 +08:00
|
|
|
bool isFriend;
|
|
|
|
if (FunctionTemplate)
|
|
|
|
isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
else
|
|
|
|
isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
bool MergeWithParentScope = (TemplateParams != nullptr) ||
|
2010-05-22 05:25:08 +08:00
|
|
|
Owner->isFunctionOrMethod() ||
|
2011-10-08 19:31:46 +08:00
|
|
|
!(isa<Decl>(Owner) &&
|
2010-01-17 04:21:20 +08:00
|
|
|
cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ParmVarDecl *, 4> Params;
|
2011-11-10 13:42:04 +08:00
|
|
|
TypeSourceInfo *TInfo = SubstFunctionType(D, Params);
|
2010-03-11 17:03:00 +08:00
|
|
|
if (!TInfo)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-14 05:56:43 +08:00
|
|
|
QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
|
2009-08-14 10:03:10 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
|
|
|
|
if (QualifierLoc) {
|
|
|
|
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
|
|
|
|
TemplateArgs);
|
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-26 12:53:08 +08:00
|
|
|
}
|
|
|
|
|
2010-02-06 09:50:47 +08:00
|
|
|
// If we're instantiating a local function declaration, put the result
|
2013-09-20 09:15:31 +08:00
|
|
|
// in the enclosing namespace; otherwise we need to find the instantiated
|
|
|
|
// context.
|
2010-02-06 09:50:47 +08:00
|
|
|
DeclContext *DC;
|
2013-09-20 09:15:31 +08:00
|
|
|
if (D->isLocalExternDecl()) {
|
2010-02-06 09:50:47 +08:00
|
|
|
DC = Owner;
|
2013-09-20 09:15:31 +08:00
|
|
|
SemaRef.adjustContextForLocalExternDecl(DC);
|
|
|
|
} else if (isFriend && QualifierLoc) {
|
2010-03-26 12:53:08 +08:00
|
|
|
CXXScopeSpec SS;
|
2011-02-25 10:25:35 +08:00
|
|
|
SS.Adopt(QualifierLoc);
|
2010-03-26 12:53:08 +08:00
|
|
|
DC = SemaRef.computeDeclContext(SS);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!DC) return nullptr;
|
2010-03-26 12:53:08 +08:00
|
|
|
} else {
|
2011-10-08 19:31:46 +08:00
|
|
|
DC = SemaRef.FindInstantiatedContext(D->getLocation(), D->getDeclContext(),
|
2010-03-01 23:56:25 +08:00
|
|
|
TemplateArgs);
|
2010-03-26 12:53:08 +08:00
|
|
|
}
|
2010-02-06 09:50:47 +08:00
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
FunctionDecl *Function =
|
2011-03-08 16:55:46 +08:00
|
|
|
FunctionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
|
2012-10-05 05:40:42 +08:00
|
|
|
D->getNameInfo(), T, TInfo,
|
2013-04-16 10:29:15 +08:00
|
|
|
D->getCanonicalDecl()->getStorageClass(),
|
2011-08-16 05:04:07 +08:00
|
|
|
D->isInlineSpecified(), D->hasWrittenPrototype(),
|
2012-02-13 11:54:03 +08:00
|
|
|
D->isConstexpr());
|
2013-07-20 02:02:36 +08:00
|
|
|
Function->setRangeEnd(D->getSourceRange().getEnd());
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2013-01-25 08:08:28 +08:00
|
|
|
if (D->isInlined())
|
|
|
|
Function->setImplicitlyInline();
|
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (QualifierLoc)
|
|
|
|
Function->setQualifierInfo(QualifierLoc);
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
if (D->isLocalExternDecl())
|
|
|
|
Function->setLocalExternDecl();
|
|
|
|
|
2010-03-27 07:10:15 +08:00
|
|
|
DeclContext *LexicalDC = Owner;
|
2013-09-20 09:15:31 +08:00
|
|
|
if (!isFriend && D->isOutOfLine() && !D->isLocalExternDecl()) {
|
2010-03-27 07:10:15 +08:00
|
|
|
assert(D->getDeclContext()->isFileContext());
|
|
|
|
LexicalDC = D->getDeclContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
Function->setLexicalDeclContext(LexicalDC);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-26 06:08:12 +08:00
|
|
|
// Attach the parameters
|
2013-08-01 05:00:18 +08:00
|
|
|
for (unsigned P = 0; P < Params.size(); ++P)
|
|
|
|
if (Params[P])
|
|
|
|
Params[P]->setOwningFunction(Function);
|
2011-09-22 02:16:56 +08:00
|
|
|
Function->setParams(Params);
|
2009-08-28 15:59:38 +08:00
|
|
|
|
2010-05-18 00:38:00 +08:00
|
|
|
SourceLocation InstantiateAtPOI;
|
2009-10-13 22:39:41 +08:00
|
|
|
if (TemplateParams) {
|
|
|
|
// Our resulting instantiation is actually a function template, since we
|
|
|
|
// are substituting only the outer template parameters. For example, given
|
|
|
|
//
|
|
|
|
// template<typename T>
|
|
|
|
// struct X {
|
|
|
|
// template<typename U> friend void f(T, U);
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// X<int> x;
|
|
|
|
//
|
2011-10-08 19:31:46 +08:00
|
|
|
// We are instantiating the friend function template "f" within X<int>,
|
2009-10-13 22:39:41 +08:00
|
|
|
// which means substituting int for T, but leaving "f" as a friend function
|
|
|
|
// template.
|
|
|
|
// Build the function template itself.
|
2010-03-26 12:53:08 +08:00
|
|
|
FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, DC,
|
2009-10-13 22:39:41 +08:00
|
|
|
Function->getLocation(),
|
|
|
|
Function->getDeclName(),
|
|
|
|
TemplateParams, Function);
|
|
|
|
Function->setDescribedFunctionTemplate(FunctionTemplate);
|
2010-03-27 07:10:15 +08:00
|
|
|
|
|
|
|
FunctionTemplate->setLexicalDeclContext(LexicalDC);
|
2010-03-26 12:53:08 +08:00
|
|
|
|
|
|
|
if (isFriend && D->isThisDeclarationADefinition()) {
|
|
|
|
// TODO: should we remember this connection regardless of whether
|
|
|
|
// the friend declaration provided a body?
|
|
|
|
FunctionTemplate->setInstantiatedFromMemberTemplate(
|
|
|
|
D->getDescribedFunctionTemplate());
|
|
|
|
}
|
2009-11-14 09:20:54 +08:00
|
|
|
} else if (FunctionTemplate) {
|
|
|
|
// Record this function template specialization.
|
2013-05-04 07:46:09 +08:00
|
|
|
ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
|
2010-02-11 09:19:42 +08:00
|
|
|
Function->setFunctionTemplateSpecialization(FunctionTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
TemplateArgumentList::CreateCopy(SemaRef.Context,
|
2013-05-04 07:46:09 +08:00
|
|
|
Innermost.begin(),
|
|
|
|
Innermost.size()),
|
2014-05-26 14:22:03 +08:00
|
|
|
/*InsertPos=*/nullptr);
|
2011-08-18 17:09:59 +08:00
|
|
|
} else if (isFriend) {
|
|
|
|
// Note, we need this connection even if the friend doesn't have a body.
|
|
|
|
// Its body may exist but not have been attached yet due to deferred
|
|
|
|
// parsing.
|
|
|
|
// FIXME: It might be cleaner to set this when attaching the body to the
|
|
|
|
// friend function declaration, however that would require finding all the
|
|
|
|
// instantiations and modifying them.
|
2010-03-26 12:53:08 +08:00
|
|
|
Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
|
2009-08-28 15:59:38 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-06-26 06:08:12 +08:00
|
|
|
if (InitFunctionInstantiation(Function, D))
|
|
|
|
Function->setInvalidDecl();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-04-08 17:05:18 +08:00
|
|
|
bool isExplicitSpecialization = false;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
LookupResult Previous(
|
|
|
|
SemaRef, Function->getDeclName(), SourceLocation(),
|
|
|
|
D->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage
|
|
|
|
: Sema::LookupOrdinaryName,
|
|
|
|
Sema::ForRedeclaration);
|
2009-11-19 06:49:29 +08:00
|
|
|
|
2010-04-08 17:05:18 +08:00
|
|
|
if (DependentFunctionTemplateSpecializationInfo *Info
|
|
|
|
= D->getDependentSpecializationInfo()) {
|
|
|
|
assert(isFriend && "non-friend has dependent specialization info?");
|
|
|
|
|
|
|
|
// This needs to be set now for future sanity.
|
2013-07-18 07:53:16 +08:00
|
|
|
Function->setObjectOfFriendDecl();
|
2010-04-08 17:05:18 +08:00
|
|
|
|
|
|
|
// Instantiate the explicit template arguments.
|
|
|
|
TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(),
|
|
|
|
Info->getRAngleLoc());
|
2010-12-23 05:19:48 +08:00
|
|
|
if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(),
|
|
|
|
ExplicitArgs, TemplateArgs))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-04-08 17:05:18 +08:00
|
|
|
|
|
|
|
// Map the candidate templates to their instantiations.
|
|
|
|
for (unsigned I = 0, E = Info->getNumTemplates(); I != E; ++I) {
|
|
|
|
Decl *Temp = SemaRef.FindInstantiatedDecl(D->getLocation(),
|
|
|
|
Info->getTemplate(I),
|
|
|
|
TemplateArgs);
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!Temp) return nullptr;
|
2010-04-08 17:05:18 +08:00
|
|
|
|
|
|
|
Previous.addDecl(cast<FunctionTemplateDecl>(Temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SemaRef.CheckFunctionTemplateSpecialization(Function,
|
|
|
|
&ExplicitArgs,
|
|
|
|
Previous))
|
|
|
|
Function->setInvalidDecl();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2010-04-08 17:05:18 +08:00
|
|
|
isExplicitSpecialization = true;
|
|
|
|
|
|
|
|
} else if (TemplateParams || !FunctionTemplate) {
|
2011-10-08 19:31:46 +08:00
|
|
|
// Look only into the namespace where the friend would be declared to
|
|
|
|
// find a previous declaration. This is the innermost enclosing namespace,
|
2009-10-13 22:39:41 +08:00
|
|
|
// as described in ActOnFriendFunctionDecl.
|
2009-11-19 06:49:29 +08:00
|
|
|
SemaRef.LookupQualifiedName(Previous, DC);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-13 22:39:41 +08:00
|
|
|
// In C++, the previous declaration we find might be a tag type
|
|
|
|
// (class or enum). In this case, the new declaration will hide the
|
|
|
|
// tag type. Note that this does does not apply if we're declaring a
|
|
|
|
// typedef (C++ [dcl.typedef]p4).
|
2009-11-19 06:49:29 +08:00
|
|
|
if (Previous.isSingleTagDecl())
|
|
|
|
Previous.clear();
|
2009-10-13 22:39:41 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,
|
2011-10-11 08:28:45 +08:00
|
|
|
isExplicitSpecialization);
|
2009-06-26 06:08:12 +08:00
|
|
|
|
2010-04-24 09:30:58 +08:00
|
|
|
NamedDecl *PrincipalDecl = (TemplateParams
|
|
|
|
? cast<NamedDecl>(FunctionTemplate)
|
|
|
|
: Function);
|
|
|
|
|
2009-10-13 22:39:41 +08:00
|
|
|
// If the original function was part of a friend declaration,
|
|
|
|
// inherit its namespace state and add it to the owner.
|
2010-03-26 12:53:08 +08:00
|
|
|
if (isFriend) {
|
2013-07-18 07:53:16 +08:00
|
|
|
PrincipalDecl->setObjectOfFriendDecl();
|
2012-03-13 11:12:56 +08:00
|
|
|
DC->makeDeclVisibleInContext(PrincipalDecl);
|
2010-08-31 05:10:05 +08:00
|
|
|
|
2014-02-03 10:37:59 +08:00
|
|
|
bool QueuedInstantiation = false;
|
2010-08-31 05:10:05 +08:00
|
|
|
|
2014-02-03 10:37:59 +08:00
|
|
|
// C++11 [temp.friend]p4 (DR329):
|
|
|
|
// When a function is defined in a friend function declaration in a class
|
|
|
|
// template, the function is instantiated when the function is odr-used.
|
|
|
|
// The same restrictions on multiple declarations and definitions that
|
|
|
|
// apply to non-template function declarations and definitions also apply
|
|
|
|
// to these implicit definitions.
|
|
|
|
if (D->isThisDeclarationADefinition()) {
|
2010-05-18 13:45:02 +08:00
|
|
|
// Check for a function body.
|
2014-05-26 14:22:03 +08:00
|
|
|
const FunctionDecl *Definition = nullptr;
|
2011-05-07 04:44:56 +08:00
|
|
|
if (Function->isDefined(Definition) &&
|
2010-05-18 13:45:02 +08:00
|
|
|
Definition->getTemplateSpecializationKind() == TSK_Undeclared) {
|
2014-02-03 10:37:59 +08:00
|
|
|
SemaRef.Diag(Function->getLocation(), diag::err_redefinition)
|
|
|
|
<< Function->getDeclName();
|
2010-05-18 13:45:02 +08:00
|
|
|
SemaRef.Diag(Definition->getLocation(), diag::note_previous_definition);
|
2011-10-08 19:31:46 +08:00
|
|
|
}
|
2010-05-18 13:45:02 +08:00
|
|
|
// Check for redefinitions due to other instantiations of this or
|
|
|
|
// a similar friend function.
|
2014-03-07 07:45:36 +08:00
|
|
|
else for (auto R : Function->redecls()) {
|
|
|
|
if (R == Function)
|
2010-08-28 23:42:30 +08:00
|
|
|
continue;
|
2014-02-03 10:37:59 +08:00
|
|
|
|
|
|
|
// If some prior declaration of this function has been used, we need
|
|
|
|
// to instantiate its definition.
|
|
|
|
if (!QueuedInstantiation && R->isUsed(false)) {
|
|
|
|
if (MemberSpecializationInfo *MSInfo =
|
|
|
|
Function->getMemberSpecializationInfo()) {
|
|
|
|
if (MSInfo->getPointOfInstantiation().isInvalid()) {
|
|
|
|
SourceLocation Loc = R->getLocation(); // FIXME
|
|
|
|
MSInfo->setPointOfInstantiation(Loc);
|
|
|
|
SemaRef.PendingLocalImplicitInstantiations.push_back(
|
|
|
|
std::make_pair(Function, Loc));
|
|
|
|
QueuedInstantiation = true;
|
2010-08-31 05:10:05 +08:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 10:37:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If some prior declaration of this function was a friend with an
|
|
|
|
// uninstantiated definition, reject it.
|
|
|
|
if (R->getFriendObjectKind()) {
|
|
|
|
if (const FunctionDecl *RPattern =
|
|
|
|
R->getTemplateInstantiationPattern()) {
|
2011-05-07 04:44:56 +08:00
|
|
|
if (RPattern->isDefined(RPattern)) {
|
2014-02-03 10:37:59 +08:00
|
|
|
SemaRef.Diag(Function->getLocation(), diag::err_redefinition)
|
2010-05-18 13:45:02 +08:00
|
|
|
<< Function->getDeclName();
|
2010-08-28 23:46:56 +08:00
|
|
|
SemaRef.Diag(R->getLocation(), diag::note_previous_definition);
|
2010-05-18 13:45:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-02-03 10:37:59 +08:00
|
|
|
}
|
2010-05-18 13:45:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-13 22:39:41 +08:00
|
|
|
}
|
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
if (Function->isLocalExternDecl() && !Function->getPreviousDecl())
|
|
|
|
DC->makeDeclVisibleInContext(PrincipalDecl);
|
|
|
|
|
2010-04-24 09:30:58 +08:00
|
|
|
if (Function->isOverloadedOperator() && !DC->isRecord() &&
|
|
|
|
PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
|
|
|
|
PrincipalDecl->setNonMemberOperator();
|
|
|
|
|
2011-05-24 05:07:59 +08:00
|
|
|
assert(!D->isDefaulted() && "only methods should be defaulted");
|
2009-06-26 06:08:12 +08:00
|
|
|
return Function;
|
|
|
|
}
|
2009-03-24 07:06:20 +08:00
|
|
|
|
2009-08-28 00:57:43 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
|
2011-08-14 11:52:19 +08:00
|
|
|
TemplateParameterList *TemplateParams,
|
|
|
|
bool IsClassScopeSpecialization) {
|
2009-08-21 08:16:32 +08:00
|
|
|
FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate();
|
2009-08-28 00:57:43 +08:00
|
|
|
if (FunctionTemplate && !TemplateParams) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// We are creating a function template specialization from a function
|
|
|
|
// template. Check whether there is already a function template
|
2009-08-28 00:57:43 +08:00
|
|
|
// specialization for this particular set of template arguments.
|
2013-05-04 07:46:09 +08:00
|
|
|
ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2010-07-20 21:59:58 +08:00
|
|
|
FunctionDecl *SpecFunc
|
2014-06-26 12:58:53 +08:00
|
|
|
= FunctionTemplate->findSpecialization(Innermost, InsertPos);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-21 08:16:32 +08:00
|
|
|
// If we already have a function template specialization, return it.
|
2010-07-20 21:59:58 +08:00
|
|
|
if (SpecFunc)
|
|
|
|
return SpecFunc;
|
2009-08-21 08:16:32 +08:00
|
|
|
}
|
|
|
|
|
2010-03-27 13:57:59 +08:00
|
|
|
bool isFriend;
|
|
|
|
if (FunctionTemplate)
|
|
|
|
isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
else
|
|
|
|
isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
bool MergeWithParentScope = (TemplateParams != nullptr) ||
|
2011-10-08 19:31:46 +08:00
|
|
|
!(isa<Decl>(Owner) &&
|
2010-01-17 04:21:20 +08:00
|
|
|
cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
|
2009-05-15 05:44:34 +08:00
|
|
|
|
2010-10-19 10:26:41 +08:00
|
|
|
// Instantiate enclosing template arguments for friends.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateParameterList *, 4> TempParamLists;
|
2010-10-19 10:26:41 +08:00
|
|
|
unsigned NumTempParamLists = 0;
|
|
|
|
if (isFriend && (NumTempParamLists = D->getNumTemplateParameterLists())) {
|
|
|
|
TempParamLists.set_size(NumTempParamLists);
|
|
|
|
for (unsigned I = 0; I != NumTempParamLists; ++I) {
|
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameterList(I);
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-10-19 10:26:41 +08:00
|
|
|
TempParamLists[I] = InstParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ParmVarDecl *, 4> Params;
|
2012-01-20 22:42:32 +08:00
|
|
|
TypeSourceInfo *TInfo = SubstFunctionType(D, Params);
|
2010-03-11 17:03:00 +08:00
|
|
|
if (!TInfo)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-14 05:56:43 +08:00
|
|
|
QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
|
2009-03-24 07:06:20 +08:00
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
|
|
|
|
if (QualifierLoc) {
|
|
|
|
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
|
2010-03-27 13:57:59 +08:00
|
|
|
TemplateArgs);
|
2011-10-08 19:31:46 +08:00
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-27 13:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DeclContext *DC = Owner;
|
|
|
|
if (isFriend) {
|
2011-02-25 10:25:35 +08:00
|
|
|
if (QualifierLoc) {
|
2010-03-27 13:57:59 +08:00
|
|
|
CXXScopeSpec SS;
|
2011-02-25 10:25:35 +08:00
|
|
|
SS.Adopt(QualifierLoc);
|
2010-03-27 13:57:59 +08:00
|
|
|
DC = SemaRef.computeDeclContext(SS);
|
2010-10-19 13:01:53 +08:00
|
|
|
|
|
|
|
if (DC && SemaRef.RequireCompleteDeclContext(SS, DC))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-27 13:57:59 +08:00
|
|
|
} else {
|
|
|
|
DC = SemaRef.FindInstantiatedContext(D->getLocation(),
|
|
|
|
D->getDeclContext(),
|
|
|
|
TemplateArgs);
|
|
|
|
}
|
2014-05-26 14:22:03 +08:00
|
|
|
if (!DC) return nullptr;
|
2010-03-27 13:57:59 +08:00
|
|
|
}
|
|
|
|
|
2009-03-24 07:06:20 +08:00
|
|
|
// Build the instantiated method declaration.
|
2010-03-27 13:57:59 +08:00
|
|
|
CXXRecordDecl *Record = cast<CXXRecordDecl>(DC);
|
2014-05-26 14:22:03 +08:00
|
|
|
CXXMethodDecl *Method = nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-03-08 16:55:46 +08:00
|
|
|
SourceLocation StartLoc = D->getInnerLocStart();
|
2010-08-12 06:01:17 +08:00
|
|
|
DeclarationNameInfo NameInfo
|
|
|
|
= SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
|
2009-08-22 06:43:28 +08:00
|
|
|
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
Method = CXXConstructorDecl::Create(SemaRef.Context, Record,
|
2011-03-08 16:55:46 +08:00
|
|
|
StartLoc, NameInfo, T, TInfo,
|
2009-09-09 23:08:12 +08:00
|
|
|
Constructor->isExplicit(),
|
2010-04-20 06:54:31 +08:00
|
|
|
Constructor->isInlineSpecified(),
|
2012-02-13 11:54:03 +08:00
|
|
|
false, Constructor->isConstexpr());
|
2013-05-17 10:19:35 +08:00
|
|
|
|
2013-04-10 13:48:59 +08:00
|
|
|
// Claim that the instantiation of a constructor or constructor template
|
|
|
|
// inherits the same constructor that the template does.
|
2013-05-17 10:19:35 +08:00
|
|
|
if (CXXConstructorDecl *Inh = const_cast<CXXConstructorDecl *>(
|
|
|
|
Constructor->getInheritedConstructor())) {
|
|
|
|
// If we're instantiating a specialization of a function template, our
|
|
|
|
// "inherited constructor" will actually itself be a function template.
|
|
|
|
// Instantiate a declaration of it, too.
|
|
|
|
if (FunctionTemplate) {
|
|
|
|
assert(!TemplateParams && Inh->getDescribedFunctionTemplate() &&
|
|
|
|
!Inh->getParent()->isDependentContext() &&
|
|
|
|
"inheriting constructor template in dependent context?");
|
|
|
|
Sema::InstantiatingTemplate Inst(SemaRef, Constructor->getLocation(),
|
|
|
|
Inh);
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-05-17 10:19:35 +08:00
|
|
|
Sema::ContextRAII SavedContext(SemaRef, Inh->getDeclContext());
|
|
|
|
LocalInstantiationScope LocalScope(SemaRef);
|
|
|
|
|
|
|
|
// Use the same template arguments that we deduced for the inheriting
|
|
|
|
// constructor. There's no way they could be deduced differently.
|
|
|
|
MultiLevelTemplateArgumentList InheritedArgs;
|
|
|
|
InheritedArgs.addOuterTemplateArguments(TemplateArgs.getInnermost());
|
|
|
|
Inh = cast_or_null<CXXConstructorDecl>(
|
|
|
|
SemaRef.SubstDecl(Inh, Inh->getDeclContext(), InheritedArgs));
|
|
|
|
if (!Inh)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-05-17 10:19:35 +08:00
|
|
|
}
|
2013-04-10 13:48:59 +08:00
|
|
|
cast<CXXConstructorDecl>(Method)->setInheritedConstructor(Inh);
|
2013-05-17 10:19:35 +08:00
|
|
|
}
|
2009-08-22 06:43:28 +08:00
|
|
|
} else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
|
|
|
|
Method = CXXDestructorDecl::Create(SemaRef.Context, Record,
|
2011-03-08 16:55:46 +08:00
|
|
|
StartLoc, NameInfo, T, TInfo,
|
2010-08-12 06:01:17 +08:00
|
|
|
Destructor->isInlineSpecified(),
|
2010-04-20 06:54:31 +08:00
|
|
|
false);
|
2009-08-22 07:19:43 +08:00
|
|
|
} else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) {
|
|
|
|
Method = CXXConversionDecl::Create(SemaRef.Context, Record,
|
2011-03-08 16:55:46 +08:00
|
|
|
StartLoc, NameInfo, T, TInfo,
|
2009-10-28 05:01:01 +08:00
|
|
|
Conversion->isInlineSpecified(),
|
2011-03-09 01:10:18 +08:00
|
|
|
Conversion->isExplicit(),
|
2012-02-13 11:54:03 +08:00
|
|
|
Conversion->isConstexpr(),
|
2011-10-01 10:31:28 +08:00
|
|
|
Conversion->getLocEnd());
|
2009-08-22 02:42:58 +08:00
|
|
|
} else {
|
2013-04-15 20:38:20 +08:00
|
|
|
StorageClass SC = D->isStatic() ? SC_Static : SC_None;
|
2010-08-12 06:01:17 +08:00
|
|
|
Method = CXXMethodDecl::Create(SemaRef.Context, Record,
|
2011-03-08 16:55:46 +08:00
|
|
|
StartLoc, NameInfo, T, TInfo,
|
2013-04-15 20:38:20 +08:00
|
|
|
SC, D->isInlineSpecified(),
|
2012-02-13 11:54:03 +08:00
|
|
|
D->isConstexpr(), D->getLocEnd());
|
2009-08-22 02:42:58 +08:00
|
|
|
}
|
2009-08-21 08:16:32 +08:00
|
|
|
|
2013-01-25 08:08:28 +08:00
|
|
|
if (D->isInlined())
|
|
|
|
Method->setImplicitlyInline();
|
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
if (QualifierLoc)
|
|
|
|
Method->setQualifierInfo(QualifierLoc);
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2009-08-28 00:57:43 +08:00
|
|
|
if (TemplateParams) {
|
|
|
|
// Our resulting instantiation is actually a function template, since we
|
|
|
|
// are substituting only the outer template parameters. For example, given
|
2009-09-09 23:08:12 +08:00
|
|
|
//
|
2009-08-28 00:57:43 +08:00
|
|
|
// template<typename T>
|
|
|
|
// struct X {
|
|
|
|
// template<typename U> void f(T, U);
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// X<int> x;
|
|
|
|
//
|
|
|
|
// We are instantiating the member template "f" within X<int>, which means
|
|
|
|
// substituting int for T, but leaving "f" as a member function template.
|
|
|
|
// Build the function template itself.
|
|
|
|
FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record,
|
|
|
|
Method->getLocation(),
|
2009-09-09 23:08:12 +08:00
|
|
|
Method->getDeclName(),
|
2009-08-28 00:57:43 +08:00
|
|
|
TemplateParams, Method);
|
2010-03-27 13:57:59 +08:00
|
|
|
if (isFriend) {
|
|
|
|
FunctionTemplate->setLexicalDeclContext(Owner);
|
2013-07-18 07:53:16 +08:00
|
|
|
FunctionTemplate->setObjectOfFriendDecl();
|
2010-03-27 13:57:59 +08:00
|
|
|
} else if (D->isOutOfLine())
|
2009-09-09 23:08:12 +08:00
|
|
|
FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext());
|
2009-08-28 00:57:43 +08:00
|
|
|
Method->setDescribedFunctionTemplate(FunctionTemplate);
|
2009-11-14 09:20:54 +08:00
|
|
|
} else if (FunctionTemplate) {
|
|
|
|
// Record this function template specialization.
|
2013-05-04 07:46:09 +08:00
|
|
|
ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
|
2010-02-11 09:19:42 +08:00
|
|
|
Method->setFunctionTemplateSpecialization(FunctionTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
TemplateArgumentList::CreateCopy(SemaRef.Context,
|
2013-05-04 07:46:09 +08:00
|
|
|
Innermost.begin(),
|
|
|
|
Innermost.size()),
|
2014-05-26 14:22:03 +08:00
|
|
|
/*InsertPos=*/nullptr);
|
2010-03-27 13:57:59 +08:00
|
|
|
} else if (!isFriend) {
|
2009-11-14 09:20:54 +08:00
|
|
|
// Record that this is an instantiation of a member function.
|
2009-10-08 07:56:10 +08:00
|
|
|
Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
|
2009-11-14 09:20:54 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
// If we are instantiating a member function defined
|
2009-07-25 04:34:43 +08:00
|
|
|
// out-of-line, the instantiation will have the same lexical
|
|
|
|
// context (which will be a namespace scope) as the template.
|
2010-03-27 13:57:59 +08:00
|
|
|
if (isFriend) {
|
2010-10-19 10:26:41 +08:00
|
|
|
if (NumTempParamLists)
|
|
|
|
Method->setTemplateParameterListsInfo(SemaRef.Context,
|
|
|
|
NumTempParamLists,
|
|
|
|
TempParamLists.data());
|
|
|
|
|
2010-03-27 13:57:59 +08:00
|
|
|
Method->setLexicalDeclContext(Owner);
|
2013-07-18 07:53:16 +08:00
|
|
|
Method->setObjectOfFriendDecl();
|
2010-03-27 13:57:59 +08:00
|
|
|
} else if (D->isOutOfLine())
|
2009-07-25 04:34:43 +08:00
|
|
|
Method->setLexicalDeclContext(D->getLexicalDeclContext());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 08:38:23 +08:00
|
|
|
// Attach the parameters
|
|
|
|
for (unsigned P = 0; P < Params.size(); ++P)
|
|
|
|
Params[P]->setOwningFunction(Method);
|
2011-09-22 02:16:56 +08:00
|
|
|
Method->setParams(Params);
|
2009-03-24 08:38:23 +08:00
|
|
|
|
|
|
|
if (InitMethodInstantiation(Method, D))
|
|
|
|
Method->setInvalidDecl();
|
2009-03-24 07:06:20 +08:00
|
|
|
|
2010-08-12 06:01:17 +08:00
|
|
|
LookupResult Previous(SemaRef, NameInfo, Sema::LookupOrdinaryName,
|
|
|
|
Sema::ForRedeclaration);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-03-27 13:57:59 +08:00
|
|
|
if (!FunctionTemplate || TemplateParams || isFriend) {
|
|
|
|
SemaRef.LookupQualifiedName(Previous, Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-22 02:42:58 +08:00
|
|
|
// In C++, the previous declaration we find might be a tag type
|
|
|
|
// (class or enum). In this case, the new declaration will hide the
|
|
|
|
// tag type. Note that this does does not apply if we're declaring a
|
|
|
|
// typedef (C++ [dcl.typedef]p4).
|
2009-11-19 06:49:29 +08:00
|
|
|
if (Previous.isSingleTagDecl())
|
|
|
|
Previous.clear();
|
2009-08-22 02:42:58 +08:00
|
|
|
}
|
2009-03-24 07:06:20 +08:00
|
|
|
|
2011-08-14 11:52:19 +08:00
|
|
|
if (!IsClassScopeSpecialization)
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.CheckFunctionDeclaration(nullptr, Method, Previous, false);
|
2009-08-22 07:19:43 +08:00
|
|
|
|
2009-12-02 01:24:26 +08:00
|
|
|
if (D->isPure())
|
|
|
|
SemaRef.CheckPureMethod(Method, SourceRange());
|
|
|
|
|
2012-08-10 11:15:35 +08:00
|
|
|
// Propagate access. For a non-friend declaration, the access is
|
|
|
|
// whatever we're propagating from. For a friend, it should be the
|
|
|
|
// previous declaration we just found.
|
|
|
|
if (isFriend && Method->getPreviousDecl())
|
|
|
|
Method->setAccess(Method->getPreviousDecl()->getAccess());
|
|
|
|
else
|
|
|
|
Method->setAccess(D->getAccess());
|
|
|
|
if (FunctionTemplate)
|
|
|
|
FunctionTemplate->setAccess(Method->getAccess());
|
2010-01-21 05:53:11 +08:00
|
|
|
|
2011-01-20 14:52:44 +08:00
|
|
|
SemaRef.CheckOverrideControl(Method);
|
|
|
|
|
2011-11-16 06:39:08 +08:00
|
|
|
// If a function is defined as defaulted or deleted, mark it as such now.
|
2012-12-08 10:53:02 +08:00
|
|
|
if (D->isExplicitlyDefaulted())
|
|
|
|
SemaRef.SetDeclDefaulted(Method, Method->getLocation());
|
2011-11-16 06:39:08 +08:00
|
|
|
if (D->isDeletedAsWritten())
|
2012-12-08 10:53:02 +08:00
|
|
|
SemaRef.SetDeclDeleted(Method, Method->getLocation());
|
2011-11-16 06:39:08 +08:00
|
|
|
|
2012-08-10 11:15:35 +08:00
|
|
|
// If there's a function template, let our caller handle it.
|
2010-03-27 13:57:59 +08:00
|
|
|
if (FunctionTemplate) {
|
2012-08-10 11:15:35 +08:00
|
|
|
// do nothing
|
|
|
|
|
|
|
|
// Don't hide a (potentially) valid declaration with an invalid one.
|
2010-03-27 13:57:59 +08:00
|
|
|
} else if (Method->isInvalidDecl() && !Previous.empty()) {
|
2012-08-10 11:15:35 +08:00
|
|
|
// do nothing
|
|
|
|
|
|
|
|
// Otherwise, check access to friends and make them visible.
|
|
|
|
} else if (isFriend) {
|
|
|
|
// We only need to re-check access for methods which we didn't
|
|
|
|
// manage to match during parsing.
|
|
|
|
if (!D->getPreviousDecl())
|
|
|
|
SemaRef.CheckFriendAccess(Method);
|
|
|
|
|
|
|
|
Record->makeDeclVisibleInContext(Method);
|
|
|
|
|
|
|
|
// Otherwise, add the declaration. We don't need to do this for
|
|
|
|
// class-scope specializations because we'll have matched them with
|
|
|
|
// the appropriate template.
|
|
|
|
} else if (!IsClassScopeSpecialization) {
|
|
|
|
Owner->addDecl(Method);
|
2010-03-27 13:57:59 +08:00
|
|
|
}
|
2011-05-24 05:07:59 +08:00
|
|
|
|
2009-03-24 07:06:20 +08:00
|
|
|
return Method;
|
|
|
|
}
|
|
|
|
|
2009-03-25 00:43:20 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
|
2009-08-22 02:42:58 +08:00
|
|
|
return VisitCXXMethodDecl(D);
|
2009-03-25 00:43:20 +08:00
|
|
|
}
|
|
|
|
|
2009-03-24 08:15:49 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
2009-08-22 06:43:28 +08:00
|
|
|
return VisitCXXMethodDecl(D);
|
2009-03-24 08:15:49 +08:00
|
|
|
}
|
|
|
|
|
2009-03-25 08:34:44 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) {
|
2009-08-22 07:19:43 +08:00
|
|
|
return VisitCXXMethodDecl(D);
|
2009-03-25 08:34:44 +08:00
|
|
|
}
|
|
|
|
|
2013-06-28 07:21:55 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
|
2013-02-21 09:47:18 +08:00
|
|
|
return SemaRef.SubstParmVarDecl(D, TemplateArgs, /*indexAdjustment*/ 0, None,
|
|
|
|
/*ExpectParameterPack=*/ false);
|
2009-03-24 07:06:20 +08:00
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
|
|
|
|
TemplateTypeParmDecl *D) {
|
|
|
|
// TODO: don't always clone when decls are refcounted.
|
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
llvm-svn: 130628
2011-05-01 08:51:33 +08:00
|
|
|
assert(D->getTypeForDecl()->isTemplateTypeParmType());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
TemplateTypeParmDecl *Inst =
|
2011-03-06 23:48:19 +08:00
|
|
|
TemplateTypeParmDecl::Create(SemaRef.Context, Owner,
|
|
|
|
D->getLocStart(), D->getLocation(),
|
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
llvm-svn: 130628
2011-05-01 08:51:33 +08:00
|
|
|
D->getDepth() - TemplateArgs.getNumLevels(),
|
|
|
|
D->getIndex(), D->getIdentifier(),
|
2009-08-20 09:44:21 +08:00
|
|
|
D->wasDeclaredWithTypename(),
|
|
|
|
D->isParameterPack());
|
2011-03-05 01:52:15 +08:00
|
|
|
Inst->setAccess(AS_public);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-08-29 07:48:32 +08:00
|
|
|
if (D->hasDefaultArgument()) {
|
|
|
|
TypeSourceInfo *InstantiatedDefaultArg =
|
|
|
|
SemaRef.SubstType(D->getDefaultArgumentInfo(), TemplateArgs,
|
|
|
|
D->getDefaultArgumentLoc(), D->getDeclName());
|
|
|
|
if (InstantiatedDefaultArg)
|
|
|
|
Inst->setDefaultArgument(InstantiatedDefaultArg, false);
|
|
|
|
}
|
2009-08-20 09:44:21 +08:00
|
|
|
|
2011-10-08 19:31:46 +08:00
|
|
|
// Introduce this template parameter's instantiation into the instantiation
|
2009-11-01 01:21:17 +08:00
|
|
|
// scope.
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Inst);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
2009-10-24 07:25:44 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
|
|
|
|
NonTypeTemplateParmDecl *D) {
|
|
|
|
// Substitute into the type of the non-type template parameter.
|
2011-01-20 04:10:05 +08:00
|
|
|
TypeLoc TL = D->getTypeSourceInfo()->getTypeLoc();
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TypeSourceInfo *, 4> ExpandedParameterPackTypesAsWritten;
|
|
|
|
SmallVector<QualType, 4> ExpandedParameterPackTypes;
|
2011-01-20 04:10:05 +08:00
|
|
|
bool IsExpandedParameterPack = false;
|
2011-10-08 19:31:46 +08:00
|
|
|
TypeSourceInfo *DI;
|
2009-10-24 07:25:44 +08:00
|
|
|
QualType T;
|
|
|
|
bool Invalid = false;
|
2011-01-20 04:10:05 +08:00
|
|
|
|
|
|
|
if (D->isExpandedParameterPack()) {
|
2011-10-08 19:31:46 +08:00
|
|
|
// The non-type template parameter pack is an already-expanded pack
|
2011-01-20 04:10:05 +08:00
|
|
|
// expansion of types. Substitute into each of the expanded types.
|
|
|
|
ExpandedParameterPackTypes.reserve(D->getNumExpansionTypes());
|
|
|
|
ExpandedParameterPackTypesAsWritten.reserve(D->getNumExpansionTypes());
|
|
|
|
for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
|
|
|
|
TypeSourceInfo *NewDI =SemaRef.SubstType(D->getExpansionTypeSourceInfo(I),
|
|
|
|
TemplateArgs,
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getLocation(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getDeclName());
|
|
|
|
if (!NewDI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
ExpandedParameterPackTypesAsWritten.push_back(NewDI);
|
|
|
|
QualType NewT =SemaRef.CheckNonTypeTemplateParameterType(NewDI->getType(),
|
|
|
|
D->getLocation());
|
|
|
|
if (NewT.isNull())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-01-20 04:10:05 +08:00
|
|
|
ExpandedParameterPackTypes.push_back(NewT);
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
IsExpandedParameterPack = true;
|
|
|
|
DI = D->getTypeSourceInfo();
|
|
|
|
T = DI->getType();
|
2012-09-07 10:06:42 +08:00
|
|
|
} else if (D->isPackExpansion()) {
|
2011-01-20 04:10:05 +08:00
|
|
|
// 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
|
|
|
|
// types.
|
2013-02-19 06:06:02 +08:00
|
|
|
PackExpansionTypeLoc Expansion = TL.castAs<PackExpansionTypeLoc>();
|
2011-01-20 04:10:05 +08:00
|
|
|
TypeLoc Pattern = Expansion.getPatternLoc();
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
2011-01-20 04:10:05 +08:00
|
|
|
SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
// Determine whether the set of unexpanded parameter packs can and should
|
|
|
|
// be expanded.
|
|
|
|
bool Expand = true;
|
|
|
|
bool RetainExpansion = false;
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> OrigNumExpansions
|
2011-01-20 04:10:05 +08:00
|
|
|
= Expansion.getTypePtr()->getNumExpansions();
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> NumExpansions = OrigNumExpansions;
|
2011-01-20 04:10:05 +08:00
|
|
|
if (SemaRef.CheckParameterPacksForExpansion(Expansion.getEllipsisLoc(),
|
|
|
|
Pattern.getSourceRange(),
|
2011-09-22 10:34:54 +08:00
|
|
|
Unexpanded,
|
2011-01-20 04:10:05 +08:00
|
|
|
TemplateArgs,
|
2011-10-08 19:31:46 +08:00
|
|
|
Expand, RetainExpansion,
|
2011-01-20 04:10:05 +08:00
|
|
|
NumExpansions))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
if (Expand) {
|
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
|
|
|
|
TypeSourceInfo *NewDI = SemaRef.SubstType(Pattern, TemplateArgs,
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getLocation(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getDeclName());
|
|
|
|
if (!NewDI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
ExpandedParameterPackTypesAsWritten.push_back(NewDI);
|
|
|
|
QualType NewT = SemaRef.CheckNonTypeTemplateParameterType(
|
|
|
|
NewDI->getType(),
|
|
|
|
D->getLocation());
|
|
|
|
if (NewT.isNull())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-01-20 04:10:05 +08:00
|
|
|
ExpandedParameterPackTypes.push_back(NewT);
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
// Note that we have an expanded parameter pack. The "type" of this
|
|
|
|
// 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();
|
|
|
|
} else {
|
|
|
|
// We cannot fully expand the pack expansion now, so substitute into the
|
|
|
|
// pattern and create a new pack expansion type.
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
|
|
|
|
TypeSourceInfo *NewPattern = SemaRef.SubstType(Pattern, TemplateArgs,
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getLocation(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getDeclName());
|
|
|
|
if (!NewPattern)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
DI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(),
|
|
|
|
NumExpansions);
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
T = DI->getType();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Simple case: substitution into a parameter that is not a parameter pack.
|
2011-10-08 19:31:46 +08:00
|
|
|
DI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getLocation(), D->getDeclName());
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
// Check that this type is acceptable for a non-type template parameter.
|
2011-10-08 19:31:46 +08:00
|
|
|
T = SemaRef.CheckNonTypeTemplateParameterType(DI->getType(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getLocation());
|
|
|
|
if (T.isNull()) {
|
|
|
|
T = SemaRef.Context.IntTy;
|
|
|
|
Invalid = true;
|
|
|
|
}
|
2009-10-24 07:25:44 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
NonTypeTemplateParmDecl *Param;
|
|
|
|
if (IsExpandedParameterPack)
|
2011-10-08 19:31:46 +08:00
|
|
|
Param = NonTypeTemplateParmDecl::Create(SemaRef.Context, Owner,
|
2011-03-08 16:55:46 +08:00
|
|
|
D->getInnerLocStart(),
|
|
|
|
D->getLocation(),
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getDepth() - TemplateArgs.getNumLevels(),
|
|
|
|
D->getPosition(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getIdentifier(), T,
|
|
|
|
DI,
|
|
|
|
ExpandedParameterPackTypes.data(),
|
|
|
|
ExpandedParameterPackTypes.size(),
|
|
|
|
ExpandedParameterPackTypesAsWritten.data());
|
|
|
|
else
|
2011-10-08 19:31:46 +08:00
|
|
|
Param = NonTypeTemplateParmDecl::Create(SemaRef.Context, Owner,
|
2011-03-08 16:55:46 +08:00
|
|
|
D->getInnerLocStart(),
|
2011-01-20 04:10:05 +08:00
|
|
|
D->getLocation(),
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getDepth() - TemplateArgs.getNumLevels(),
|
|
|
|
D->getPosition(),
|
|
|
|
D->getIdentifier(), T,
|
2011-01-20 04:10:05 +08:00
|
|
|
D->isParameterPack(), DI);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-03-05 01:52:15 +08:00
|
|
|
Param->setAccess(AS_public);
|
2009-10-24 07:25:44 +08:00
|
|
|
if (Invalid)
|
|
|
|
Param->setInvalidDecl();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-08-29 07:48:32 +08:00
|
|
|
if (D->hasDefaultArgument()) {
|
|
|
|
ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs);
|
|
|
|
if (!Value.isInvalid())
|
|
|
|
Param->setDefaultArgument(Value.get(), false);
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
|
|
|
// Introduce this template parameter's instantiation into the instantiation
|
2009-11-01 01:21:17 +08:00
|
|
|
// scope.
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
|
2009-10-24 07:25:44 +08:00
|
|
|
return Param;
|
|
|
|
}
|
|
|
|
|
2012-09-07 10:06:42 +08:00
|
|
|
static void collectUnexpandedParameterPacks(
|
|
|
|
Sema &S,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
|
|
|
|
for (TemplateParameterList::const_iterator I = Params->begin(),
|
|
|
|
E = Params->end(); I != E; ++I) {
|
|
|
|
if ((*I)->isTemplateParameterPack())
|
|
|
|
continue;
|
|
|
|
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*I))
|
|
|
|
S.collectUnexpandedParameterPacks(NTTP->getTypeSourceInfo()->getTypeLoc(),
|
|
|
|
Unexpanded);
|
|
|
|
if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*I))
|
|
|
|
collectUnexpandedParameterPacks(S, TTP->getTemplateParameters(),
|
|
|
|
Unexpanded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 00:58:32 +08:00
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitTemplateTemplateParmDecl(
|
|
|
|
TemplateTemplateParmDecl *D) {
|
|
|
|
// Instantiate the template parameter list of the template template parameter.
|
|
|
|
TemplateParameterList *TempParams = D->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams;
|
2012-09-07 10:06:42 +08:00
|
|
|
SmallVector<TemplateParameterList*, 8> ExpandedParams;
|
|
|
|
|
|
|
|
bool IsExpandedParameterPack = false;
|
|
|
|
|
|
|
|
if (D->isExpandedParameterPack()) {
|
|
|
|
// The template template parameter pack is an already-expanded pack
|
|
|
|
// expansion of template parameters. Substitute into each of the expanded
|
|
|
|
// parameters.
|
|
|
|
ExpandedParams.reserve(D->getNumExpansionTemplateParameters());
|
|
|
|
for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
|
|
|
|
I != N; ++I) {
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
TemplateParameterList *Expansion =
|
|
|
|
SubstTemplateParams(D->getExpansionTemplateParameters(I));
|
|
|
|
if (!Expansion)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-07 10:06:42 +08:00
|
|
|
ExpandedParams.push_back(Expansion);
|
|
|
|
}
|
|
|
|
|
|
|
|
IsExpandedParameterPack = true;
|
|
|
|
InstParams = TempParams;
|
|
|
|
} else if (D->isPackExpansion()) {
|
|
|
|
// The template template parameter pack expands to a pack of template
|
|
|
|
// template parameters. Determine whether we need to expand this parameter
|
|
|
|
// pack into separate parameters.
|
|
|
|
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
collectUnexpandedParameterPacks(SemaRef, D->getTemplateParameters(),
|
|
|
|
Unexpanded);
|
|
|
|
|
|
|
|
// Determine whether the set of unexpanded parameter packs can and should
|
|
|
|
// be expanded.
|
|
|
|
bool Expand = true;
|
|
|
|
bool RetainExpansion = false;
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> NumExpansions;
|
2012-09-07 10:06:42 +08:00
|
|
|
if (SemaRef.CheckParameterPacksForExpansion(D->getLocation(),
|
|
|
|
TempParams->getSourceRange(),
|
|
|
|
Unexpanded,
|
|
|
|
TemplateArgs,
|
|
|
|
Expand, RetainExpansion,
|
|
|
|
NumExpansions))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-07 10:06:42 +08:00
|
|
|
|
|
|
|
if (Expand) {
|
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
TemplateParameterList *Expansion = SubstTemplateParams(TempParams);
|
|
|
|
if (!Expansion)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-07 10:06:42 +08:00
|
|
|
ExpandedParams.push_back(Expansion);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that we have an expanded parameter pack. The "type" of this
|
|
|
|
// expanded parameter pack is the original expansion type, but callers
|
|
|
|
// will end up using the expanded parameter pack types for type-checking.
|
|
|
|
IsExpandedParameterPack = true;
|
|
|
|
InstParams = TempParams;
|
|
|
|
} else {
|
|
|
|
// We cannot fully expand the pack expansion now, so just substitute
|
|
|
|
// into the pattern.
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
|
|
|
|
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2012-09-07 10:06:42 +08:00
|
|
|
}
|
|
|
|
} else {
|
2009-11-12 00:58:32 +08:00
|
|
|
// Perform the actual substitution of template parameters within a new,
|
|
|
|
// local instantiation scope.
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
2009-11-12 00:58:32 +08:00
|
|
|
InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
}
|
|
|
|
|
2009-11-12 00:58:32 +08:00
|
|
|
// Build the template template parameter.
|
2012-09-07 10:06:42 +08:00
|
|
|
TemplateTemplateParmDecl *Param;
|
|
|
|
if (IsExpandedParameterPack)
|
|
|
|
Param = TemplateTemplateParmDecl::Create(SemaRef.Context, Owner,
|
|
|
|
D->getLocation(),
|
|
|
|
D->getDepth() - TemplateArgs.getNumLevels(),
|
|
|
|
D->getPosition(),
|
|
|
|
D->getIdentifier(), InstParams,
|
|
|
|
ExpandedParams);
|
|
|
|
else
|
|
|
|
Param = TemplateTemplateParmDecl::Create(SemaRef.Context, Owner,
|
|
|
|
D->getLocation(),
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getDepth() - TemplateArgs.getNumLevels(),
|
2012-09-07 10:06:42 +08:00
|
|
|
D->getPosition(),
|
|
|
|
D->isParameterPack(),
|
|
|
|
D->getIdentifier(), InstParams);
|
2013-08-29 07:48:32 +08:00
|
|
|
if (D->hasDefaultArgument()) {
|
|
|
|
NestedNameSpecifierLoc QualifierLoc =
|
|
|
|
D->getDefaultArgument().getTemplateQualifierLoc();
|
|
|
|
QualifierLoc =
|
|
|
|
SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs);
|
|
|
|
TemplateName TName = SemaRef.SubstTemplateName(
|
|
|
|
QualifierLoc, D->getDefaultArgument().getArgument().getAsTemplate(),
|
|
|
|
D->getDefaultArgument().getTemplateNameLoc(), TemplateArgs);
|
|
|
|
if (!TName.isNull())
|
|
|
|
Param->setDefaultArgument(
|
|
|
|
TemplateArgumentLoc(TemplateArgument(TName),
|
|
|
|
D->getDefaultArgument().getTemplateQualifierLoc(),
|
|
|
|
D->getDefaultArgument().getTemplateNameLoc()),
|
|
|
|
false);
|
|
|
|
}
|
2011-03-05 01:52:15 +08:00
|
|
|
Param->setAccess(AS_public);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
|
|
|
// Introduce this template parameter's instantiation into the instantiation
|
2009-11-12 00:58:32 +08:00
|
|
|
// scope.
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-11-12 00:58:32 +08:00
|
|
|
return Param;
|
|
|
|
}
|
|
|
|
|
2009-11-17 14:07:40 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
|
2011-02-26 00:33:46 +08:00
|
|
|
// Using directives are never dependent (and never contain any types or
|
|
|
|
// expressions), so they require no explicit instantiation work.
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-11-17 14:07:40 +08:00
|
|
|
UsingDirectiveDecl *Inst
|
|
|
|
= UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(),
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getNamespaceKeyLocation(),
|
2011-02-26 00:33:46 +08:00
|
|
|
D->getQualifierLoc(),
|
2011-10-08 19:31:46 +08:00
|
|
|
D->getIdentLocation(),
|
|
|
|
D->getNominatedNamespace(),
|
2009-11-17 14:07:40 +08:00
|
|
|
D->getCommonAncestor());
|
2012-09-05 17:55:10 +08:00
|
|
|
|
|
|
|
// Add the using directive to its declaration context
|
|
|
|
// only if this is not a function or method.
|
|
|
|
if (!Owner->isFunctionOrMethod())
|
|
|
|
Owner->addDecl(Inst);
|
|
|
|
|
2009-11-17 14:07:40 +08:00
|
|
|
return Inst;
|
|
|
|
}
|
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) {
|
2010-09-30 01:58:28 +08:00
|
|
|
|
|
|
|
// The nested name specifier may be dependent, for example
|
|
|
|
// template <typename T> struct t {
|
|
|
|
// struct s1 { T f1(); };
|
|
|
|
// struct s2 : s1 { using s1::f1; };
|
|
|
|
// };
|
|
|
|
// template struct t<int>;
|
|
|
|
// Here, in using s1::f1, s1 refers to t<T>::s1;
|
|
|
|
// we need to substitute for t<int>::s1.
|
2011-02-25 23:54:31 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc
|
|
|
|
= SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
|
|
|
|
TemplateArgs);
|
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-09-30 01:58:28 +08:00
|
|
|
|
|
|
|
// The name info is non-dependent, so no transformation
|
|
|
|
// is required.
|
2010-08-12 19:46:03 +08:00
|
|
|
DeclarationNameInfo NameInfo = D->getNameInfo();
|
2009-12-05 06:46:56 +08:00
|
|
|
|
2009-12-10 17:41:52 +08:00
|
|
|
// We only need to do redeclaration lookups if we're in a class
|
|
|
|
// scope (in fact, it's not really even possible in non-class
|
|
|
|
// scopes).
|
|
|
|
bool CheckRedeclaration = Owner->isRecord();
|
|
|
|
|
2010-08-12 19:46:03 +08:00
|
|
|
LookupResult Prev(SemaRef, NameInfo, Sema::LookupUsingDeclName,
|
|
|
|
Sema::ForRedeclaration);
|
2009-12-10 17:41:52 +08:00
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
UsingDecl *NewUD = UsingDecl::Create(SemaRef.Context, Owner,
|
2013-07-22 18:54:09 +08:00
|
|
|
D->getUsingLoc(),
|
2011-02-25 23:54:31 +08:00
|
|
|
QualifierLoc,
|
2010-08-12 19:46:03 +08:00
|
|
|
NameInfo,
|
2013-07-22 18:54:09 +08:00
|
|
|
D->hasTypename());
|
2009-12-05 06:46:56 +08:00
|
|
|
|
2011-02-25 23:54:31 +08:00
|
|
|
CXXScopeSpec SS;
|
|
|
|
SS.Adopt(QualifierLoc);
|
2009-12-10 17:41:52 +08:00
|
|
|
if (CheckRedeclaration) {
|
|
|
|
Prev.setHideTags(false);
|
|
|
|
SemaRef.LookupQualifiedName(Prev, Owner);
|
|
|
|
|
|
|
|
// Check for invalid redeclarations.
|
2013-07-22 18:54:09 +08:00
|
|
|
if (SemaRef.CheckUsingDeclRedeclaration(D->getUsingLoc(),
|
|
|
|
D->hasTypename(), SS,
|
2009-12-10 17:41:52 +08:00
|
|
|
D->getLocation(), Prev))
|
|
|
|
NewUD->setInvalidDecl();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NewUD->isInvalidDecl() &&
|
2014-04-03 05:44:35 +08:00
|
|
|
SemaRef.CheckUsingDeclQualifier(D->getUsingLoc(), SS, NameInfo,
|
2009-12-05 06:46:56 +08:00
|
|
|
D->getLocation()))
|
|
|
|
NewUD->setInvalidDecl();
|
2009-12-10 17:41:52 +08:00
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
SemaRef.Context.setInstantiatedFromUsingDecl(NewUD, D);
|
|
|
|
NewUD->setAccess(D->getAccess());
|
|
|
|
Owner->addDecl(NewUD);
|
|
|
|
|
2009-12-10 17:41:52 +08:00
|
|
|
// Don't process the shadow decls for an invalid decl.
|
|
|
|
if (NewUD->isInvalidDecl())
|
|
|
|
return NewUD;
|
|
|
|
|
2012-04-02 09:30:27 +08:00
|
|
|
if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName) {
|
2014-05-01 08:35:04 +08:00
|
|
|
SemaRef.CheckInheritingConstructorUsingDecl(NewUD);
|
2012-04-02 09:30:27 +08:00
|
|
|
return NewUD;
|
|
|
|
}
|
|
|
|
|
2009-12-23 06:26:37 +08:00
|
|
|
bool isFunctionScope = Owner->isFunctionOrMethod();
|
|
|
|
|
2009-12-10 17:41:52 +08:00
|
|
|
// Process the shadow decls.
|
2014-03-14 02:07:29 +08:00
|
|
|
for (auto *Shadow : D->shadows()) {
|
2009-12-10 17:41:52 +08:00
|
|
|
NamedDecl *InstTarget =
|
2013-10-23 10:17:46 +08:00
|
|
|
cast_or_null<NamedDecl>(SemaRef.FindInstantiatedDecl(
|
|
|
|
Shadow->getLocation(), Shadow->getTargetDecl(), TemplateArgs));
|
2011-03-05 03:46:35 +08:00
|
|
|
if (!InstTarget)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-12-10 17:41:52 +08:00
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
UsingShadowDecl *PrevDecl = nullptr;
|
2013-10-23 10:17:46 +08:00
|
|
|
if (CheckRedeclaration) {
|
|
|
|
if (SemaRef.CheckUsingShadowDecl(NewUD, InstTarget, Prev, PrevDecl))
|
|
|
|
continue;
|
|
|
|
} else if (UsingShadowDecl *OldPrev = Shadow->getPreviousDecl()) {
|
|
|
|
PrevDecl = cast_or_null<UsingShadowDecl>(SemaRef.FindInstantiatedDecl(
|
|
|
|
Shadow->getLocation(), OldPrev, TemplateArgs));
|
|
|
|
}
|
2009-12-10 17:41:52 +08:00
|
|
|
|
2013-10-23 10:17:46 +08:00
|
|
|
UsingShadowDecl *InstShadow =
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.BuildUsingShadowDecl(/*Scope*/nullptr, NewUD, InstTarget,
|
|
|
|
PrevDecl);
|
2009-12-10 17:41:52 +08:00
|
|
|
SemaRef.Context.setInstantiatedFromUsingShadowDecl(InstShadow, Shadow);
|
2009-12-23 06:26:37 +08:00
|
|
|
|
|
|
|
if (isFunctionScope)
|
|
|
|
SemaRef.CurrentInstantiationScope->InstantiatedLocal(Shadow, InstShadow);
|
2009-12-10 17:41:52 +08:00
|
|
|
}
|
2009-12-05 06:46:56 +08:00
|
|
|
|
|
|
|
return NewUD;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitUsingShadowDecl(UsingShadowDecl *D) {
|
2009-12-10 17:41:52 +08:00
|
|
|
// Ignore these; we handle them in bulk when processing the UsingDecl.
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-12-05 06:46:56 +08:00
|
|
|
}
|
|
|
|
|
2009-11-18 10:36:19 +08:00
|
|
|
Decl * TemplateDeclInstantiator
|
|
|
|
::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
|
2011-02-25 23:54:31 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc
|
2011-10-08 19:31:46 +08:00
|
|
|
= SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
|
2011-02-25 23:54:31 +08:00
|
|
|
TemplateArgs);
|
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-11-18 10:36:19 +08:00
|
|
|
|
|
|
|
CXXScopeSpec SS;
|
2011-02-25 23:54:31 +08:00
|
|
|
SS.Adopt(QualifierLoc);
|
2009-11-18 10:36:19 +08:00
|
|
|
|
2010-08-12 19:46:03 +08:00
|
|
|
// Since NameInfo refers to a typename, it cannot be a C++ special name.
|
2012-11-14 23:08:31 +08:00
|
|
|
// Hence, no transformation is required for it.
|
2010-08-12 19:46:03 +08:00
|
|
|
DeclarationNameInfo NameInfo(D->getDeclName(), D->getLocation());
|
2009-11-18 10:36:19 +08:00
|
|
|
NamedDecl *UD =
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.BuildUsingDeclaration(/*Scope*/ nullptr, D->getAccess(),
|
|
|
|
D->getUsingLoc(), SS, NameInfo, nullptr,
|
2009-11-18 10:36:19 +08:00
|
|
|
/*instantiation*/ true,
|
|
|
|
/*typename*/ true, D->getTypenameLoc());
|
2010-05-20 01:02:24 +08:00
|
|
|
if (UD)
|
2009-12-05 06:46:56 +08:00
|
|
|
SemaRef.Context.setInstantiatedFromUsingDecl(cast<UsingDecl>(UD), D);
|
|
|
|
|
2009-11-18 10:36:19 +08:00
|
|
|
return UD;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl * TemplateDeclInstantiator
|
|
|
|
::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
|
2011-02-25 23:54:31 +08:00
|
|
|
NestedNameSpecifierLoc QualifierLoc
|
|
|
|
= SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), TemplateArgs);
|
|
|
|
if (!QualifierLoc)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-08-28 23:18:15 +08:00
|
|
|
CXXScopeSpec SS;
|
2011-02-25 23:54:31 +08:00
|
|
|
SS.Adopt(QualifierLoc);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-12 19:46:03 +08:00
|
|
|
DeclarationNameInfo NameInfo
|
|
|
|
= SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
NamedDecl *UD =
|
2014-05-26 14:22:03 +08:00
|
|
|
SemaRef.BuildUsingDeclaration(/*Scope*/ nullptr, D->getAccess(),
|
|
|
|
D->getUsingLoc(), SS, NameInfo, nullptr,
|
2009-11-18 10:36:19 +08:00
|
|
|
/*instantiation*/ true,
|
|
|
|
/*typename*/ false, SourceLocation());
|
2010-05-20 01:02:24 +08:00
|
|
|
if (UD)
|
2009-12-05 06:46:56 +08:00
|
|
|
SemaRef.Context.setInstantiatedFromUsingDecl(cast<UsingDecl>(UD), D);
|
|
|
|
|
2009-08-30 03:37:28 +08:00
|
|
|
return UD;
|
2009-08-28 23:18:15 +08:00
|
|
|
}
|
|
|
|
|
2011-08-14 11:52:19 +08:00
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitClassScopeFunctionSpecializationDecl(
|
|
|
|
ClassScopeFunctionSpecializationDecl *Decl) {
|
|
|
|
CXXMethodDecl *OldFD = Decl->getSpecialization();
|
2012-06-26 01:21:05 +08:00
|
|
|
CXXMethodDecl *NewFD = cast<CXXMethodDecl>(VisitCXXMethodDecl(OldFD,
|
2014-05-26 14:22:03 +08:00
|
|
|
nullptr, true));
|
2011-08-14 11:52:19 +08:00
|
|
|
|
|
|
|
LookupResult Previous(SemaRef, NewFD->getNameInfo(), Sema::LookupOrdinaryName,
|
|
|
|
Sema::ForRedeclaration);
|
|
|
|
|
2012-06-26 01:21:05 +08:00
|
|
|
TemplateArgumentListInfo TemplateArgs;
|
2014-05-26 14:22:03 +08:00
|
|
|
TemplateArgumentListInfo *TemplateArgsPtr = nullptr;
|
2012-06-26 01:21:05 +08:00
|
|
|
if (Decl->hasExplicitTemplateArgs()) {
|
|
|
|
TemplateArgs = Decl->templateArgs();
|
|
|
|
TemplateArgsPtr = &TemplateArgs;
|
|
|
|
}
|
|
|
|
|
2011-08-14 11:52:19 +08:00
|
|
|
SemaRef.LookupQualifiedName(Previous, SemaRef.CurContext);
|
2012-06-26 01:21:05 +08:00
|
|
|
if (SemaRef.CheckFunctionTemplateSpecialization(NewFD, TemplateArgsPtr,
|
|
|
|
Previous)) {
|
2011-08-14 11:52:19 +08:00
|
|
|
NewFD->setInvalidDecl();
|
|
|
|
return NewFD;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate the specialization with the pattern.
|
|
|
|
FunctionDecl *Specialization = cast<FunctionDecl>(Previous.getFoundDecl());
|
|
|
|
assert(Specialization && "Class scope Specialization is null");
|
|
|
|
SemaRef.Context.setClassScopeSpecializationPattern(Specialization, OldFD);
|
|
|
|
|
|
|
|
return NewFD;
|
|
|
|
}
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl(
|
|
|
|
OMPThreadPrivateDecl *D) {
|
2013-05-13 12:18:18 +08:00
|
|
|
SmallVector<Expr *, 5> Vars;
|
2014-03-14 23:55:35 +08:00
|
|
|
for (auto *I : D->varlists()) {
|
2014-05-29 18:55:11 +08:00
|
|
|
Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get();
|
2013-03-22 14:34:35 +08:00
|
|
|
assert(isa<DeclRefExpr>(Var) && "threadprivate arg is not a DeclRefExpr");
|
2013-05-13 12:18:18 +08:00
|
|
|
Vars.push_back(Var);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OMPThreadPrivateDecl *TD =
|
|
|
|
SemaRef.CheckOMPThreadPrivateDecl(D->getLocation(), Vars);
|
|
|
|
|
2014-03-07 17:46:29 +08:00
|
|
|
TD->setAccess(AS_public);
|
|
|
|
Owner->addDecl(TD);
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
return TD;
|
|
|
|
}
|
|
|
|
|
2013-06-28 07:21:55 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) {
|
2014-05-26 14:22:03 +08:00
|
|
|
return VisitFunctionDecl(D, nullptr);
|
2013-06-28 07:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D) {
|
2014-05-26 14:22:03 +08:00
|
|
|
return VisitCXXMethodDecl(D, nullptr);
|
2013-06-28 07:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitRecordDecl(RecordDecl *D) {
|
|
|
|
llvm_unreachable("There are only CXXRecordDecls in C++");
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *
|
|
|
|
TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D) {
|
2013-12-14 09:04:22 +08:00
|
|
|
// As a MS extension, we permit class-scope explicit specialization
|
|
|
|
// of member class templates.
|
|
|
|
ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate();
|
|
|
|
assert(ClassTemplate->getDeclContext()->isRecord() &&
|
|
|
|
D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
|
|
|
|
"can only instantiate an explicit specialization "
|
|
|
|
"for a member class template");
|
|
|
|
|
|
|
|
// Lookup the already-instantiated declaration in the instantiation
|
|
|
|
// of the class template. FIXME: Diagnose or assert if this fails?
|
|
|
|
DeclContext::lookup_result Found
|
|
|
|
= Owner->lookup(ClassTemplate->getDeclName());
|
|
|
|
if (Found.empty())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
ClassTemplateDecl *InstClassTemplate
|
|
|
|
= dyn_cast<ClassTemplateDecl>(Found.front());
|
|
|
|
if (!InstClassTemplate)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// Substitute into the template arguments of the class template explicit
|
|
|
|
// specialization.
|
|
|
|
TemplateSpecializationTypeLoc Loc = D->getTypeAsWritten()->getTypeLoc().
|
|
|
|
castAs<TemplateSpecializationTypeLoc>();
|
|
|
|
TemplateArgumentListInfo InstTemplateArgs(Loc.getLAngleLoc(),
|
|
|
|
Loc.getRAngleLoc());
|
|
|
|
SmallVector<TemplateArgumentLoc, 4> ArgLocs;
|
|
|
|
for (unsigned I = 0; I != Loc.getNumArgs(); ++I)
|
|
|
|
ArgLocs.push_back(Loc.getArgLoc(I));
|
|
|
|
if (SemaRef.Subst(ArgLocs.data(), ArgLocs.size(),
|
|
|
|
InstTemplateArgs, TemplateArgs))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// Check that the template argument list is well-formed for this
|
|
|
|
// class template.
|
|
|
|
SmallVector<TemplateArgument, 4> Converted;
|
|
|
|
if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
|
|
|
|
D->getLocation(),
|
|
|
|
InstTemplateArgs,
|
|
|
|
false,
|
|
|
|
Converted))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// Figure out where to insert this class template explicit specialization
|
|
|
|
// in the member template's set of class template explicit specializations.
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
ClassTemplateSpecializationDecl *PrevDecl =
|
2014-06-26 12:58:53 +08:00
|
|
|
InstClassTemplate->findSpecialization(Converted, InsertPos);
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// Check whether we've already seen a conflicting instantiation of this
|
|
|
|
// declaration (for instance, if there was a prior implicit instantiation).
|
|
|
|
bool Ignored;
|
|
|
|
if (PrevDecl &&
|
|
|
|
SemaRef.CheckSpecializationInstantiationRedecl(D->getLocation(),
|
|
|
|
D->getSpecializationKind(),
|
|
|
|
PrevDecl,
|
|
|
|
PrevDecl->getSpecializationKind(),
|
|
|
|
PrevDecl->getPointOfInstantiation(),
|
|
|
|
Ignored))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// If PrevDecl was a definition and D is also a definition, diagnose.
|
|
|
|
// This happens in cases like:
|
|
|
|
//
|
|
|
|
// template<typename T, typename U>
|
|
|
|
// struct Outer {
|
|
|
|
// template<typename X> struct Inner;
|
|
|
|
// template<> struct Inner<T> {};
|
|
|
|
// template<> struct Inner<U> {};
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// Outer<int, int> outer; // error: the explicit specializations of Inner
|
|
|
|
// // have the same signature.
|
|
|
|
if (PrevDecl && PrevDecl->getDefinition() &&
|
|
|
|
D->isThisDeclarationADefinition()) {
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_redefinition) << PrevDecl;
|
|
|
|
SemaRef.Diag(PrevDecl->getDefinition()->getLocation(),
|
|
|
|
diag::note_previous_definition);
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the class template partial specialization declaration.
|
|
|
|
ClassTemplateSpecializationDecl *InstD
|
|
|
|
= ClassTemplateSpecializationDecl::Create(SemaRef.Context,
|
|
|
|
D->getTagKind(),
|
|
|
|
Owner,
|
|
|
|
D->getLocStart(),
|
|
|
|
D->getLocation(),
|
|
|
|
InstClassTemplate,
|
|
|
|
Converted.data(),
|
|
|
|
Converted.size(),
|
|
|
|
PrevDecl);
|
|
|
|
|
|
|
|
// Add this partial specialization to the set of class template partial
|
|
|
|
// specializations.
|
|
|
|
if (!PrevDecl)
|
|
|
|
InstClassTemplate->AddSpecialization(InstD, InsertPos);
|
|
|
|
|
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(D, InstD))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
// Build the canonical type that describes the converted template
|
|
|
|
// arguments of the class template explicit specialization.
|
|
|
|
QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
|
|
|
|
TemplateName(InstClassTemplate), Converted.data(), Converted.size(),
|
|
|
|
SemaRef.Context.getRecordType(InstD));
|
|
|
|
|
|
|
|
// Build the fully-sugared type for this class template
|
|
|
|
// specialization as the user wrote in the specialization
|
|
|
|
// itself. This means that we'll pretty-print the type retrieved
|
|
|
|
// from the specialization's declaration the way that the user
|
|
|
|
// actually wrote the specialization, rather than formatting the
|
|
|
|
// name based on the "canonical" representation used to store the
|
|
|
|
// template arguments in the specialization.
|
|
|
|
TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo(
|
|
|
|
TemplateName(InstClassTemplate), D->getLocation(), InstTemplateArgs,
|
|
|
|
CanonType);
|
|
|
|
|
|
|
|
InstD->setAccess(D->getAccess());
|
|
|
|
InstD->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation);
|
|
|
|
InstD->setSpecializationKind(D->getSpecializationKind());
|
|
|
|
InstD->setTypeAsWritten(WrittenTy);
|
|
|
|
InstD->setExternLoc(D->getExternLoc());
|
|
|
|
InstD->setTemplateKeywordLoc(D->getTemplateKeywordLoc());
|
|
|
|
|
|
|
|
Owner->addDecl(InstD);
|
|
|
|
|
|
|
|
// Instantiate the members of the class-scope explicit specialization eagerly.
|
|
|
|
// We don't have support for lazy instantiation of an explicit specialization
|
|
|
|
// yet, and MSVC eagerly instantiates in this case.
|
|
|
|
if (D->isThisDeclarationADefinition() &&
|
|
|
|
SemaRef.InstantiateClass(D->getLocation(), InstD, D, TemplateArgs,
|
|
|
|
TSK_ImplicitInstantiation,
|
|
|
|
/*Complain=*/true))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-12-14 09:04:22 +08:00
|
|
|
|
|
|
|
return InstD;
|
2013-06-28 07:21:55 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
|
|
|
|
VarTemplateSpecializationDecl *D) {
|
|
|
|
|
|
|
|
TemplateArgumentListInfo VarTemplateArgsInfo;
|
|
|
|
VarTemplateDecl *VarTemplate = D->getSpecializedTemplate();
|
|
|
|
assert(VarTemplate &&
|
|
|
|
"A template specialization without specialized template?");
|
|
|
|
|
|
|
|
// Substitute the current template arguments.
|
|
|
|
const TemplateArgumentListInfo &TemplateArgsInfo = D->getTemplateArgsInfo();
|
|
|
|
VarTemplateArgsInfo.setLAngleLoc(TemplateArgsInfo.getLAngleLoc());
|
|
|
|
VarTemplateArgsInfo.setRAngleLoc(TemplateArgsInfo.getRAngleLoc());
|
|
|
|
|
|
|
|
if (SemaRef.Subst(TemplateArgsInfo.getArgumentArray(),
|
|
|
|
TemplateArgsInfo.size(), VarTemplateArgsInfo, TemplateArgs))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Check that the template argument list is well-formed for this template.
|
|
|
|
SmallVector<TemplateArgument, 4> Converted;
|
|
|
|
if (SemaRef.CheckTemplateArgumentList(
|
|
|
|
VarTemplate, VarTemplate->getLocStart(),
|
|
|
|
const_cast<TemplateArgumentListInfo &>(VarTemplateArgsInfo), false,
|
2014-01-09 10:22:22 +08:00
|
|
|
Converted))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Find the variable template specialization declaration that
|
|
|
|
// corresponds to these arguments.
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
if (VarTemplateSpecializationDecl *VarSpec = VarTemplate->findSpecialization(
|
2014-06-26 12:58:53 +08:00
|
|
|
Converted, InsertPos))
|
2013-08-06 09:03:05 +08:00
|
|
|
// If we already have a variable template specialization, return it.
|
|
|
|
return VarSpec;
|
|
|
|
|
|
|
|
return VisitVarTemplateSpecializationDecl(VarTemplate, D, InsertPos,
|
|
|
|
VarTemplateArgsInfo, Converted);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
|
|
|
|
VarTemplateDecl *VarTemplate, VarDecl *D, void *InsertPos,
|
|
|
|
const TemplateArgumentListInfo &TemplateArgsInfo,
|
2014-06-29 07:22:23 +08:00
|
|
|
ArrayRef<TemplateArgument> Converted) {
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// If this is the variable for an anonymous struct or union,
|
|
|
|
// instantiate the anonymous struct/union type first.
|
|
|
|
if (const RecordType *RecordTy = D->getType()->getAs<RecordType>())
|
|
|
|
if (RecordTy->getDecl()->isAnonymousStructOrUnion())
|
|
|
|
if (!VisitCXXRecordDecl(cast<CXXRecordDecl>(RecordTy->getDecl())))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Do substitution on the type of the declaration
|
|
|
|
TypeSourceInfo *DI =
|
|
|
|
SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
|
|
|
|
D->getTypeSpecStartLoc(), D->getDeclName());
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
if (DI->getType()->isFunctionType()) {
|
|
|
|
SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
|
|
|
|
<< D->isStaticDataMember() << DI->getType();
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the instantiated declaration
|
|
|
|
VarTemplateSpecializationDecl *Var = VarTemplateSpecializationDecl::Create(
|
|
|
|
SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
|
|
|
|
VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted.data(),
|
|
|
|
Converted.size());
|
|
|
|
Var->setTemplateArgsInfo(TemplateArgsInfo);
|
2013-09-28 04:14:12 +08:00
|
|
|
if (InsertPos)
|
|
|
|
VarTemplate->AddSpecialization(Var, InsertPos);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(D, Var))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs,
|
2013-09-20 09:15:31 +08:00
|
|
|
Owner, StartingScope);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
return Var;
|
|
|
|
}
|
|
|
|
|
2013-06-28 07:21:55 +08:00
|
|
|
Decl *TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
|
|
|
|
llvm_unreachable("@defs is not supported in Objective-C++");
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
|
|
|
|
// FIXME: We need to be able to instantiate FriendTemplateDecls.
|
|
|
|
unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID(
|
|
|
|
DiagnosticsEngine::Error,
|
|
|
|
"cannot instantiate %0 yet");
|
|
|
|
SemaRef.Diag(D->getLocation(), DiagID)
|
|
|
|
<< D->getDeclKindName();
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-06-28 07:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *TemplateDeclInstantiator::VisitDecl(Decl *D) {
|
|
|
|
llvm_unreachable("Unexpected decl");
|
|
|
|
}
|
|
|
|
|
2009-08-26 06:02:44 +08:00
|
|
|
Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner,
|
2009-08-29 04:31:08 +08:00
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2009-05-12 07:53:27 +08:00
|
|
|
TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
|
2010-02-17 03:28:15 +08:00
|
|
|
if (D->isInvalidDecl())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-02-17 03:28:15 +08:00
|
|
|
|
2009-03-18 05:15:40 +08:00
|
|
|
return Instantiator.Visit(D);
|
|
|
|
}
|
|
|
|
|
2009-08-20 09:44:21 +08:00
|
|
|
/// \brief Instantiates a nested template parameter list in the current
|
|
|
|
/// instantiation context.
|
|
|
|
///
|
|
|
|
/// \param L The parameter list to instantiate
|
|
|
|
///
|
|
|
|
/// \returns NULL if there was an error
|
|
|
|
TemplateParameterList *
|
2009-08-26 06:02:44 +08:00
|
|
|
TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) {
|
2009-08-20 09:44:21 +08:00
|
|
|
// Get errors for all the parameters before bailing out.
|
|
|
|
bool Invalid = false;
|
|
|
|
|
|
|
|
unsigned N = L->size();
|
2011-07-23 18:55:15 +08:00
|
|
|
typedef SmallVector<NamedDecl *, 8> ParamVector;
|
2009-08-20 09:44:21 +08:00
|
|
|
ParamVector Params;
|
|
|
|
Params.reserve(N);
|
|
|
|
for (TemplateParameterList::iterator PI = L->begin(), PE = L->end();
|
|
|
|
PI != PE; ++PI) {
|
2009-09-16 00:23:51 +08:00
|
|
|
NamedDecl *D = cast_or_null<NamedDecl>(Visit(*PI));
|
2009-08-20 09:44:21 +08:00
|
|
|
Params.push_back(D);
|
2009-11-12 03:13:48 +08:00
|
|
|
Invalid = Invalid || !D || D->isInvalidDecl();
|
2009-08-20 09:44:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up if we had an error.
|
2010-07-26 02:17:45 +08:00
|
|
|
if (Invalid)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-08-20 09:44:21 +08:00
|
|
|
|
|
|
|
TemplateParameterList *InstL
|
|
|
|
= TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(),
|
|
|
|
L->getLAngleLoc(), &Params.front(), N,
|
|
|
|
L->getRAngleLoc());
|
|
|
|
return InstL;
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-08-20 09:44:21 +08:00
|
|
|
|
2011-10-08 19:31:46 +08:00
|
|
|
/// \brief Instantiate the declaration of a class template partial
|
2009-10-29 08:04:11 +08:00
|
|
|
/// specialization.
|
|
|
|
///
|
|
|
|
/// \param ClassTemplate the (instantiated) class template that is partially
|
|
|
|
// specialized by the instantiation of \p PartialSpec.
|
|
|
|
///
|
2011-10-08 19:31:46 +08:00
|
|
|
/// \param PartialSpec the (uninstantiated) class template partial
|
2009-10-29 08:04:11 +08:00
|
|
|
/// specialization that we are instantiating.
|
|
|
|
///
|
2010-11-11 03:44:59 +08:00
|
|
|
/// \returns The instantiated partial specialization, if successful; otherwise,
|
|
|
|
/// NULL to indicate an error.
|
|
|
|
ClassTemplatePartialSpecializationDecl *
|
2009-10-29 08:04:11 +08:00
|
|
|
TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
|
|
|
|
ClassTemplateDecl *ClassTemplate,
|
|
|
|
ClassTemplatePartialSpecializationDecl *PartialSpec) {
|
2009-11-01 01:21:17 +08:00
|
|
|
// Create a local instantiation scope for this class template partial
|
|
|
|
// specialization, which will contain the instantiations of the template
|
|
|
|
// parameters.
|
2010-08-25 13:32:35 +08:00
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Substitute into the template parameters of the class template partial
|
|
|
|
// specialization.
|
|
|
|
TemplateParameterList *TempParams = PartialSpec->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Substitute into the template arguments of the class template partial
|
|
|
|
// specialization.
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *TemplArgInfo
|
|
|
|
= PartialSpec->getTemplateArgsAsWritten();
|
|
|
|
TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc,
|
|
|
|
TemplArgInfo->RAngleLoc);
|
|
|
|
if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
|
|
|
|
TemplArgInfo->NumTemplateArgs,
|
2010-12-23 05:19:48 +08:00
|
|
|
InstTemplateArgs, TemplateArgs))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Check that the template argument list is well-formed for this
|
|
|
|
// class template.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateArgument, 4> Converted;
|
2011-10-08 19:31:46 +08:00
|
|
|
if (SemaRef.CheckTemplateArgumentList(ClassTemplate,
|
2009-10-29 08:04:11 +08:00
|
|
|
PartialSpec->getLocation(),
|
2011-10-08 19:31:46 +08:00
|
|
|
InstTemplateArgs,
|
2009-10-29 08:04:11 +08:00
|
|
|
false,
|
|
|
|
Converted))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-10-29 08:04:11 +08:00
|
|
|
|
|
|
|
// Figure out where to insert this class template partial specialization
|
|
|
|
// in the member template's set of class template partial specializations.
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2009-10-29 08:04:11 +08:00
|
|
|
ClassTemplateSpecializationDecl *PrevDecl
|
2014-06-26 12:58:53 +08:00
|
|
|
= ClassTemplate->findPartialSpecialization(Converted, InsertPos);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Build the canonical type that describes the converted template
|
|
|
|
// arguments of the class template partial specialization.
|
2011-10-08 19:31:46 +08:00
|
|
|
QualType CanonType
|
2009-10-29 08:04:11 +08:00
|
|
|
= SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
|
2010-11-08 07:05:16 +08:00
|
|
|
Converted.data(),
|
|
|
|
Converted.size());
|
2009-10-29 08:04:11 +08:00
|
|
|
|
|
|
|
// Build the fully-sugared type for this class template
|
|
|
|
// specialization as the user wrote in the specialization
|
|
|
|
// itself. This means that we'll pretty-print the type retrieved
|
|
|
|
// from the specialization's declaration the way that the user
|
|
|
|
// actually wrote the specialization, rather than formatting the
|
|
|
|
// name based on the "canonical" representation used to store the
|
|
|
|
// template arguments in the specialization.
|
2010-03-10 11:28:59 +08:00
|
|
|
TypeSourceInfo *WrittenTy
|
|
|
|
= SemaRef.Context.getTemplateSpecializationTypeInfo(
|
|
|
|
TemplateName(ClassTemplate),
|
|
|
|
PartialSpec->getLocation(),
|
2009-11-23 09:53:49 +08:00
|
|
|
InstTemplateArgs,
|
2009-10-29 08:04:11 +08:00
|
|
|
CanonType);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
if (PrevDecl) {
|
|
|
|
// We've already seen a partial specialization with the same template
|
|
|
|
// parameters and template arguments. This can happen, for example, when
|
|
|
|
// substituting the outer template arguments ends up causing two
|
|
|
|
// class template partial specializations of a member class template
|
|
|
|
// to have identical forms, e.g.,
|
|
|
|
//
|
|
|
|
// template<typename T, typename U>
|
|
|
|
// struct Outer {
|
|
|
|
// template<typename X, typename Y> struct Inner;
|
|
|
|
// template<typename Y> struct Inner<T, Y>;
|
|
|
|
// template<typename Y> struct Inner<U, Y>;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// Outer<int, int> outer; // error: the partial specializations of Inner
|
|
|
|
// // have the same signature.
|
|
|
|
SemaRef.Diag(PartialSpec->getLocation(), diag::err_partial_spec_redeclared)
|
2010-11-11 03:44:59 +08:00
|
|
|
<< WrittenTy->getType();
|
2009-10-29 08:04:11 +08:00
|
|
|
SemaRef.Diag(PrevDecl->getLocation(), diag::note_prev_partial_spec_here)
|
|
|
|
<< SemaRef.Context.getTypeDeclType(PrevDecl);
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-10-29 08:04:11 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Create the class template partial specialization declaration.
|
|
|
|
ClassTemplatePartialSpecializationDecl *InstPartialSpec
|
2011-10-08 19:31:46 +08:00
|
|
|
= ClassTemplatePartialSpecializationDecl::Create(SemaRef.Context,
|
2010-05-06 08:28:52 +08:00
|
|
|
PartialSpec->getTagKind(),
|
2011-10-08 19:31:46 +08:00
|
|
|
Owner,
|
2011-03-09 22:09:51 +08:00
|
|
|
PartialSpec->getLocStart(),
|
|
|
|
PartialSpec->getLocation(),
|
2009-10-29 08:04:11 +08:00
|
|
|
InstParams,
|
2011-10-08 19:31:46 +08:00
|
|
|
ClassTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
Converted.data(),
|
|
|
|
Converted.size(),
|
2009-11-23 09:53:49 +08:00
|
|
|
InstTemplateArgs,
|
2010-03-10 11:28:59 +08:00
|
|
|
CanonType,
|
2014-05-26 14:22:03 +08:00
|
|
|
nullptr);
|
2010-03-15 18:12:16 +08:00
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(PartialSpec, InstPartialSpec))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-03-15 18:12:16 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
InstPartialSpec->setInstantiatedFromMember(PartialSpec);
|
2010-05-20 01:02:24 +08:00
|
|
|
InstPartialSpec->setTypeAsWritten(WrittenTy);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
// Add this partial specialization to the set of class template partial
|
|
|
|
// specializations.
|
2014-05-26 14:22:03 +08:00
|
|
|
ClassTemplate->AddPartialSpecialization(InstPartialSpec,
|
|
|
|
/*InsertPos=*/nullptr);
|
2010-11-11 03:44:59 +08:00
|
|
|
return InstPartialSpec;
|
2009-10-29 08:04:11 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
/// \brief Instantiate the declaration of a variable template partial
|
|
|
|
/// specialization.
|
|
|
|
///
|
|
|
|
/// \param VarTemplate the (instantiated) variable template that is partially
|
|
|
|
/// specialized by the instantiation of \p PartialSpec.
|
|
|
|
///
|
|
|
|
/// \param PartialSpec the (uninstantiated) variable template partial
|
|
|
|
/// specialization that we are instantiating.
|
|
|
|
///
|
|
|
|
/// \returns The instantiated partial specialization, if successful; otherwise,
|
|
|
|
/// NULL to indicate an error.
|
|
|
|
VarTemplatePartialSpecializationDecl *
|
|
|
|
TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
|
|
|
|
VarTemplateDecl *VarTemplate,
|
|
|
|
VarTemplatePartialSpecializationDecl *PartialSpec) {
|
|
|
|
// Create a local instantiation scope for this variable template partial
|
|
|
|
// specialization, which will contain the instantiations of the template
|
|
|
|
// parameters.
|
|
|
|
LocalInstantiationScope Scope(SemaRef);
|
|
|
|
|
|
|
|
// Substitute into the template parameters of the variable template partial
|
|
|
|
// specialization.
|
|
|
|
TemplateParameterList *TempParams = PartialSpec->getTemplateParameters();
|
|
|
|
TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
|
|
|
|
if (!InstParams)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Substitute into the template arguments of the variable template partial
|
|
|
|
// specialization.
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *TemplArgInfo
|
|
|
|
= PartialSpec->getTemplateArgsAsWritten();
|
|
|
|
TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc,
|
|
|
|
TemplArgInfo->RAngleLoc);
|
|
|
|
if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
|
|
|
|
TemplArgInfo->NumTemplateArgs,
|
2013-08-06 09:03:05 +08:00
|
|
|
InstTemplateArgs, TemplateArgs))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Check that the template argument list is well-formed for this
|
|
|
|
// class template.
|
|
|
|
SmallVector<TemplateArgument, 4> Converted;
|
|
|
|
if (SemaRef.CheckTemplateArgumentList(VarTemplate, PartialSpec->getLocation(),
|
|
|
|
InstTemplateArgs, false, Converted))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Figure out where to insert this variable template partial specialization
|
|
|
|
// in the member template's set of variable template partial specializations.
|
2014-05-26 14:22:03 +08:00
|
|
|
void *InsertPos = nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
VarTemplateSpecializationDecl *PrevDecl =
|
2014-06-26 12:58:53 +08:00
|
|
|
VarTemplate->findPartialSpecialization(Converted, InsertPos);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Build the canonical type that describes the converted template
|
|
|
|
// arguments of the variable template partial specialization.
|
|
|
|
QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
|
|
|
|
TemplateName(VarTemplate), Converted.data(), Converted.size());
|
|
|
|
|
|
|
|
// Build the fully-sugared type for this variable template
|
|
|
|
// specialization as the user wrote in the specialization
|
|
|
|
// itself. This means that we'll pretty-print the type retrieved
|
|
|
|
// from the specialization's declaration the way that the user
|
|
|
|
// actually wrote the specialization, rather than formatting the
|
|
|
|
// name based on the "canonical" representation used to store the
|
|
|
|
// template arguments in the specialization.
|
|
|
|
TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo(
|
|
|
|
TemplateName(VarTemplate), PartialSpec->getLocation(), InstTemplateArgs,
|
|
|
|
CanonType);
|
|
|
|
|
|
|
|
if (PrevDecl) {
|
|
|
|
// We've already seen a partial specialization with the same template
|
|
|
|
// parameters and template arguments. This can happen, for example, when
|
|
|
|
// substituting the outer template arguments ends up causing two
|
|
|
|
// variable template partial specializations of a member variable template
|
|
|
|
// to have identical forms, e.g.,
|
|
|
|
//
|
|
|
|
// template<typename T, typename U>
|
|
|
|
// struct Outer {
|
|
|
|
// template<typename X, typename Y> pair<X,Y> p;
|
|
|
|
// template<typename Y> pair<T, Y> p;
|
|
|
|
// template<typename Y> pair<U, Y> p;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// Outer<int, int> outer; // error: the partial specializations of Inner
|
|
|
|
// // have the same signature.
|
|
|
|
SemaRef.Diag(PartialSpec->getLocation(),
|
|
|
|
diag::err_var_partial_spec_redeclared)
|
|
|
|
<< WrittenTy->getType();
|
|
|
|
SemaRef.Diag(PrevDecl->getLocation(),
|
|
|
|
diag::note_var_prev_partial_spec_here);
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do substitution on the type of the declaration
|
|
|
|
TypeSourceInfo *DI = SemaRef.SubstType(
|
|
|
|
PartialSpec->getTypeSourceInfo(), TemplateArgs,
|
|
|
|
PartialSpec->getTypeSpecStartLoc(), PartialSpec->getDeclName());
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
if (DI->getType()->isFunctionType()) {
|
|
|
|
SemaRef.Diag(PartialSpec->getLocation(),
|
|
|
|
diag::err_variable_instantiates_to_function)
|
|
|
|
<< PartialSpec->isStaticDataMember() << DI->getType();
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the variable template partial specialization declaration.
|
|
|
|
VarTemplatePartialSpecializationDecl *InstPartialSpec =
|
|
|
|
VarTemplatePartialSpecializationDecl::Create(
|
|
|
|
SemaRef.Context, Owner, PartialSpec->getInnerLocStart(),
|
|
|
|
PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(),
|
|
|
|
DI, PartialSpec->getStorageClass(), Converted.data(),
|
2013-08-23 07:27:37 +08:00
|
|
|
Converted.size(), InstTemplateArgs);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Substitute the nested name specifier, if any.
|
|
|
|
if (SubstQualifier(PartialSpec, InstPartialSpec))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
InstPartialSpec->setInstantiatedFromMember(PartialSpec);
|
|
|
|
InstPartialSpec->setTypeAsWritten(WrittenTy);
|
|
|
|
|
|
|
|
// Add this partial specialization to the set of variable template partial
|
|
|
|
// specializations. The instantiation of the initializer is not necessary.
|
2014-05-26 14:22:03 +08:00
|
|
|
VarTemplate->AddPartialSpecialization(InstPartialSpec, /*InsertPos=*/nullptr);
|
2013-08-22 08:28:27 +08:00
|
|
|
|
|
|
|
SemaRef.BuildVariableInstantiation(InstPartialSpec, PartialSpec, TemplateArgs,
|
2013-09-20 09:15:31 +08:00
|
|
|
LateAttrs, Owner, StartingScope);
|
2013-08-22 08:28:27 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
return InstPartialSpec;
|
|
|
|
}
|
|
|
|
|
2010-03-11 17:03:00 +08:00
|
|
|
TypeSourceInfo*
|
|
|
|
TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D,
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<ParmVarDecl *> &Params) {
|
2010-03-11 17:03:00 +08:00
|
|
|
TypeSourceInfo *OldTInfo = D->getTypeSourceInfo();
|
|
|
|
assert(OldTInfo && "substituting function without type source info");
|
|
|
|
assert(Params.empty() && "parameter vector is non-empty at start");
|
2014-05-26 14:22:03 +08:00
|
|
|
|
|
|
|
CXXRecordDecl *ThisContext = nullptr;
|
2012-04-16 15:05:22 +08:00
|
|
|
unsigned ThisTypeQuals = 0;
|
|
|
|
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
|
2013-06-07 10:33:37 +08:00
|
|
|
ThisContext = cast<CXXRecordDecl>(Owner);
|
2012-04-16 15:05:22 +08:00
|
|
|
ThisTypeQuals = Method->getTypeQualifiers();
|
|
|
|
}
|
|
|
|
|
2010-04-10 01:38:44 +08:00
|
|
|
TypeSourceInfo *NewTInfo
|
|
|
|
= SemaRef.SubstFunctionDeclType(OldTInfo, TemplateArgs,
|
|
|
|
D->getTypeSpecStartLoc(),
|
2012-04-16 15:05:22 +08:00
|
|
|
D->getDeclName(),
|
|
|
|
ThisContext, ThisTypeQuals);
|
2010-03-11 17:03:00 +08:00
|
|
|
if (!NewTInfo)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-03-24 08:38:23 +08:00
|
|
|
|
2013-08-01 05:00:18 +08:00
|
|
|
TypeLoc OldTL = OldTInfo->getTypeLoc().IgnoreParens();
|
|
|
|
if (FunctionProtoTypeLoc OldProtoLoc = OldTL.getAs<FunctionProtoTypeLoc>()) {
|
|
|
|
if (NewTInfo != OldTInfo) {
|
|
|
|
// Get parameters from the new type info.
|
2010-12-14 06:27:55 +08:00
|
|
|
TypeLoc NewTL = NewTInfo->getTypeLoc().IgnoreParens();
|
2013-02-19 06:06:02 +08:00
|
|
|
FunctionProtoTypeLoc NewProtoLoc = NewTL.castAs<FunctionProtoTypeLoc>();
|
2012-07-18 09:29:05 +08:00
|
|
|
unsigned NewIdx = 0;
|
2014-01-21 08:32:38 +08:00
|
|
|
for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
llvm-svn: 123000
2011-01-08 00:43:16 +08:00
|
|
|
OldIdx != NumOldParams; ++OldIdx) {
|
2014-01-21 08:32:38 +08:00
|
|
|
ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
|
2012-07-18 09:29:05 +08:00
|
|
|
LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
|
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> NumArgumentsInExpansion;
|
2012-07-18 09:29:05 +08:00
|
|
|
if (OldParam->isParameterPack())
|
|
|
|
NumArgumentsInExpansion =
|
|
|
|
SemaRef.getNumArgumentsInExpansion(OldParam->getType(),
|
|
|
|
TemplateArgs);
|
|
|
|
if (!NumArgumentsInExpansion) {
|
2011-10-08 19:31:46 +08:00
|
|
|
// Simple case: normal parameter, or a parameter pack that's
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
llvm-svn: 123000
2011-01-08 00:43:16 +08:00
|
|
|
// instantiated to a (still-dependent) parameter pack.
|
2014-01-21 08:32:38 +08:00
|
|
|
ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++);
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
llvm-svn: 123000
2011-01-08 00:43:16 +08:00
|
|
|
Params.push_back(NewParam);
|
2012-07-18 09:29:05 +08:00
|
|
|
Scope->InstantiatedLocal(OldParam, NewParam);
|
|
|
|
} else {
|
|
|
|
// Parameter pack expansion: make the instantiation an argument pack.
|
|
|
|
Scope->MakeInstantiatedLocalArgPack(OldParam);
|
|
|
|
for (unsigned I = 0; I != *NumArgumentsInExpansion; ++I) {
|
2014-01-21 08:32:38 +08:00
|
|
|
ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++);
|
2012-07-18 09:29:05 +08:00
|
|
|
Params.push_back(NewParam);
|
|
|
|
Scope->InstantiatedLocalPackArg(OldParam, NewParam);
|
|
|
|
}
|
Implement substitution of a function parameter pack for its set of
instantiated function parameters, enabling instantiation of arbitrary
pack expansions involving function parameter packs. At this point, we
can now correctly compile a simple, variadic print() example:
#include <iostream>
#include <string>
void print() {}
template<typename Head, typename ...Tail>
void print(const Head &head, const Tail &...tail) {
std::cout << head;
print(tail...);
}
int main() {
std::string hello = "Hello";
print(hello, ", world!", " ", 2011, '\n');
}
llvm-svn: 123000
2011-01-08 00:43:16 +08:00
|
|
|
}
|
2010-05-03 23:32:18 +08:00
|
|
|
}
|
2013-08-01 05:00:18 +08:00
|
|
|
} else {
|
|
|
|
// The function type itself was not dependent and therefore no
|
|
|
|
// substitution occurred. However, we still need to instantiate
|
|
|
|
// the function parameters themselves.
|
|
|
|
const FunctionProtoType *OldProto =
|
|
|
|
cast<FunctionProtoType>(OldProtoLoc.getType());
|
2014-01-21 08:32:38 +08:00
|
|
|
for (unsigned i = 0, i_end = OldProtoLoc.getNumParams(); i != i_end;
|
|
|
|
++i) {
|
|
|
|
ParmVarDecl *OldParam = OldProtoLoc.getParam(i);
|
2013-08-01 05:00:18 +08:00
|
|
|
if (!OldParam) {
|
|
|
|
Params.push_back(SemaRef.BuildParmVarDeclForTypedef(
|
2014-01-21 04:26:09 +08:00
|
|
|
D, D->getLocation(), OldProto->getParamType(i)));
|
2013-08-01 05:00:18 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-28 07:21:55 +08:00
|
|
|
ParmVarDecl *Parm =
|
2013-08-01 05:00:18 +08:00
|
|
|
cast_or_null<ParmVarDecl>(VisitParmVarDecl(OldParam));
|
2010-05-03 23:32:18 +08:00
|
|
|
if (!Parm)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-05-03 23:32:18 +08:00
|
|
|
Params.push_back(Parm);
|
|
|
|
}
|
Be sure to instantiate the parameters of a function, even when the
function's type is (strictly speaking) non-dependent. This ensures
that, e.g., default function arguments get instantiated properly.
And, since I couldn't resist, collapse the two implementations of
function-parameter instantiation into calls to a single, new function
(Sema::SubstParmVarDecl), since the two had nearly identical code (and
each had bugs the other didn't!). More importantly, factored out the
semantic analysis of a parameter declaration into
Sema::CheckParameter, which is called both by
Sema::ActOnParamDeclarator (when parameters are parsed) and when a
parameter is instantiated. Previously, we were missing some
Objective-C and address-space checks on instantiated function
parameters.
Fixes PR6733.
llvm-svn: 101029
2010-04-12 15:48:19 +08:00
|
|
|
}
|
2013-08-01 05:00:18 +08:00
|
|
|
} else {
|
|
|
|
// If the type of this function, after ignoring parentheses, is not
|
|
|
|
// *directly* a function type, then we're instantiating a function that
|
|
|
|
// was declared via a typedef or with attributes, e.g.,
|
|
|
|
//
|
|
|
|
// typedef int functype(int, int);
|
|
|
|
// functype func;
|
|
|
|
// int __cdecl meth(int, int);
|
|
|
|
//
|
|
|
|
// In this case, we'll just go instantiate the ParmVarDecls that we
|
|
|
|
// synthesized in the method declaration.
|
|
|
|
SmallVector<QualType, 4> ParamTypes;
|
|
|
|
if (SemaRef.SubstParmTypes(D->getLocation(), D->param_begin(),
|
|
|
|
D->getNumParams(), TemplateArgs, ParamTypes,
|
|
|
|
&Params))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
Be sure to instantiate the parameters of a function, even when the
function's type is (strictly speaking) non-dependent. This ensures
that, e.g., default function arguments get instantiated properly.
And, since I couldn't resist, collapse the two implementations of
function-parameter instantiation into calls to a single, new function
(Sema::SubstParmVarDecl), since the two had nearly identical code (and
each had bugs the other didn't!). More importantly, factored out the
semantic analysis of a parameter declaration into
Sema::CheckParameter, which is called both by
Sema::ActOnParamDeclarator (when parameters are parsed) and when a
parameter is instantiated. Previously, we were missing some
Objective-C and address-space checks on instantiated function
parameters.
Fixes PR6733.
llvm-svn: 101029
2010-04-12 15:48:19 +08:00
|
|
|
}
|
2013-08-01 05:00:18 +08:00
|
|
|
|
2010-03-11 17:03:00 +08:00
|
|
|
return NewTInfo;
|
2009-03-24 08:38:23 +08:00
|
|
|
}
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
/// Introduce the instantiated function parameters into the local
|
|
|
|
/// instantiation scope, and set the parameter names to those used
|
|
|
|
/// in the template.
|
|
|
|
static void addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function,
|
|
|
|
const FunctionDecl *PatternDecl,
|
|
|
|
LocalInstantiationScope &Scope,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
|
|
|
unsigned FParamIdx = 0;
|
|
|
|
for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
|
|
|
|
const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
|
|
|
|
if (!PatternParam->isParameterPack()) {
|
|
|
|
// Simple case: not a parameter pack.
|
|
|
|
assert(FParamIdx < Function->getNumParams());
|
|
|
|
ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
|
2014-03-13 08:28:45 +08:00
|
|
|
// If the parameter's type is not dependent, update it to match the type
|
|
|
|
// in the pattern. They can differ in top-level cv-qualifiers, and we want
|
|
|
|
// the pattern's type here. If the type is dependent, they can't differ,
|
|
|
|
// per core issue 1668.
|
|
|
|
// FIXME: Updating the type to work around this is at best fragile.
|
|
|
|
if (!PatternDecl->getType()->isDependentType())
|
|
|
|
FunctionParam->setType(PatternParam->getType());
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
FunctionParam->setDeclName(PatternParam->getDeclName());
|
|
|
|
Scope.InstantiatedLocal(PatternParam, FunctionParam);
|
|
|
|
++FParamIdx;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the parameter pack.
|
|
|
|
Scope.MakeInstantiatedLocalArgPack(PatternParam);
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> NumArgumentsInExpansion
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
= S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
|
2012-07-18 09:29:05 +08:00
|
|
|
assert(NumArgumentsInExpansion &&
|
|
|
|
"should only be called when all template arguments are known");
|
|
|
|
for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
|
2014-03-13 08:28:45 +08:00
|
|
|
if (!PatternDecl->getType()->isDependentType())
|
|
|
|
FunctionParam->setType(PatternParam->getType());
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
FunctionParam->setDeclName(PatternParam->getDeclName());
|
|
|
|
Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
|
|
|
|
++FParamIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InstantiateExceptionSpec(Sema &SemaRef, FunctionDecl *New,
|
|
|
|
const FunctionProtoType *Proto,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2012-04-19 08:08:28 +08:00
|
|
|
assert(Proto->getExceptionSpecType() != EST_Uninstantiated);
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
// C++11 [expr.prim.general]p3:
|
|
|
|
// If a declaration declares a member function or member function
|
|
|
|
// template of a class X, the expression this is a prvalue of type
|
|
|
|
// "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
|
|
|
|
// and the end of the function-definition, member-declarator, or
|
|
|
|
// declarator.
|
2014-05-26 14:22:03 +08:00
|
|
|
CXXRecordDecl *ThisContext = nullptr;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
unsigned ThisTypeQuals = 0;
|
|
|
|
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(New)) {
|
|
|
|
ThisContext = Method->getParent();
|
|
|
|
ThisTypeQuals = Method->getTypeQualifiers();
|
|
|
|
}
|
|
|
|
Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals,
|
2013-01-02 19:42:31 +08:00
|
|
|
SemaRef.getLangOpts().CPlusPlus11);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
// The function has an exception specification or a "noreturn"
|
|
|
|
// attribute. Substitute into each of the exception types.
|
|
|
|
SmallVector<QualType, 4> Exceptions;
|
|
|
|
for (unsigned I = 0, N = Proto->getNumExceptions(); I != N; ++I) {
|
|
|
|
// FIXME: Poor location information!
|
|
|
|
if (const PackExpansionType *PackExpansion
|
|
|
|
= Proto->getExceptionType(I)->getAs<PackExpansionType>()) {
|
|
|
|
// We have a pack expansion. Instantiate it.
|
|
|
|
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
|
|
|
|
SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
|
|
|
|
Unexpanded);
|
|
|
|
assert(!Unexpanded.empty() &&
|
|
|
|
"Pack expansion without parameter packs?");
|
|
|
|
|
|
|
|
bool Expand = false;
|
|
|
|
bool RetainExpansion = false;
|
2013-06-07 10:33:37 +08:00
|
|
|
Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
if (SemaRef.CheckParameterPacksForExpansion(New->getLocation(),
|
|
|
|
SourceRange(),
|
|
|
|
Unexpanded,
|
|
|
|
TemplateArgs,
|
|
|
|
Expand,
|
|
|
|
RetainExpansion,
|
|
|
|
NumExpansions))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!Expand) {
|
|
|
|
// We can't expand this pack expansion into separate arguments yet;
|
|
|
|
// just substitute into the pattern and create a new pack expansion
|
|
|
|
// type.
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
|
|
|
|
QualType T = SemaRef.SubstType(PackExpansion->getPattern(),
|
|
|
|
TemplateArgs,
|
|
|
|
New->getLocation(), New->getDeclName());
|
|
|
|
if (T.isNull())
|
|
|
|
break;
|
|
|
|
|
|
|
|
T = SemaRef.Context.getPackExpansionType(T, NumExpansions);
|
|
|
|
Exceptions.push_back(T);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Substitute into the pack expansion pattern for each template
|
|
|
|
bool Invalid = false;
|
|
|
|
for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
|
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, ArgIdx);
|
|
|
|
|
|
|
|
QualType T = SemaRef.SubstType(PackExpansion->getPattern(),
|
|
|
|
TemplateArgs,
|
|
|
|
New->getLocation(), New->getDeclName());
|
|
|
|
if (T.isNull()) {
|
|
|
|
Invalid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exceptions.push_back(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Invalid)
|
|
|
|
break;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QualType T
|
|
|
|
= SemaRef.SubstType(Proto->getExceptionType(I), TemplateArgs,
|
|
|
|
New->getLocation(), New->getDeclName());
|
|
|
|
if (T.isNull() ||
|
|
|
|
SemaRef.CheckSpecifiedExceptionType(T, New->getLocation()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Exceptions.push_back(T);
|
|
|
|
}
|
2014-05-26 14:22:03 +08:00
|
|
|
Expr *NoexceptExpr = nullptr;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
if (Expr *OldNoexceptExpr = Proto->getNoexceptExpr()) {
|
|
|
|
EnterExpressionEvaluationContext Unevaluated(SemaRef,
|
|
|
|
Sema::ConstantEvaluated);
|
|
|
|
ExprResult E = SemaRef.SubstExpr(OldNoexceptExpr, TemplateArgs);
|
|
|
|
if (E.isUsable())
|
|
|
|
E = SemaRef.CheckBooleanCondition(E.get(), E.get()->getLocStart());
|
|
|
|
|
|
|
|
if (E.isUsable()) {
|
2014-05-29 18:55:11 +08:00
|
|
|
NoexceptExpr = E.get();
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
if (!NoexceptExpr->isTypeDependent() &&
|
|
|
|
!NoexceptExpr->isValueDependent())
|
2012-05-05 06:38:52 +08:00
|
|
|
NoexceptExpr
|
|
|
|
= SemaRef.VerifyIntegerConstantExpression(NoexceptExpr,
|
2014-05-26 14:22:03 +08:00
|
|
|
nullptr, diag::err_noexcept_needs_constant_expression,
|
2014-05-29 18:55:11 +08:00
|
|
|
/*AllowFold*/ false).get();
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 05:47:22 +08:00
|
|
|
FunctionProtoType::ExtProtoInfo EPI;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
EPI.ExceptionSpecType = Proto->getExceptionSpecType();
|
|
|
|
EPI.NumExceptions = Exceptions.size();
|
|
|
|
EPI.Exceptions = Exceptions.data();
|
|
|
|
EPI.NoexceptExpr = NoexceptExpr;
|
|
|
|
|
2014-03-21 05:47:22 +08:00
|
|
|
SemaRef.UpdateExceptionSpec(New, EPI);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
|
|
|
|
FunctionDecl *Decl) {
|
2012-04-19 08:08:28 +08:00
|
|
|
const FunctionProtoType *Proto = Decl->getType()->castAs<FunctionProtoType>();
|
|
|
|
if (Proto->getExceptionSpecType() != EST_Uninstantiated)
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
InstantiatingTemplate Inst(*this, PointOfInstantiation, Decl,
|
|
|
|
InstantiatingTemplate::ExceptionSpecification());
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid()) {
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
// We hit the instantiation depth limit. Clear the exception specification
|
|
|
|
// so that our callers don't have to cope with EST_Uninstantiated.
|
2014-03-21 05:47:22 +08:00
|
|
|
FunctionProtoType::ExtProtoInfo EPI;
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
EPI.ExceptionSpecType = EST_None;
|
2014-03-21 05:47:22 +08:00
|
|
|
UpdateExceptionSpec(Decl, EPI);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return;
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
}
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
// Enter the scope of this instantiation. We don't use
|
|
|
|
// PushDeclContext because we don't have a scope.
|
|
|
|
Sema::ContextRAII savedContext(*this, Decl);
|
|
|
|
LocalInstantiationScope Scope(*this);
|
|
|
|
|
|
|
|
MultiLevelTemplateArgumentList TemplateArgs =
|
2014-05-26 14:22:03 +08:00
|
|
|
getTemplateInstantiationArgs(Decl, nullptr, /*RelativeToPrimary*/true);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
2012-04-19 08:08:28 +08:00
|
|
|
FunctionDecl *Template = Proto->getExceptionSpecTemplate();
|
|
|
|
addInstantiatedParametersToScope(*this, Decl, Template, Scope, TemplateArgs);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
2012-04-19 08:08:28 +08:00
|
|
|
::InstantiateExceptionSpec(*this, Decl,
|
|
|
|
Template->getType()->castAs<FunctionProtoType>(),
|
|
|
|
TemplateArgs);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// \brief Initializes the common fields of an instantiation function
|
2009-06-26 06:08:12 +08:00
|
|
|
/// declaration (New) from the corresponding fields of its template (Tmpl).
|
|
|
|
///
|
|
|
|
/// \returns true if there was an error
|
2009-09-09 23:08:12 +08:00
|
|
|
bool
|
|
|
|
TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
|
2009-06-26 06:08:12 +08:00
|
|
|
FunctionDecl *Tmpl) {
|
2012-07-17 02:50:45 +08:00
|
|
|
if (Tmpl->isDeleted())
|
2011-05-07 04:44:56 +08:00
|
|
|
New->setDeletedAsWritten();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-12-04 17:01:55 +08:00
|
|
|
// Forward the mangling number from the template to the instantiated decl.
|
|
|
|
SemaRef.Context.setManglingNumber(New,
|
|
|
|
SemaRef.Context.getManglingNumber(Tmpl));
|
|
|
|
|
2009-07-02 06:01:06 +08:00
|
|
|
// If we are performing substituting explicitly-specified template arguments
|
|
|
|
// or deduced template arguments into a function template and we reach this
|
|
|
|
// point, we are now past the point where SFINAE applies and have committed
|
2009-09-09 23:08:12 +08:00
|
|
|
// to keeping the new function template specialization. We therefore
|
|
|
|
// convert the active template instantiation for the function template
|
2009-07-02 06:01:06 +08:00
|
|
|
// into a template instantiation for this specific function template
|
|
|
|
// specialization, which is not a SFINAE context, so that we diagnose any
|
|
|
|
// further errors in the declaration itself.
|
|
|
|
typedef Sema::ActiveTemplateInstantiation ActiveInstType;
|
|
|
|
ActiveInstType &ActiveInst = SemaRef.ActiveTemplateInstantiations.back();
|
|
|
|
if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution ||
|
|
|
|
ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) {
|
2009-09-09 23:08:12 +08:00
|
|
|
if (FunctionTemplateDecl *FunTmpl
|
2012-11-16 16:40:59 +08:00
|
|
|
= dyn_cast<FunctionTemplateDecl>(ActiveInst.Entity)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(FunTmpl->getTemplatedDecl() == Tmpl &&
|
2009-07-02 06:01:06 +08:00
|
|
|
"Deduction from the wrong function template?");
|
2009-07-17 06:10:11 +08:00
|
|
|
(void) FunTmpl;
|
2009-07-02 06:01:06 +08:00
|
|
|
ActiveInst.Kind = ActiveInstType::TemplateInstantiation;
|
2012-11-16 16:40:59 +08:00
|
|
|
ActiveInst.Entity = New;
|
2009-07-02 06:01:06 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-09 01:45:32 +08:00
|
|
|
const FunctionProtoType *Proto = Tmpl->getType()->getAs<FunctionProtoType>();
|
|
|
|
assert(Proto && "Function template without prototype?");
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
if (Proto->hasExceptionSpec() || Proto->getNoReturnAttr()) {
|
2010-12-14 16:05:40 +08:00
|
|
|
FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
// DR1330: In C++11, defer instantiation of a non-trivial
|
|
|
|
// exception specification.
|
2013-01-02 19:42:31 +08:00
|
|
|
if (SemaRef.getLangOpts().CPlusPlus11 &&
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
EPI.ExceptionSpecType != EST_None &&
|
|
|
|
EPI.ExceptionSpecType != EST_DynamicNone &&
|
|
|
|
EPI.ExceptionSpecType != EST_BasicNoexcept) {
|
2012-04-19 08:08:28 +08:00
|
|
|
FunctionDecl *ExceptionSpecTemplate = Tmpl;
|
|
|
|
if (EPI.ExceptionSpecType == EST_Uninstantiated)
|
|
|
|
ExceptionSpecTemplate = EPI.ExceptionSpecTemplate;
|
2013-04-10 13:48:59 +08:00
|
|
|
ExceptionSpecificationType NewEST = EST_Uninstantiated;
|
|
|
|
if (EPI.ExceptionSpecType == EST_Unevaluated)
|
|
|
|
NewEST = EST_Unevaluated;
|
2012-04-19 08:08:28 +08:00
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
// Mark the function has having an uninstantiated exception specification.
|
|
|
|
const FunctionProtoType *NewProto
|
|
|
|
= New->getType()->getAs<FunctionProtoType>();
|
|
|
|
assert(NewProto && "Template instantiation without function prototype?");
|
|
|
|
EPI = NewProto->getExtProtoInfo();
|
2013-04-10 13:48:59 +08:00
|
|
|
EPI.ExceptionSpecType = NewEST;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
EPI.ExceptionSpecDecl = New;
|
2012-04-19 08:08:28 +08:00
|
|
|
EPI.ExceptionSpecTemplate = ExceptionSpecTemplate;
|
2013-06-11 04:51:09 +08:00
|
|
|
New->setType(SemaRef.Context.getFunctionType(
|
2014-01-26 00:55:45 +08:00
|
|
|
NewProto->getReturnType(), NewProto->getParamTypes(), EPI));
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
} else {
|
|
|
|
::InstantiateExceptionSpec(SemaRef, New, Proto, TemplateArgs);
|
|
|
|
}
|
2009-12-09 01:45:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-06 23:46:09 +08:00
|
|
|
// Get the definition. Leaves the variable unchanged if undefined.
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
const FunctionDecl *Definition = Tmpl;
|
2011-07-06 23:46:09 +08:00
|
|
|
Tmpl->isDefined(Definition);
|
|
|
|
|
2012-01-21 06:50:54 +08:00
|
|
|
SemaRef.InstantiateAttrs(TemplateArgs, Definition, New,
|
|
|
|
LateAttrs, StartingScope);
|
2010-06-16 01:05:35 +08:00
|
|
|
|
2009-06-26 06:08:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-24 08:38:23 +08:00
|
|
|
/// \brief Initializes common fields of an instantiated method
|
|
|
|
/// declaration (New) from the corresponding fields of its template
|
|
|
|
/// (Tmpl).
|
|
|
|
///
|
|
|
|
/// \returns true if there was an error
|
2009-09-09 23:08:12 +08:00
|
|
|
bool
|
|
|
|
TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New,
|
2009-03-24 08:38:23 +08:00
|
|
|
CXXMethodDecl *Tmpl) {
|
2009-06-26 06:08:12 +08:00
|
|
|
if (InitFunctionInstantiation(New, Tmpl))
|
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-24 08:38:23 +08:00
|
|
|
New->setAccess(Tmpl->getAccess());
|
2009-12-04 02:44:40 +08:00
|
|
|
if (Tmpl->isVirtualAsWritten())
|
2010-09-29 04:50:54 +08:00
|
|
|
New->setVirtualAsWritten(true);
|
2009-03-24 08:38:23 +08:00
|
|
|
|
|
|
|
// FIXME: New needs a pointer to Tmpl
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-14 04:28:22 +08:00
|
|
|
|
|
|
|
/// \brief Instantiate the definition of the given function from its
|
|
|
|
/// template.
|
|
|
|
///
|
2009-07-01 01:20:14 +08:00
|
|
|
/// \param PointOfInstantiation the point at which the instantiation was
|
|
|
|
/// required. Note that this is not precisely a "point of instantiation"
|
|
|
|
/// for the function, but it's close.
|
|
|
|
///
|
2009-05-14 04:28:22 +08:00
|
|
|
/// \param Function the already-instantiated declaration of a
|
2009-07-01 01:20:14 +08:00
|
|
|
/// function template specialization or member function of a class template
|
|
|
|
/// specialization.
|
|
|
|
///
|
|
|
|
/// \param Recursive if true, recursively instantiates any functions that
|
|
|
|
/// are required by this instantiation.
|
2009-10-15 22:05:49 +08:00
|
|
|
///
|
|
|
|
/// \param DefinitionRequired if true, then we are performing an explicit
|
|
|
|
/// instantiation where the body of the function is required. Complain if
|
|
|
|
/// there is no such body.
|
2009-05-19 01:01:57 +08:00
|
|
|
void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
|
2009-07-01 01:20:14 +08:00
|
|
|
FunctionDecl *Function,
|
2009-10-15 22:05:49 +08:00
|
|
|
bool Recursive,
|
|
|
|
bool DefinitionRequired) {
|
2011-05-07 04:44:56 +08:00
|
|
|
if (Function->isInvalidDecl() || Function->isDefined())
|
2009-05-15 07:26:13 +08:00
|
|
|
return;
|
|
|
|
|
2011-08-14 11:52:19 +08:00
|
|
|
// Never instantiate an explicit specialization except if it is a class scope
|
|
|
|
// explicit specialization.
|
|
|
|
if (Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
|
|
|
|
!Function->getClassScopeSpecializationPattern())
|
2009-10-08 15:24:58 +08:00
|
|
|
return;
|
2010-05-18 01:34:56 +08:00
|
|
|
|
2009-05-15 05:06:31 +08:00
|
|
|
// Find the function body that we'll be substituting.
|
2009-10-28 04:53:28 +08:00
|
|
|
const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern();
|
2011-05-28 04:00:14 +08:00
|
|
|
assert(PatternDecl && "instantiating a non-template");
|
|
|
|
|
|
|
|
Stmt *Pattern = PatternDecl->getBody(PatternDecl);
|
|
|
|
assert(PatternDecl && "template definition is not a template");
|
|
|
|
if (!Pattern) {
|
|
|
|
// Try to find a defaulted definition
|
|
|
|
PatternDecl->isDefined(PatternDecl);
|
2011-05-26 06:02:25 +08:00
|
|
|
}
|
2011-05-28 04:00:14 +08:00
|
|
|
assert(PatternDecl && "template definition is not a template");
|
2009-05-15 05:06:31 +08:00
|
|
|
|
2011-04-23 06:18:13 +08:00
|
|
|
// Postpone late parsed template instantiations.
|
2011-05-28 04:00:14 +08:00
|
|
|
if (PatternDecl->isLateTemplateParsed() &&
|
2011-05-12 11:51:24 +08:00
|
|
|
!LateTemplateParser) {
|
2011-04-23 06:18:13 +08:00
|
|
|
PendingInstantiations.push_back(
|
|
|
|
std::make_pair(Function, PointOfInstantiation));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-16 16:29:13 +08:00
|
|
|
// Call the LateTemplateParser callback if there is a need to late parse
|
2011-10-08 19:31:46 +08:00
|
|
|
// a templated function definition.
|
2011-05-28 04:00:14 +08:00
|
|
|
if (!Pattern && PatternDecl->isLateTemplateParsed() &&
|
2011-04-23 06:18:13 +08:00
|
|
|
LateTemplateParser) {
|
2013-08-08 05:41:30 +08:00
|
|
|
// FIXME: Optimize to allow individual templates to be deserialized.
|
|
|
|
if (PatternDecl->isFromASTFile())
|
|
|
|
ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap);
|
|
|
|
|
|
|
|
LateParsedTemplate *LPT = LateParsedTemplateMap.lookup(PatternDecl);
|
|
|
|
assert(LPT && "missing LateParsedTemplate");
|
|
|
|
LateTemplateParser(OpaqueParser, *LPT);
|
2011-04-23 06:18:13 +08:00
|
|
|
Pattern = PatternDecl->getBody(PatternDecl);
|
|
|
|
}
|
|
|
|
|
2011-05-28 04:00:14 +08:00
|
|
|
if (!Pattern && !PatternDecl->isDefaulted()) {
|
2009-10-15 22:05:49 +08:00
|
|
|
if (DefinitionRequired) {
|
|
|
|
if (Function->getPrimaryTemplate())
|
2011-10-08 19:31:46 +08:00
|
|
|
Diag(PointOfInstantiation,
|
2009-10-15 22:05:49 +08:00
|
|
|
diag::err_explicit_instantiation_undefined_func_template)
|
|
|
|
<< Function->getPrimaryTemplate();
|
|
|
|
else
|
2011-10-08 19:31:46 +08:00
|
|
|
Diag(PointOfInstantiation,
|
2009-10-15 22:05:49 +08:00
|
|
|
diag::err_explicit_instantiation_undefined_member)
|
|
|
|
<< 1 << Function->getDeclName() << Function->getDeclContext();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-15 22:05:49 +08:00
|
|
|
if (PatternDecl)
|
2011-10-08 19:31:46 +08:00
|
|
|
Diag(PatternDecl->getLocation(),
|
2009-10-15 22:05:49 +08:00
|
|
|
diag::note_explicit_instantiation_here);
|
2010-05-18 01:57:54 +08:00
|
|
|
Function->setInvalidDecl();
|
2010-08-25 16:27:02 +08:00
|
|
|
} else if (Function->getTemplateSpecializationKind()
|
|
|
|
== TSK_ExplicitInstantiationDefinition) {
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.push_back(
|
2010-08-25 16:27:02 +08:00
|
|
|
std::make_pair(Function, PointOfInstantiation));
|
2009-10-15 22:05:49 +08:00
|
|
|
}
|
2010-08-25 16:27:02 +08:00
|
|
|
|
2009-05-15 05:06:31 +08:00
|
|
|
return;
|
2009-10-15 22:05:49 +08:00
|
|
|
}
|
2009-05-15 05:06:31 +08:00
|
|
|
|
2013-05-04 15:00:32 +08:00
|
|
|
// C++1y [temp.explicit]p10:
|
|
|
|
// Except for inline functions, declarations with types deduced from their
|
|
|
|
// initializer or return value, and class template specializations, other
|
|
|
|
// explicit instantiation declarations have the effect of suppressing the
|
|
|
|
// implicit instantiation of the entity to which they refer.
|
2014-01-26 00:55:45 +08:00
|
|
|
if (Function->getTemplateSpecializationKind() ==
|
|
|
|
TSK_ExplicitInstantiationDeclaration &&
|
2013-05-04 15:00:32 +08:00
|
|
|
!PatternDecl->isInlined() &&
|
2014-01-26 00:55:45 +08:00
|
|
|
!PatternDecl->getReturnType()->getContainedAutoType())
|
2009-09-05 06:48:11 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-29 11:15:31 +08:00
|
|
|
if (PatternDecl->isInlined()) {
|
|
|
|
// Function, and all later redeclarations of it (from imported modules,
|
|
|
|
// for instance), are now implicitly inline.
|
|
|
|
for (auto *D = Function->getMostRecentDecl(); /**/;
|
|
|
|
D = D->getPreviousDecl()) {
|
|
|
|
D->setImplicitlyInline();
|
|
|
|
if (D == Function)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 08:08:28 +08:00
|
|
|
|
2009-05-19 01:01:57 +08:00
|
|
|
InstantiatingTemplate Inst(*this, PointOfInstantiation, Function);
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid())
|
2011-10-08 19:31:46 +08:00
|
|
|
return;
|
|
|
|
|
2011-11-18 16:08:52 +08:00
|
|
|
// Copy the inner loc start from the pattern.
|
|
|
|
Function->setInnerLocStart(PatternDecl->getInnerLocStart());
|
|
|
|
|
2009-07-01 01:20:14 +08:00
|
|
|
// If we're performing recursive template instantiation, create our own
|
|
|
|
// queue of pending implicit instantiations that we will instantiate later,
|
|
|
|
// while we're still within our own instantiation context.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<VTableUse, 16> SavedVTableUses;
|
2010-08-25 16:44:16 +08:00
|
|
|
std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
|
2013-11-28 06:57:44 +08:00
|
|
|
SavePendingLocalImplicitInstantiationsRAII
|
|
|
|
SavedPendingLocalImplicitInstantiations(*this);
|
2010-11-25 08:35:20 +08:00
|
|
|
if (Recursive) {
|
|
|
|
VTableUses.swap(SavedVTableUses);
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
2010-11-25 08:35:20 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-08 19:31:46 +08:00
|
|
|
EnterExpressionEvaluationContext EvalContext(*this,
|
2010-08-27 07:41:50 +08:00
|
|
|
Sema::PotentiallyEvaluated);
|
2009-05-16 01:59:04 +08:00
|
|
|
|
2009-05-15 07:26:13 +08:00
|
|
|
// Introduce a new scope where local variable instantiations will be
|
2010-01-17 06:29:39 +08:00
|
|
|
// recorded, unless we're actually a member function within a local
|
|
|
|
// class, in which case we need to merge our results with the parent
|
|
|
|
// scope (of the enclosing function).
|
|
|
|
bool MergeWithParentScope = false;
|
|
|
|
if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Function->getDeclContext()))
|
|
|
|
MergeWithParentScope = Rec->isLocalClass();
|
|
|
|
|
|
|
|
LocalInstantiationScope Scope(*this, MergeWithParentScope);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
if (PatternDecl->isDefaulted())
|
|
|
|
SetDeclDefaulted(Function, PatternDecl->getLocation());
|
|
|
|
else {
|
2014-05-26 14:22:03 +08:00
|
|
|
ActOnStartOfFunctionDef(nullptr, Function);
|
2012-03-13 14:56:52 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
// Enter the scope of this instantiation. We don't use
|
|
|
|
// PushDeclContext because we don't have a scope.
|
|
|
|
Sema::ContextRAII savedContext(*this, Function);
|
2012-03-13 14:56:52 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
MultiLevelTemplateArgumentList TemplateArgs =
|
2014-05-26 14:22:03 +08:00
|
|
|
getTemplateInstantiationArgs(Function, nullptr, false, PatternDecl);
|
2009-05-15 07:26:13 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
addInstantiatedParametersToScope(*this, Function, PatternDecl, Scope,
|
|
|
|
TemplateArgs);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-05-24 07:14:04 +08:00
|
|
|
// If this is a constructor, instantiate the member initializers.
|
|
|
|
if (const CXXConstructorDecl *Ctor =
|
|
|
|
dyn_cast<CXXConstructorDecl>(PatternDecl)) {
|
|
|
|
InstantiateMemInitializers(cast<CXXConstructorDecl>(Function), Ctor,
|
|
|
|
TemplateArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate the function body.
|
|
|
|
StmtResult Body = SubstStmt(Pattern, TemplateArgs);
|
|
|
|
|
|
|
|
if (Body.isInvalid())
|
|
|
|
Function->setInvalidDecl();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-05-24 07:14:04 +08:00
|
|
|
ActOnFinishFunctionBody(Function, Body.get(),
|
|
|
|
/*IsInstantiation=*/true);
|
2009-05-15 08:01:03 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
PerformDependentDiagnostics(PatternDecl, TemplateArgs);
|
2010-03-24 13:22:00 +08:00
|
|
|
|
2014-03-23 07:33:22 +08:00
|
|
|
if (auto *Listener = getASTMutationListener())
|
|
|
|
Listener->FunctionDefinitionInstantiated(Function);
|
2014-03-22 09:43:32 +08:00
|
|
|
|
2012-12-11 09:14:52 +08:00
|
|
|
savedContext.pop();
|
|
|
|
}
|
2009-05-27 04:50:29 +08:00
|
|
|
|
|
|
|
DeclGroupRef DG(Function);
|
|
|
|
Consumer.HandleTopLevelDecl(DG);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-17 06:29:39 +08:00
|
|
|
// This class may have local implicit instantiations that need to be
|
|
|
|
// instantiation within this scope.
|
2010-08-25 16:44:16 +08:00
|
|
|
PerformPendingInstantiations(/*LocalOnly=*/true);
|
2010-01-17 06:29:39 +08:00
|
|
|
Scope.Exit();
|
|
|
|
|
2009-07-01 01:20:14 +08:00
|
|
|
if (Recursive) {
|
2010-11-25 08:35:20 +08:00
|
|
|
// Define any pending vtables.
|
|
|
|
DefineUsedVTables();
|
|
|
|
|
2009-07-01 01:20:14 +08:00
|
|
|
// Instantiate any pending implicit instantiations found during the
|
2009-09-09 23:08:12 +08:00
|
|
|
// instantiation of this template.
|
2010-08-25 16:44:16 +08:00
|
|
|
PerformPendingInstantiations();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-11-25 08:35:20 +08:00
|
|
|
// Restore the set of pending vtables.
|
2011-05-31 15:58:42 +08:00
|
|
|
assert(VTableUses.empty() &&
|
|
|
|
"VTableUses should be empty before it is discarded.");
|
2010-11-25 08:35:20 +08:00
|
|
|
VTableUses.swap(SavedVTableUses);
|
|
|
|
|
2009-07-01 01:20:14 +08:00
|
|
|
// Restore the set of pending implicit instantiations.
|
2011-05-31 15:58:42 +08:00
|
|
|
assert(PendingInstantiations.empty() &&
|
|
|
|
"PendingInstantiations should be empty before it is discarded.");
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
2009-07-01 01:20:14 +08:00
|
|
|
}
|
2009-05-14 04:28:22 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
|
|
|
|
VarTemplateDecl *VarTemplate, VarDecl *FromVar,
|
|
|
|
const TemplateArgumentList &TemplateArgList,
|
|
|
|
const TemplateArgumentListInfo &TemplateArgsInfo,
|
|
|
|
SmallVectorImpl<TemplateArgument> &Converted,
|
|
|
|
SourceLocation PointOfInstantiation, void *InsertPos,
|
|
|
|
LateInstantiatedAttrVec *LateAttrs,
|
|
|
|
LocalInstantiationScope *StartingScope) {
|
|
|
|
if (FromVar->isInvalidDecl())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
InstantiatingTemplate Inst(*this, PointOfInstantiation, FromVar);
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
MultiLevelTemplateArgumentList TemplateArgLists;
|
|
|
|
TemplateArgLists.addOuterTemplateArguments(&TemplateArgList);
|
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Instantiate the first declaration of the variable template: for a partial
|
|
|
|
// specialization of a static data member template, the first declaration may
|
|
|
|
// or may not be the declaration in the class; if it's in the class, we want
|
|
|
|
// to instantiate a member in the class (a declaration), and if it's outside,
|
|
|
|
// we want to instantiate a definition.
|
2014-01-17 07:39:20 +08:00
|
|
|
//
|
|
|
|
// If we're instantiating an explicitly-specialized member template or member
|
|
|
|
// partial specialization, don't do this. The member specialization completely
|
|
|
|
// replaces the original declaration in this case.
|
|
|
|
bool IsMemberSpec = false;
|
|
|
|
if (VarTemplatePartialSpecializationDecl *PartialSpec =
|
|
|
|
dyn_cast<VarTemplatePartialSpecializationDecl>(FromVar))
|
|
|
|
IsMemberSpec = PartialSpec->isMemberSpecialization();
|
|
|
|
else if (VarTemplateDecl *FromTemplate = FromVar->getDescribedVarTemplate())
|
|
|
|
IsMemberSpec = FromTemplate->isMemberSpecialization();
|
|
|
|
if (!IsMemberSpec)
|
|
|
|
FromVar = FromVar->getFirstDecl();
|
2013-09-28 04:14:12 +08:00
|
|
|
|
2013-09-30 21:29:01 +08:00
|
|
|
MultiLevelTemplateArgumentList MultiLevelList(TemplateArgList);
|
|
|
|
TemplateDeclInstantiator Instantiator(*this, FromVar->getDeclContext(),
|
|
|
|
MultiLevelList);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// TODO: Set LateAttrs and StartingScope ...
|
|
|
|
|
|
|
|
return cast_or_null<VarTemplateSpecializationDecl>(
|
|
|
|
Instantiator.VisitVarTemplateSpecializationDecl(
|
|
|
|
VarTemplate, FromVar, InsertPos, TemplateArgsInfo, Converted));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Instantiates a variable template specialization by completing it
|
|
|
|
/// with appropriate type information and initializer.
|
|
|
|
VarTemplateSpecializationDecl *Sema::CompleteVarTemplateSpecializationDecl(
|
|
|
|
VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
|
|
|
|
|
|
|
// Do substitution on the type of the declaration
|
|
|
|
TypeSourceInfo *DI =
|
2013-09-28 04:14:12 +08:00
|
|
|
SubstType(PatternDecl->getTypeSourceInfo(), TemplateArgs,
|
2013-08-06 09:03:05 +08:00
|
|
|
PatternDecl->getTypeSpecStartLoc(), PatternDecl->getDeclName());
|
|
|
|
if (!DI)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Update the type of this variable template specialization.
|
|
|
|
VarSpec->setType(DI->getType());
|
|
|
|
|
|
|
|
// Instantiate the initializer.
|
|
|
|
InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
|
|
|
|
|
|
|
|
return VarSpec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BuildVariableInstantiation - Used after a new variable has been created.
|
|
|
|
/// Sets basic variable data and decides whether to postpone the
|
|
|
|
/// variable instantiation.
|
|
|
|
void Sema::BuildVariableInstantiation(
|
|
|
|
VarDecl *NewVar, VarDecl *OldVar,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs,
|
2013-09-20 09:15:31 +08:00
|
|
|
LateInstantiatedAttrVec *LateAttrs, DeclContext *Owner,
|
|
|
|
LocalInstantiationScope *StartingScope,
|
2013-08-22 08:59:14 +08:00
|
|
|
bool InstantiatingVarTemplate) {
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
// If we are instantiating a local extern declaration, the
|
|
|
|
// instantiation belongs lexically to the containing function.
|
2013-08-06 09:03:05 +08:00
|
|
|
// If we are instantiating a static data member defined
|
|
|
|
// out-of-line, the instantiation will have the same lexical
|
|
|
|
// context (which will be a namespace scope) as the template.
|
2013-09-20 09:15:31 +08:00
|
|
|
if (OldVar->isLocalExternDecl()) {
|
|
|
|
NewVar->setLocalExternDecl();
|
|
|
|
NewVar->setLexicalDeclContext(Owner);
|
|
|
|
} else if (OldVar->isOutOfLine())
|
2013-08-06 09:03:05 +08:00
|
|
|
NewVar->setLexicalDeclContext(OldVar->getLexicalDeclContext());
|
|
|
|
NewVar->setTSCSpec(OldVar->getTSCSpec());
|
|
|
|
NewVar->setInitStyle(OldVar->getInitStyle());
|
|
|
|
NewVar->setCXXForRangeDecl(OldVar->isCXXForRangeDecl());
|
|
|
|
NewVar->setConstexpr(OldVar->isConstexpr());
|
2013-09-28 12:02:39 +08:00
|
|
|
NewVar->setInitCapture(OldVar->isInitCapture());
|
2013-08-14 02:18:50 +08:00
|
|
|
NewVar->setPreviousDeclInSameBlockScope(
|
|
|
|
OldVar->isPreviousDeclInSameBlockScope());
|
2013-08-06 09:03:05 +08:00
|
|
|
NewVar->setAccess(OldVar->getAccess());
|
|
|
|
|
2013-09-24 07:12:22 +08:00
|
|
|
if (!OldVar->isStaticDataMember()) {
|
2013-10-24 00:46:34 +08:00
|
|
|
if (OldVar->isUsed(false))
|
|
|
|
NewVar->setIsUsed();
|
2013-08-06 09:03:05 +08:00
|
|
|
NewVar->setReferenced(OldVar->isReferenced());
|
|
|
|
}
|
|
|
|
|
2013-09-18 07:57:10 +08:00
|
|
|
// See if the old variable had a type-specifier that defined an anonymous tag.
|
|
|
|
// If it did, mark the new variable as being the declarator for the new
|
|
|
|
// anonymous tag.
|
|
|
|
if (const TagType *OldTagType = OldVar->getType()->getAs<TagType>()) {
|
|
|
|
TagDecl *OldTag = OldTagType->getDecl();
|
|
|
|
if (OldTag->getDeclaratorForAnonDecl() == OldVar) {
|
|
|
|
TagDecl *NewTag = NewVar->getType()->castAs<TagType>()->getDecl();
|
|
|
|
assert(!NewTag->hasNameForLinkage() &&
|
|
|
|
!NewTag->hasDeclaratorForAnonDecl());
|
|
|
|
NewTag->setDeclaratorForAnonDecl(NewVar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope);
|
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
LookupResult Previous(
|
|
|
|
*this, NewVar->getDeclName(), NewVar->getLocation(),
|
|
|
|
NewVar->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage
|
|
|
|
: Sema::LookupOrdinaryName,
|
|
|
|
Sema::ForRedeclaration);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2013-11-27 16:34:14 +08:00
|
|
|
if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl() &&
|
|
|
|
(!OldVar->getPreviousDecl()->getDeclContext()->isDependentContext() ||
|
|
|
|
OldVar->getPreviousDecl()->getDeclContext()==OldVar->getDeclContext())) {
|
2013-08-14 02:18:50 +08:00
|
|
|
// We have a previous declaration. Use that one, so we merge with the
|
|
|
|
// right type.
|
|
|
|
if (NamedDecl *NewPrev = FindInstantiatedDecl(
|
|
|
|
NewVar->getLocation(), OldVar->getPreviousDecl(), TemplateArgs))
|
|
|
|
Previous.addDecl(NewPrev);
|
|
|
|
} else if (!isa<VarTemplateSpecializationDecl>(NewVar) &&
|
|
|
|
OldVar->hasLinkage())
|
2013-08-06 09:03:05 +08:00
|
|
|
LookupQualifiedName(Previous, NewVar->getDeclContext(), false);
|
2013-08-22 08:59:14 +08:00
|
|
|
CheckVariableDeclaration(NewVar, Previous);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2013-09-20 09:15:31 +08:00
|
|
|
if (!InstantiatingVarTemplate) {
|
|
|
|
NewVar->getLexicalDeclContext()->addHiddenDecl(NewVar);
|
|
|
|
if (!NewVar->isLocalExternDecl() || !NewVar->getPreviousDecl())
|
2013-08-06 09:03:05 +08:00
|
|
|
NewVar->getDeclContext()->makeDeclVisibleInContext(NewVar);
|
2013-09-20 09:15:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!OldVar->isOutOfLine()) {
|
2013-08-06 09:03:05 +08:00
|
|
|
if (NewVar->getDeclContext()->isFunctionOrMethod())
|
|
|
|
CurrentInstantiationScope->InstantiatedLocal(OldVar, NewVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link instantiations of static data members back to the template from
|
|
|
|
// which they were instantiated.
|
2013-08-22 08:59:14 +08:00
|
|
|
if (NewVar->isStaticDataMember() && !InstantiatingVarTemplate)
|
2013-08-06 09:03:05 +08:00
|
|
|
NewVar->setInstantiationOfStaticDataMember(OldVar,
|
|
|
|
TSK_ImplicitInstantiation);
|
|
|
|
|
2013-12-04 17:01:55 +08:00
|
|
|
// Forward the mangling number from the template to the instantiated decl.
|
|
|
|
Context.setManglingNumber(NewVar, Context.getManglingNumber(OldVar));
|
2014-03-05 16:57:59 +08:00
|
|
|
Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar));
|
2013-12-04 17:01:55 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Delay instantiation of the initializer for variable templates until a
|
2014-03-16 09:00:40 +08:00
|
|
|
// definition of the variable is needed. We need it right away if the type
|
|
|
|
// contains 'auto'.
|
|
|
|
if ((!isa<VarTemplateSpecializationDecl>(NewVar) &&
|
|
|
|
!InstantiatingVarTemplate) ||
|
|
|
|
NewVar->getType()->isUndeducedType())
|
2013-08-06 09:03:05 +08:00
|
|
|
InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
|
|
|
|
|
|
|
|
// Diagnose unused local variables with dependent types, where the diagnostic
|
|
|
|
// will have been deferred.
|
|
|
|
if (!NewVar->isInvalidDecl() &&
|
|
|
|
NewVar->getDeclContext()->isFunctionOrMethod() && !NewVar->isUsed() &&
|
|
|
|
OldVar->getType()->isDependentType())
|
|
|
|
DiagnoseUnusedDecl(NewVar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Instantiate the initializer of a variable.
|
|
|
|
void Sema::InstantiateVariableInitializer(
|
|
|
|
VarDecl *Var, VarDecl *OldVar,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
|
|
|
|
|
|
|
if (Var->getAnyInitializer())
|
|
|
|
// We already have an initializer in the class.
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (OldVar->getInit()) {
|
|
|
|
if (Var->isStaticDataMember() && !OldVar->isOutOfLine())
|
|
|
|
PushExpressionEvaluationContext(Sema::ConstantEvaluated, OldVar);
|
|
|
|
else
|
|
|
|
PushExpressionEvaluationContext(Sema::PotentiallyEvaluated, OldVar);
|
|
|
|
|
|
|
|
// Instantiate the initializer.
|
|
|
|
ExprResult Init =
|
|
|
|
SubstInitializer(OldVar->getInit(), TemplateArgs,
|
|
|
|
OldVar->getInitStyle() == VarDecl::CallInit);
|
|
|
|
if (!Init.isInvalid()) {
|
|
|
|
bool TypeMayContainAuto = true;
|
2014-06-10 08:55:51 +08:00
|
|
|
Expr *InitExpr = Init.get();
|
|
|
|
|
2014-07-11 04:53:43 +08:00
|
|
|
if (Var->hasAttr<DLLImportAttr>() &&
|
|
|
|
(!InitExpr ||
|
|
|
|
!InitExpr->isConstantInitializer(getASTContext(), false))) {
|
2014-06-10 08:55:51 +08:00
|
|
|
// Do not dynamically initialize dllimport variables.
|
|
|
|
} else if (InitExpr) {
|
2013-08-06 09:03:05 +08:00
|
|
|
bool DirectInit = OldVar->isDirectInit();
|
2014-06-10 08:55:51 +08:00
|
|
|
AddInitializerToDecl(Var, InitExpr, DirectInit, TypeMayContainAuto);
|
2013-08-06 09:03:05 +08:00
|
|
|
} else
|
|
|
|
ActOnUninitializedDecl(Var, TypeMayContainAuto);
|
|
|
|
} else {
|
|
|
|
// FIXME: Not too happy about invalidating the declaration
|
|
|
|
// because of a bogus initializer.
|
|
|
|
Var->setInvalidDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
PopExpressionEvaluationContext();
|
|
|
|
} else if ((!Var->isStaticDataMember() || Var->isOutOfLine()) &&
|
|
|
|
!Var->isCXXForRangeDecl())
|
|
|
|
ActOnUninitializedDecl(Var, false);
|
|
|
|
}
|
|
|
|
|
2009-05-14 04:28:22 +08:00
|
|
|
/// \brief Instantiate the definition of the given variable from its
|
|
|
|
/// template.
|
|
|
|
///
|
2009-07-25 04:34:43 +08:00
|
|
|
/// \param PointOfInstantiation the point at which the instantiation was
|
|
|
|
/// required. Note that this is not precisely a "point of instantiation"
|
|
|
|
/// for the function, but it's close.
|
|
|
|
///
|
|
|
|
/// \param Var the already-instantiated declaration of a static member
|
|
|
|
/// variable of a class template specialization.
|
|
|
|
///
|
|
|
|
/// \param Recursive if true, recursively instantiates any functions that
|
|
|
|
/// are required by this instantiation.
|
2009-10-15 22:05:49 +08:00
|
|
|
///
|
|
|
|
/// \param DefinitionRequired if true, then we are performing an explicit
|
|
|
|
/// instantiation where an out-of-line definition of the member variable
|
|
|
|
/// is required. Complain if there is no such definition.
|
2009-07-25 04:34:43 +08:00
|
|
|
void Sema::InstantiateStaticDataMemberDefinition(
|
|
|
|
SourceLocation PointOfInstantiation,
|
|
|
|
VarDecl *Var,
|
2009-10-15 22:05:49 +08:00
|
|
|
bool Recursive,
|
|
|
|
bool DefinitionRequired) {
|
2013-08-06 09:03:05 +08:00
|
|
|
InstantiateVariableDefinition(PointOfInstantiation, Var, Recursive,
|
|
|
|
DefinitionRequired);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
|
|
|
|
VarDecl *Var, bool Recursive,
|
|
|
|
bool DefinitionRequired) {
|
2009-07-25 04:34:43 +08:00
|
|
|
if (Var->isInvalidDecl())
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
VarTemplateSpecializationDecl *VarSpec =
|
|
|
|
dyn_cast<VarTemplateSpecializationDecl>(Var);
|
2014-05-26 14:22:03 +08:00
|
|
|
VarDecl *PatternDecl = nullptr, *Def = nullptr;
|
2013-09-28 04:14:12 +08:00
|
|
|
MultiLevelTemplateArgumentList TemplateArgs =
|
|
|
|
getTemplateInstantiationArgs(Var);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
if (VarSpec) {
|
2013-09-28 04:14:12 +08:00
|
|
|
// If this is a variable template specialization, make sure that it is
|
|
|
|
// non-dependent, then find its instantiation pattern.
|
2013-08-06 09:03:05 +08:00
|
|
|
bool InstantiationDependent = false;
|
|
|
|
assert(!TemplateSpecializationType::anyDependentTemplateArguments(
|
|
|
|
VarSpec->getTemplateArgsInfo(), InstantiationDependent) &&
|
|
|
|
"Only instantiate variable template specializations that are "
|
|
|
|
"not type-dependent");
|
2013-08-06 11:57:41 +08:00
|
|
|
(void)InstantiationDependent;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Find the variable initialization that we'll be substituting. If the
|
|
|
|
// pattern was instantiated from a member template, look back further to
|
|
|
|
// find the real pattern.
|
2013-08-06 09:03:05 +08:00
|
|
|
assert(VarSpec->getSpecializedTemplate() &&
|
|
|
|
"Specialization without specialized template?");
|
|
|
|
llvm::PointerUnion<VarTemplateDecl *,
|
|
|
|
VarTemplatePartialSpecializationDecl *> PatternPtr =
|
|
|
|
VarSpec->getSpecializedTemplateOrPartial();
|
2013-08-13 10:02:26 +08:00
|
|
|
if (PatternPtr.is<VarTemplatePartialSpecializationDecl *>()) {
|
2013-09-28 04:14:12 +08:00
|
|
|
VarTemplatePartialSpecializationDecl *Tmpl =
|
|
|
|
PatternPtr.get<VarTemplatePartialSpecializationDecl *>();
|
|
|
|
while (VarTemplatePartialSpecializationDecl *From =
|
|
|
|
Tmpl->getInstantiatedFromMember()) {
|
|
|
|
if (Tmpl->isMemberSpecialization())
|
|
|
|
break;
|
2013-08-13 10:02:26 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
Tmpl = From;
|
|
|
|
}
|
|
|
|
PatternDecl = Tmpl;
|
2013-08-13 10:02:26 +08:00
|
|
|
} else {
|
2013-09-28 04:14:12 +08:00
|
|
|
VarTemplateDecl *Tmpl = PatternPtr.get<VarTemplateDecl *>();
|
|
|
|
while (VarTemplateDecl *From =
|
|
|
|
Tmpl->getInstantiatedFromMemberTemplate()) {
|
|
|
|
if (Tmpl->isMemberSpecialization())
|
|
|
|
break;
|
|
|
|
|
|
|
|
Tmpl = From;
|
|
|
|
}
|
|
|
|
PatternDecl = Tmpl->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a static data member template, there might be an
|
|
|
|
// uninstantiated initializer on the declaration. If so, instantiate
|
|
|
|
// it now.
|
|
|
|
if (PatternDecl->isStaticDataMember() &&
|
2013-10-17 23:37:26 +08:00
|
|
|
(PatternDecl = PatternDecl->getFirstDecl())->hasInit() &&
|
2013-09-28 04:14:12 +08:00
|
|
|
!Var->hasInit()) {
|
|
|
|
// FIXME: Factor out the duplicated instantiation context setup/tear down
|
|
|
|
// code here.
|
|
|
|
InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid())
|
2013-09-28 04:14:12 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're performing recursive template instantiation, create our own
|
|
|
|
// queue of pending implicit instantiations that we will instantiate
|
|
|
|
// later, while we're still within our own instantiation context.
|
|
|
|
SmallVector<VTableUse, 16> SavedVTableUses;
|
|
|
|
std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
|
|
|
|
if (Recursive) {
|
|
|
|
VTableUses.swap(SavedVTableUses);
|
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalInstantiationScope Local(*this);
|
|
|
|
|
|
|
|
// Enter the scope of this instantiation. We don't use
|
|
|
|
// PushDeclContext because we don't have a scope.
|
|
|
|
ContextRAII PreviousContext(*this, Var->getDeclContext());
|
|
|
|
InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs);
|
|
|
|
PreviousContext.pop();
|
|
|
|
|
|
|
|
// FIXME: Need to inform the ASTConsumer that we instantiated the
|
|
|
|
// initializer?
|
|
|
|
|
|
|
|
// This variable may have local implicit instantiations that need to be
|
|
|
|
// instantiated within this scope.
|
|
|
|
PerformPendingInstantiations(/*LocalOnly=*/true);
|
|
|
|
|
|
|
|
Local.Exit();
|
|
|
|
|
|
|
|
if (Recursive) {
|
|
|
|
// Define any newly required vtables.
|
|
|
|
DefineUsedVTables();
|
|
|
|
|
|
|
|
// Instantiate any pending implicit instantiations found during the
|
|
|
|
// instantiation of this template.
|
|
|
|
PerformPendingInstantiations();
|
2013-08-13 10:02:26 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Restore the set of pending vtables.
|
|
|
|
assert(VTableUses.empty() &&
|
|
|
|
"VTableUses should be empty before it is discarded.");
|
|
|
|
VTableUses.swap(SavedVTableUses);
|
2013-08-13 10:02:26 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Restore the set of pending implicit instantiations.
|
|
|
|
assert(PendingInstantiations.empty() &&
|
|
|
|
"PendingInstantiations should be empty before it is discarded.");
|
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
|
|
|
}
|
2013-08-13 10:02:26 +08:00
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// Find actual definition
|
|
|
|
Def = PatternDecl->getDefinition(getASTContext());
|
|
|
|
} else {
|
|
|
|
// If this is a static data member, find its out-of-line definition.
|
|
|
|
assert(Var->isStaticDataMember() && "not a static data member?");
|
|
|
|
PatternDecl = Var->getInstantiatedFromStaticDataMember();
|
|
|
|
|
|
|
|
assert(PatternDecl && "data member was not instantiated from a template?");
|
|
|
|
assert(PatternDecl->isStaticDataMember() && "not a static data member?");
|
|
|
|
Def = PatternDecl->getOutOfLineDefinition();
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// If we don't have a definition of the variable template, we won't perform
|
|
|
|
// any instantiation. Rather, we rely on the user to instantiate this
|
|
|
|
// definition (or provide a specialization for it) in another translation
|
|
|
|
// unit.
|
|
|
|
if (!Def) {
|
2009-10-15 22:05:49 +08:00
|
|
|
if (DefinitionRequired) {
|
2013-09-28 04:14:12 +08:00
|
|
|
if (VarSpec)
|
2013-08-06 09:03:05 +08:00
|
|
|
Diag(PointOfInstantiation,
|
2013-09-28 04:14:12 +08:00
|
|
|
diag::err_explicit_instantiation_undefined_var_template) << Var;
|
|
|
|
else
|
2013-08-06 09:03:05 +08:00
|
|
|
Diag(PointOfInstantiation,
|
|
|
|
diag::err_explicit_instantiation_undefined_member)
|
2013-09-28 04:14:12 +08:00
|
|
|
<< 2 << Var->getDeclName() << Var->getDeclContext();
|
|
|
|
Diag(PatternDecl->getLocation(),
|
|
|
|
diag::note_explicit_instantiation_here);
|
2013-08-06 09:03:05 +08:00
|
|
|
if (VarSpec)
|
|
|
|
Var->setInvalidDecl();
|
2010-08-25 16:27:02 +08:00
|
|
|
} else if (Var->getTemplateSpecializationKind()
|
|
|
|
== TSK_ExplicitInstantiationDefinition) {
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.push_back(
|
2010-08-25 16:27:02 +08:00
|
|
|
std::make_pair(Var, PointOfInstantiation));
|
|
|
|
}
|
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-05 18:54:55 +08:00
|
|
|
TemplateSpecializationKind TSK = Var->getTemplateSpecializationKind();
|
|
|
|
|
2009-10-08 15:24:58 +08:00
|
|
|
// Never instantiate an explicit specialization.
|
2012-03-05 18:54:55 +08:00
|
|
|
if (TSK == TSK_ExplicitSpecialization)
|
2009-10-08 15:24:58 +08:00
|
|
|
return;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
// C++11 [temp.explicit]p10:
|
|
|
|
// Except for inline functions, [...] explicit instantiation declarations
|
|
|
|
// have the effect of suppressing the implicit instantiation of the entity
|
|
|
|
// to which they refer.
|
2012-03-05 18:54:55 +08:00
|
|
|
if (TSK == TSK_ExplicitInstantiationDeclaration)
|
2009-10-08 15:24:58 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-02-24 08:05:01 +08:00
|
|
|
// Make sure to pass the instantiated variable to the consumer at the end.
|
|
|
|
struct PassToConsumerRAII {
|
|
|
|
ASTConsumer &Consumer;
|
|
|
|
VarDecl *Var;
|
|
|
|
|
|
|
|
PassToConsumerRAII(ASTConsumer &Consumer, VarDecl *Var)
|
|
|
|
: Consumer(Consumer), Var(Var) { }
|
|
|
|
|
|
|
|
~PassToConsumerRAII() {
|
2013-09-28 04:14:12 +08:00
|
|
|
Consumer.HandleCXXStaticMemberVarInstantiation(Var);
|
2013-02-24 08:05:01 +08:00
|
|
|
}
|
|
|
|
} PassToConsumerRAII(Consumer, Var);
|
2012-03-08 23:51:03 +08:00
|
|
|
|
2013-09-28 04:14:12 +08:00
|
|
|
// If we already have a definition, we're done.
|
|
|
|
if (VarDecl *Def = Var->getDefinition()) {
|
|
|
|
// We may be explicitly instantiating something we've already implicitly
|
|
|
|
// instantiated.
|
|
|
|
Def->setTemplateSpecializationKind(Var->getTemplateSpecializationKind(),
|
|
|
|
PointOfInstantiation);
|
|
|
|
return;
|
2012-04-04 10:38:36 +08:00
|
|
|
}
|
2011-06-03 11:35:07 +08:00
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
|
2013-10-08 16:09:04 +08:00
|
|
|
if (Inst.isInvalid())
|
2009-07-25 04:34:43 +08:00
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
// If we're performing recursive template instantiation, create our own
|
|
|
|
// queue of pending implicit instantiations that we will instantiate later,
|
|
|
|
// while we're still within our own instantiation context.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<VTableUse, 16> SavedVTableUses;
|
2010-08-25 16:44:16 +08:00
|
|
|
std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
|
2013-11-28 06:57:44 +08:00
|
|
|
SavePendingLocalImplicitInstantiationsRAII
|
|
|
|
SavedPendingLocalImplicitInstantiations(*this);
|
2011-05-31 15:58:42 +08:00
|
|
|
if (Recursive) {
|
|
|
|
VTableUses.swap(SavedVTableUses);
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
2011-05-31 15:58:42 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
// Enter the scope of this instantiation. We don't use
|
|
|
|
// PushDeclContext because we don't have a scope.
|
2013-08-06 09:03:05 +08:00
|
|
|
ContextRAII PreviousContext(*this, Var->getDeclContext());
|
2012-02-17 05:36:18 +08:00
|
|
|
LocalInstantiationScope Local(*this);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2009-10-15 05:29:40 +08:00
|
|
|
VarDecl *OldVar = Var;
|
2013-08-06 09:03:05 +08:00
|
|
|
if (!VarSpec)
|
|
|
|
Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(),
|
2013-09-28 04:14:12 +08:00
|
|
|
TemplateArgs));
|
|
|
|
else if (Var->isStaticDataMember() &&
|
|
|
|
Var->getLexicalDeclContext()->isRecord()) {
|
|
|
|
// We need to instantiate the definition of a static data member template,
|
|
|
|
// and all we have is the in-class declaration of it. Instantiate a separate
|
|
|
|
// declaration of the definition.
|
|
|
|
TemplateDeclInstantiator Instantiator(*this, Var->getDeclContext(),
|
|
|
|
TemplateArgs);
|
|
|
|
Var = cast_or_null<VarDecl>(Instantiator.VisitVarTemplateSpecializationDecl(
|
2014-05-26 14:22:03 +08:00
|
|
|
VarSpec->getSpecializedTemplate(), Def, nullptr,
|
2013-09-28 04:14:12 +08:00
|
|
|
VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray()));
|
|
|
|
if (Var) {
|
|
|
|
llvm::PointerUnion<VarTemplateDecl *,
|
|
|
|
VarTemplatePartialSpecializationDecl *> PatternPtr =
|
|
|
|
VarSpec->getSpecializedTemplateOrPartial();
|
|
|
|
if (VarTemplatePartialSpecializationDecl *Partial =
|
|
|
|
PatternPtr.dyn_cast<VarTemplatePartialSpecializationDecl *>())
|
|
|
|
cast<VarTemplateSpecializationDecl>(Var)->setInstantiationOf(
|
|
|
|
Partial, &VarSpec->getTemplateInstantiationArgs());
|
|
|
|
|
|
|
|
// Merge the definition with the declaration.
|
|
|
|
LookupResult R(*this, Var->getDeclName(), Var->getLocation(),
|
|
|
|
LookupOrdinaryName, ForRedeclaration);
|
|
|
|
R.addDecl(OldVar);
|
|
|
|
MergeVarDecl(Var, R);
|
|
|
|
|
|
|
|
// Attach the initializer.
|
|
|
|
InstantiateVariableInitializer(Var, Def, TemplateArgs);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
// Complete the existing variable's definition with an appropriately
|
|
|
|
// substituted type and initializer.
|
|
|
|
Var = CompleteVarTemplateSpecializationDecl(VarSpec, Def, TemplateArgs);
|
2011-02-15 04:37:25 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
PreviousContext.pop();
|
2009-07-25 04:34:43 +08:00
|
|
|
|
|
|
|
if (Var) {
|
2013-08-06 09:03:05 +08:00
|
|
|
PassToConsumerRAII.Var = Var;
|
2013-09-28 04:14:12 +08:00
|
|
|
Var->setTemplateSpecializationKind(OldVar->getTemplateSpecializationKind(),
|
|
|
|
OldVar->getPointOfInstantiation());
|
2009-07-25 04:34:43 +08:00
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// This variable may have local implicit instantiations that need to be
|
|
|
|
// instantiated within this scope.
|
|
|
|
PerformPendingInstantiations(/*LocalOnly=*/true);
|
|
|
|
|
2012-02-17 05:36:18 +08:00
|
|
|
Local.Exit();
|
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
if (Recursive) {
|
2011-05-31 15:58:42 +08:00
|
|
|
// Define any newly required vtables.
|
|
|
|
DefineUsedVTables();
|
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
// Instantiate any pending implicit instantiations found during the
|
2009-09-09 23:08:12 +08:00
|
|
|
// instantiation of this template.
|
2010-08-25 16:44:16 +08:00
|
|
|
PerformPendingInstantiations();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-05-31 15:58:42 +08:00
|
|
|
// Restore the set of pending vtables.
|
|
|
|
assert(VTableUses.empty() &&
|
2013-08-06 09:03:05 +08:00
|
|
|
"VTableUses should be empty before it is discarded.");
|
2011-05-31 15:58:42 +08:00
|
|
|
VTableUses.swap(SavedVTableUses);
|
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
// Restore the set of pending implicit instantiations.
|
2011-05-31 15:58:42 +08:00
|
|
|
assert(PendingInstantiations.empty() &&
|
2013-08-06 09:03:05 +08:00
|
|
|
"PendingInstantiations should be empty before it is discarded.");
|
2010-08-25 16:44:16 +08:00
|
|
|
PendingInstantiations.swap(SavedPendingInstantiations);
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-05-14 04:28:22 +08:00
|
|
|
}
|
2009-05-27 13:35:12 +08:00
|
|
|
|
2009-08-29 13:16:22 +08:00
|
|
|
void
|
|
|
|
Sema::InstantiateMemInitializers(CXXConstructorDecl *New,
|
|
|
|
const CXXConstructorDecl *Tmpl,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-09 11:18:59 +08:00
|
|
|
SmallVector<CXXCtorInitializer*, 4> NewInits;
|
2012-09-25 08:23:05 +08:00
|
|
|
bool AnyErrors = Tmpl->isInvalidDecl();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-08-29 13:16:22 +08:00
|
|
|
// Instantiate all the initializers.
|
2014-03-14 01:34:31 +08:00
|
|
|
for (const auto *Init : Tmpl->inits()) {
|
2010-09-04 05:54:20 +08:00
|
|
|
// Only instantiate written initializers, let Sema re-construct implicit
|
|
|
|
// ones.
|
|
|
|
if (!Init->isWritten())
|
|
|
|
continue;
|
|
|
|
|
2011-01-04 08:32:56 +08:00
|
|
|
SourceLocation EllipsisLoc;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-04 08:32:56 +08:00
|
|
|
if (Init->isPackExpansion()) {
|
|
|
|
// This is a pack expansion. We should expand it now.
|
2011-11-01 09:16:03 +08:00
|
|
|
TypeLoc BaseTL = Init->getTypeSourceInfo()->getTypeLoc();
|
2013-06-13 08:45:47 +08:00
|
|
|
SmallVector<UnexpandedParameterPack, 4> Unexpanded;
|
2011-01-04 08:32:56 +08:00
|
|
|
collectUnexpandedParameterPacks(BaseTL, Unexpanded);
|
2013-06-13 08:45:47 +08:00
|
|
|
collectUnexpandedParameterPacks(Init->getInit(), Unexpanded);
|
2011-01-04 08:32:56 +08:00
|
|
|
bool ShouldExpand = false;
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
llvm-svn: 123163
2011-01-10 15:32:04 +08:00
|
|
|
bool RetainExpansion = false;
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<unsigned> NumExpansions;
|
2011-10-08 19:31:46 +08:00
|
|
|
if (CheckParameterPacksForExpansion(Init->getEllipsisLoc(),
|
2011-01-04 08:32:56 +08:00
|
|
|
BaseTL.getSourceRange(),
|
2011-09-22 10:34:54 +08:00
|
|
|
Unexpanded,
|
2011-10-08 19:31:46 +08:00
|
|
|
TemplateArgs, ShouldExpand,
|
Work-in-progress implementation of C++0x [temp.arg.explicit]p9, which
allows an argument pack determines via explicit specification of
function template arguments to be extended by further, deduced
arguments. For example:
template<class ... Types> void f(Types ... values);
void g() {
f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
}
There are a number of FIXMEs in here that indicate places where we
need to implement + test retained expansions, plus a number of other
places in deduction where we need to correctly cope with the
explicitly-specified arguments when deducing an argument
pack. Furthermore, it appears that the RecursiveASTVisitor needs to be
auditied; it's missing some traversals (especially w.r.t. template
arguments) that cause it not to find unexpanded parameter packs when
it should.
The good news, however, is that the tr1::tuple implementation now
works fully, and the tr1::bind example (both from N2080) is actually
working now.
llvm-svn: 123163
2011-01-10 15:32:04 +08:00
|
|
|
RetainExpansion,
|
2011-01-04 08:32:56 +08:00
|
|
|
NumExpansions)) {
|
|
|
|
AnyErrors = true;
|
|
|
|
New->setInvalidDecl();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(ShouldExpand && "Partial instantiation of base initializer?");
|
2011-10-08 19:31:46 +08:00
|
|
|
|
|
|
|
// Loop over all of the arguments in the argument pack(s),
|
2011-01-15 01:04:44 +08:00
|
|
|
for (unsigned I = 0; I != *NumExpansions; ++I) {
|
2011-01-04 08:32:56 +08:00
|
|
|
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
|
|
|
|
|
|
|
|
// Instantiate the initializer.
|
Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.
- ActOnCXXDirectInitializer, which was mostly duplication of
AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
int x = {1};
int x({1});
int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
always produces a ParenListExpr. Placed that so far failed to convert that
back to a ParenExpr containing comma operators have been fixed. I'm pretty
sure I could have made a crashing test case before this.
The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)
This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.
llvm-svn: 150318
2012-02-12 07:51:47 +08:00
|
|
|
ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs,
|
|
|
|
/*CXXDirectInit=*/true);
|
|
|
|
if (TempInit.isInvalid()) {
|
2011-01-04 08:32:56 +08:00
|
|
|
AnyErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate the base type.
|
2011-11-01 09:16:03 +08:00
|
|
|
TypeSourceInfo *BaseTInfo = SubstType(Init->getTypeSourceInfo(),
|
2011-10-08 19:31:46 +08:00
|
|
|
TemplateArgs,
|
|
|
|
Init->getSourceLocation(),
|
2011-01-04 08:32:56 +08:00
|
|
|
New->getDeclName());
|
|
|
|
if (!BaseTInfo) {
|
|
|
|
AnyErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the initializer.
|
2011-09-25 01:48:25 +08:00
|
|
|
MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(),
|
2014-05-29 18:55:11 +08:00
|
|
|
BaseTInfo, TempInit.get(),
|
2011-01-04 08:32:56 +08:00
|
|
|
New->getParent(),
|
|
|
|
SourceLocation());
|
|
|
|
if (NewInit.isInvalid()) {
|
|
|
|
AnyErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-04 08:32:56 +08:00
|
|
|
NewInits.push_back(NewInit.get());
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-01-04 08:32:56 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-03-02 15:38:39 +08:00
|
|
|
// Instantiate the initializer.
|
Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.
- ActOnCXXDirectInitializer, which was mostly duplication of
AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
int x = {1};
int x({1});
int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
always produces a ParenListExpr. Placed that so far failed to convert that
back to a ParenExpr containing comma operators have been fixed. I'm pretty
sure I could have made a crashing test case before this.
The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)
This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.
llvm-svn: 150318
2012-02-12 07:51:47 +08:00
|
|
|
ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs,
|
|
|
|
/*CXXDirectInit=*/true);
|
|
|
|
if (TempInit.isInvalid()) {
|
2010-03-02 15:38:39 +08:00
|
|
|
AnyErrors = true;
|
|
|
|
continue;
|
2009-08-29 13:16:22 +08:00
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-08-29 13:16:22 +08:00
|
|
|
MemInitResult NewInit;
|
2011-11-01 09:16:03 +08:00
|
|
|
if (Init->isDelegatingInitializer() || Init->isBaseInitializer()) {
|
|
|
|
TypeSourceInfo *TInfo = SubstType(Init->getTypeSourceInfo(),
|
|
|
|
TemplateArgs,
|
|
|
|
Init->getSourceLocation(),
|
|
|
|
New->getDeclName());
|
|
|
|
if (!TInfo) {
|
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
|
|
|
AnyErrors = true;
|
2009-12-03 06:36:29 +08:00
|
|
|
New->setInvalidDecl();
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-25 01:48:25 +08:00
|
|
|
|
2011-11-01 09:16:03 +08:00
|
|
|
if (Init->isBaseInitializer())
|
2014-05-29 18:55:11 +08:00
|
|
|
NewInit = BuildBaseInitializer(TInfo->getType(), TInfo, TempInit.get(),
|
2011-11-01 09:16:03 +08:00
|
|
|
New->getParent(), EllipsisLoc);
|
|
|
|
else
|
2014-05-29 18:55:11 +08:00
|
|
|
NewInit = BuildDelegatingInitializer(TInfo, TempInit.get(),
|
2011-11-01 09:16:03 +08:00
|
|
|
cast<CXXRecordDecl>(CurContext->getParent()));
|
2009-08-29 13:16:22 +08:00
|
|
|
} else if (Init->isMemberInitializer()) {
|
2011-03-05 03:46:35 +08:00
|
|
|
FieldDecl *Member = cast_or_null<FieldDecl>(FindInstantiatedDecl(
|
2010-12-04 17:14:42 +08:00
|
|
|
Init->getMemberLocation(),
|
|
|
|
Init->getMember(),
|
|
|
|
TemplateArgs));
|
2011-03-05 03:46:35 +08:00
|
|
|
if (!Member) {
|
|
|
|
AnyErrors = true;
|
|
|
|
New->setInvalidDecl();
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
NewInit = BuildMemberInitializer(Member, TempInit.get(),
|
2011-09-25 01:48:25 +08:00
|
|
|
Init->getSourceLocation());
|
2010-12-04 17:14:42 +08:00
|
|
|
} else if (Init->isIndirectMemberInitializer()) {
|
|
|
|
IndirectFieldDecl *IndirectMember =
|
2011-03-05 03:46:35 +08:00
|
|
|
cast_or_null<IndirectFieldDecl>(FindInstantiatedDecl(
|
2010-12-04 17:14:42 +08:00
|
|
|
Init->getMemberLocation(),
|
|
|
|
Init->getIndirectMember(), TemplateArgs));
|
|
|
|
|
2011-03-05 03:46:35 +08:00
|
|
|
if (!IndirectMember) {
|
|
|
|
AnyErrors = true;
|
|
|
|
New->setInvalidDecl();
|
2011-09-25 01:48:25 +08:00
|
|
|
continue;
|
2011-03-05 03:46:35 +08:00
|
|
|
}
|
2011-09-25 01:48:25 +08:00
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
NewInit = BuildMemberInitializer(IndirectMember, TempInit.get(),
|
2011-09-25 01:48:25 +08:00
|
|
|
Init->getSourceLocation());
|
2009-08-29 13:16:22 +08:00
|
|
|
}
|
|
|
|
|
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
|
|
|
if (NewInit.isInvalid()) {
|
|
|
|
AnyErrors = true;
|
2009-08-29 13:16:22 +08:00
|
|
|
New->setInvalidDecl();
|
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
|
|
|
} else {
|
2011-09-09 11:18:59 +08:00
|
|
|
NewInits.push_back(NewInit.get());
|
2009-08-29 13:16:22 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-29 13:16:22 +08:00
|
|
|
// Assign all the initializers to the new constructor.
|
2010-08-21 17:40:31 +08:00
|
|
|
ActOnMemInitializers(New,
|
2009-08-29 13:16:22 +08:00
|
|
|
/*FIXME: ColonLoc */
|
|
|
|
SourceLocation(),
|
2013-01-17 13:26:25 +08:00
|
|
|
NewInits,
|
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
|
|
|
AnyErrors);
|
2009-08-29 13:16:22 +08:00
|
|
|
}
|
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
// TODO: this could be templated if the various decl types used the
|
|
|
|
// same method name.
|
|
|
|
static bool isInstantiationOf(ClassTemplateDecl *Pattern,
|
|
|
|
ClassTemplateDecl *Instance) {
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
|
|
|
|
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMemberTemplate();
|
|
|
|
} while (Instance);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-28 14:34:35 +08:00
|
|
|
static bool isInstantiationOf(FunctionTemplateDecl *Pattern,
|
|
|
|
FunctionTemplateDecl *Instance) {
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-09-28 14:34:35 +08:00
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMemberTemplate();
|
|
|
|
} while (Instance);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-09-28 14:34:35 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-08 19:31:46 +08:00
|
|
|
static bool
|
2009-10-29 08:04:11 +08:00
|
|
|
isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern,
|
|
|
|
ClassTemplatePartialSpecializationDecl *Instance) {
|
2011-10-08 19:31:46 +08:00
|
|
|
Pattern
|
2009-10-29 08:04:11 +08:00
|
|
|
= cast<ClassTemplatePartialSpecializationDecl>(Pattern->getCanonicalDecl());
|
|
|
|
do {
|
|
|
|
Instance = cast<ClassTemplatePartialSpecializationDecl>(
|
|
|
|
Instance->getCanonicalDecl());
|
|
|
|
if (Pattern == Instance)
|
|
|
|
return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMember();
|
|
|
|
} while (Instance);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
static bool isInstantiationOf(CXXRecordDecl *Pattern,
|
|
|
|
CXXRecordDecl *Instance) {
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
|
|
|
|
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMemberClass();
|
|
|
|
} while (Instance);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInstantiationOf(FunctionDecl *Pattern,
|
|
|
|
FunctionDecl *Instance) {
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
|
|
|
|
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMemberFunction();
|
|
|
|
} while (Instance);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInstantiationOf(EnumDecl *Pattern,
|
|
|
|
EnumDecl *Instance) {
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
|
|
|
|
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromMemberEnum();
|
|
|
|
} while (Instance);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
static bool isInstantiationOf(UsingShadowDecl *Pattern,
|
|
|
|
UsingShadowDecl *Instance,
|
|
|
|
ASTContext &C) {
|
|
|
|
return C.getInstantiatedFromUsingShadowDecl(Instance) == Pattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInstantiationOf(UsingDecl *Pattern,
|
|
|
|
UsingDecl *Instance,
|
|
|
|
ASTContext &C) {
|
|
|
|
return C.getInstantiatedFromUsingDecl(Instance) == Pattern;
|
|
|
|
}
|
|
|
|
|
2009-11-18 10:36:19 +08:00
|
|
|
static bool isInstantiationOf(UnresolvedUsingValueDecl *Pattern,
|
|
|
|
UsingDecl *Instance,
|
|
|
|
ASTContext &C) {
|
2009-12-05 06:46:56 +08:00
|
|
|
return C.getInstantiatedFromUsingDecl(Instance) == Pattern;
|
2009-11-18 10:36:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInstantiationOf(UnresolvedUsingTypenameDecl *Pattern,
|
2009-08-30 03:37:28 +08:00
|
|
|
UsingDecl *Instance,
|
|
|
|
ASTContext &C) {
|
2009-12-05 06:46:56 +08:00
|
|
|
return C.getInstantiatedFromUsingDecl(Instance) == Pattern;
|
2009-08-30 03:37:28 +08:00
|
|
|
}
|
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
static bool isInstantiationOfStaticDataMember(VarDecl *Pattern,
|
|
|
|
VarDecl *Instance) {
|
|
|
|
assert(Instance->isStaticDataMember());
|
|
|
|
|
|
|
|
Pattern = Pattern->getCanonicalDecl();
|
|
|
|
|
|
|
|
do {
|
|
|
|
Instance = Instance->getCanonicalDecl();
|
|
|
|
if (Pattern == Instance) return true;
|
|
|
|
Instance = Instance->getInstantiatedFromStaticDataMember();
|
|
|
|
} while (Instance);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
// Other is the prospective instantiation
|
|
|
|
// D is the prospective pattern
|
2009-05-27 13:35:12 +08:00
|
|
|
static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
|
2009-08-30 03:37:28 +08:00
|
|
|
if (D->getKind() != Other->getKind()) {
|
2009-11-18 10:36:19 +08:00
|
|
|
if (UnresolvedUsingTypenameDecl *UUD
|
|
|
|
= dyn_cast<UnresolvedUsingTypenameDecl>(D)) {
|
|
|
|
if (UsingDecl *UD = dyn_cast<UsingDecl>(Other)) {
|
|
|
|
return isInstantiationOf(UUD, UD, Ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UnresolvedUsingValueDecl *UUD
|
|
|
|
= dyn_cast<UnresolvedUsingValueDecl>(D)) {
|
2009-08-30 03:37:28 +08:00
|
|
|
if (UsingDecl *UD = dyn_cast<UsingDecl>(Other)) {
|
|
|
|
return isInstantiationOf(UUD, UD, Ctx);
|
|
|
|
}
|
|
|
|
}
|
2009-05-27 13:35:12 +08:00
|
|
|
|
2009-08-30 03:37:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<CXXRecordDecl>(D), Record);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<FunctionDecl>(D), Function);
|
2009-05-27 13:35:12 +08:00
|
|
|
|
2009-08-29 16:11:13 +08:00
|
|
|
if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<EnumDecl>(D), Enum);
|
2009-05-27 13:35:12 +08:00
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
if (VarDecl *Var = dyn_cast<VarDecl>(Other))
|
2009-08-29 16:11:13 +08:00
|
|
|
if (Var->isStaticDataMember())
|
|
|
|
return isInstantiationOfStaticDataMember(cast<VarDecl>(D), Var);
|
|
|
|
|
|
|
|
if (ClassTemplateDecl *Temp = dyn_cast<ClassTemplateDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<ClassTemplateDecl>(D), Temp);
|
2009-08-29 06:03:51 +08:00
|
|
|
|
2009-09-28 14:34:35 +08:00
|
|
|
if (FunctionTemplateDecl *Temp = dyn_cast<FunctionTemplateDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<FunctionTemplateDecl>(D), Temp);
|
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
if (ClassTemplatePartialSpecializationDecl *PartialSpec
|
|
|
|
= dyn_cast<ClassTemplatePartialSpecializationDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(D),
|
|
|
|
PartialSpec);
|
|
|
|
|
2009-09-01 12:26:58 +08:00
|
|
|
if (FieldDecl *Field = dyn_cast<FieldDecl>(Other)) {
|
|
|
|
if (!Field->getDeclName()) {
|
|
|
|
// This is an unnamed field.
|
2009-09-09 23:08:12 +08:00
|
|
|
return Ctx.getInstantiatedFromUnnamedFieldDecl(Field) ==
|
2009-09-01 12:26:58 +08:00
|
|
|
cast<FieldDecl>(D);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
if (UsingDecl *Using = dyn_cast<UsingDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<UsingDecl>(D), Using, Ctx);
|
|
|
|
|
|
|
|
if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(Other))
|
|
|
|
return isInstantiationOf(cast<UsingShadowDecl>(D), Shadow, Ctx);
|
|
|
|
|
2009-05-27 13:35:12 +08:00
|
|
|
return D->getDeclName() && isa<NamedDecl>(Other) &&
|
|
|
|
D->getDeclName() == cast<NamedDecl>(Other)->getDeclName();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename ForwardIterator>
|
2009-09-09 23:08:12 +08:00
|
|
|
static NamedDecl *findInstantiationOf(ASTContext &Ctx,
|
2009-05-27 13:35:12 +08:00
|
|
|
NamedDecl *D,
|
|
|
|
ForwardIterator first,
|
|
|
|
ForwardIterator last) {
|
|
|
|
for (; first != last; ++first)
|
|
|
|
if (isInstantiationOf(Ctx, D, *first))
|
|
|
|
return cast<NamedDecl>(*first);
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-05-27 13:35:12 +08:00
|
|
|
}
|
|
|
|
|
2009-08-28 15:59:38 +08:00
|
|
|
/// \brief Finds the instantiation of the given declaration context
|
|
|
|
/// within the current instantiation.
|
|
|
|
///
|
|
|
|
/// \returns NULL if there was an error
|
2010-03-01 23:56:25 +08:00
|
|
|
DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC,
|
2009-09-17 02:34:49 +08:00
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2009-08-28 15:59:38 +08:00
|
|
|
if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) {
|
2010-03-01 23:56:25 +08:00
|
|
|
Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs);
|
2009-08-28 15:59:38 +08:00
|
|
|
return cast_or_null<DeclContext>(ID);
|
|
|
|
} else return DC;
|
|
|
|
}
|
|
|
|
|
2009-05-28 01:54:46 +08:00
|
|
|
/// \brief Find the instantiation of the given declaration within the
|
|
|
|
/// current instantiation.
|
2009-05-27 13:35:12 +08:00
|
|
|
///
|
|
|
|
/// This routine is intended to be used when \p D is a declaration
|
|
|
|
/// referenced from within a template, that needs to mapped into the
|
|
|
|
/// corresponding declaration within an instantiation. For example,
|
|
|
|
/// given:
|
|
|
|
///
|
|
|
|
/// \code
|
|
|
|
/// template<typename T>
|
|
|
|
/// struct X {
|
|
|
|
/// enum Kind {
|
|
|
|
/// KnownValue = sizeof(T)
|
|
|
|
/// };
|
|
|
|
///
|
|
|
|
/// bool getKind() const { return KnownValue; }
|
|
|
|
/// };
|
|
|
|
///
|
|
|
|
/// template struct X<int>;
|
|
|
|
/// \endcode
|
|
|
|
///
|
2013-07-10 12:59:14 +08:00
|
|
|
/// In the instantiation of <tt>X<int>::getKind()</tt>, we need to map the
|
|
|
|
/// \p EnumConstantDecl for \p KnownValue (which refers to
|
|
|
|
/// <tt>X<T>::<Kind>::KnownValue</tt>) to its instantiation
|
|
|
|
/// (<tt>X<int>::<Kind>::KnownValue</tt>). \p FindInstantiatedDecl performs
|
|
|
|
/// this mapping from within the instantiation of <tt>X<int></tt>.
|
2010-03-01 23:56:25 +08:00
|
|
|
NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
|
2009-09-17 02:34:49 +08:00
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2009-05-27 13:35:12 +08:00
|
|
|
DeclContext *ParentDC = D->getDeclContext();
|
2013-10-23 14:44:28 +08:00
|
|
|
// FIXME: Parmeters of pointer to functions (y below) that are themselves
|
|
|
|
// parameters (p below) can have their ParentDC set to the translation-unit
|
|
|
|
// - thus we can not consistently check if the ParentDC of such a parameter
|
|
|
|
// is Dependent or/and a FunctionOrMethod.
|
|
|
|
// For e.g. this code, during Template argument deduction tries to
|
|
|
|
// find an instantiated decl for (T y) when the ParentDC for y is
|
|
|
|
// the translation unit.
|
|
|
|
// e.g. template <class T> void Foo(auto (*p)(T y) -> decltype(y())) {}
|
2014-01-16 21:03:14 +08:00
|
|
|
// float baz(float(*)()) { return 0.0; }
|
2013-10-23 14:44:28 +08:00
|
|
|
// Foo(baz);
|
|
|
|
// The better fix here is perhaps to ensure that a ParmVarDecl, by the time
|
|
|
|
// it gets here, always has a FunctionOrMethod as its ParentDC??
|
|
|
|
// For now:
|
|
|
|
// - as long as we have a ParmVarDecl whose parent is non-dependent and
|
|
|
|
// whose type is not instantiation dependent, do nothing to the decl
|
|
|
|
// - otherwise find its instantiated decl.
|
|
|
|
if (isa<ParmVarDecl>(D) && !ParentDC->isDependentContext() &&
|
|
|
|
!cast<ParmVarDecl>(D)->getType()->isInstantiationDependentType())
|
|
|
|
return D;
|
2013-10-23 12:12:23 +08:00
|
|
|
if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) ||
|
2010-02-06 03:54:12 +08:00
|
|
|
isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D) ||
|
2012-02-17 05:36:18 +08:00
|
|
|
(ParentDC->isFunctionOrMethod() && ParentDC->isDependentContext()) ||
|
|
|
|
(isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda())) {
|
2009-05-28 01:07:49 +08:00
|
|
|
// D is a local of some kind. Look into the map of local
|
|
|
|
// declarations to their instantiations.
|
2011-02-18 03:47:42 +08:00
|
|
|
typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
|
|
|
|
llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
|
|
|
|
= CurrentInstantiationScope->findInstantiationOf(D);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-18 04:34:02 +08:00
|
|
|
if (Found) {
|
|
|
|
if (Decl *FD = Found->dyn_cast<Decl *>())
|
|
|
|
return cast<NamedDecl>(FD);
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2012-09-12 08:56:43 +08:00
|
|
|
int PackIdx = ArgumentPackSubstitutionIndex;
|
|
|
|
assert(PackIdx != -1 && "found declaration pack but not pack expanding");
|
2011-02-18 04:34:02 +08:00
|
|
|
return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]);
|
|
|
|
}
|
|
|
|
|
2013-07-15 14:14:07 +08:00
|
|
|
// If we're performing a partial substitution during template argument
|
|
|
|
// deduction, we may not have values for template parameters yet. They
|
|
|
|
// just map to themselves.
|
|
|
|
if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
|
|
|
|
isa<TemplateTemplateParmDecl>(D))
|
|
|
|
return D;
|
|
|
|
|
2013-08-10 20:00:21 +08:00
|
|
|
if (D->isInvalidDecl())
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2013-08-10 20:00:21 +08:00
|
|
|
|
2011-02-18 04:34:02 +08:00
|
|
|
// If we didn't find the decl, then we must have a label decl that hasn't
|
|
|
|
// been found yet. Lazily instantiate it and return it now.
|
|
|
|
assert(isa<LabelDecl>(D));
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-18 04:34:02 +08:00
|
|
|
Decl *Inst = SubstDecl(D, CurContext, TemplateArgs);
|
|
|
|
assert(Inst && "Failed to instantiate label??");
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-02-18 04:34:02 +08:00
|
|
|
CurrentInstantiationScope->InstantiatedLocal(D, Inst);
|
|
|
|
return cast<LabelDecl>(Inst);
|
2009-05-28 01:07:49 +08:00
|
|
|
}
|
2009-05-27 13:35:12 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
// For variable template specializations, update those that are still
|
|
|
|
// type-dependent.
|
|
|
|
if (VarTemplateSpecializationDecl *VarSpec =
|
|
|
|
dyn_cast<VarTemplateSpecializationDecl>(D)) {
|
|
|
|
bool InstantiationDependent = false;
|
|
|
|
const TemplateArgumentListInfo &VarTemplateArgs =
|
|
|
|
VarSpec->getTemplateArgsInfo();
|
|
|
|
if (TemplateSpecializationType::anyDependentTemplateArguments(
|
|
|
|
VarTemplateArgs, InstantiationDependent))
|
|
|
|
D = cast<NamedDecl>(
|
|
|
|
SubstDecl(D, VarSpec->getDeclContext(), TemplateArgs));
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
|
2009-09-17 02:34:49 +08:00
|
|
|
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (!Record->isDependentContext())
|
|
|
|
return D;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
// Determine whether this record is the "templated" declaration describing
|
|
|
|
// a class template or class template partial specialization.
|
2009-09-17 02:34:49 +08:00
|
|
|
ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
|
2011-11-08 01:43:18 +08:00
|
|
|
if (ClassTemplate)
|
|
|
|
ClassTemplate = ClassTemplate->getCanonicalDecl();
|
|
|
|
else if (ClassTemplatePartialSpecializationDecl *PartialSpec
|
|
|
|
= dyn_cast<ClassTemplatePartialSpecializationDecl>(Record))
|
|
|
|
ClassTemplate = PartialSpec->getSpecializedTemplate()->getCanonicalDecl();
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
// Walk the current context to find either the record or an instantiation of
|
|
|
|
// it.
|
|
|
|
DeclContext *DC = CurContext;
|
|
|
|
while (!DC->isFileContext()) {
|
|
|
|
// If we're performing substitution while we're inside the template
|
|
|
|
// definition, we'll find our own context. We're done.
|
|
|
|
if (DC->Equals(Record))
|
|
|
|
return Record;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
if (CXXRecordDecl *InstRecord = dyn_cast<CXXRecordDecl>(DC)) {
|
|
|
|
// Check whether we're in the process of instantiating a class template
|
|
|
|
// specialization of the template we're mapping.
|
|
|
|
if (ClassTemplateSpecializationDecl *InstSpec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(InstRecord)){
|
|
|
|
ClassTemplateDecl *SpecTemplate = InstSpec->getSpecializedTemplate();
|
|
|
|
if (ClassTemplate && isInstantiationOf(ClassTemplate, SpecTemplate))
|
|
|
|
return InstRecord;
|
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
// Check whether we're in the process of instantiating a member class.
|
|
|
|
if (isInstantiationOf(Record, InstRecord))
|
|
|
|
return InstRecord;
|
2009-09-17 02:34:49 +08:00
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
// Move to the outer template scope.
|
|
|
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DC)) {
|
|
|
|
if (FD->getFriendObjectKind() && FD->getDeclContext()->isFileContext()){
|
|
|
|
DC = FD->getLexicalDeclContext();
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-29 16:11:13 +08:00
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
2011-11-08 01:43:18 +08:00
|
|
|
DC = DC->getParent();
|
2009-08-29 16:11:13 +08:00
|
|
|
}
|
2010-02-06 06:40:03 +08:00
|
|
|
|
2009-09-17 02:34:49 +08:00
|
|
|
// Fall through to deal with other dependent record types (e.g.,
|
|
|
|
// anonymous unions in class templates).
|
|
|
|
}
|
2009-08-29 16:11:13 +08:00
|
|
|
|
2009-09-17 02:34:49 +08:00
|
|
|
if (!ParentDC->isDependentContext())
|
|
|
|
return D;
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2010-03-01 23:56:25 +08:00
|
|
|
ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs);
|
2009-09-09 23:08:12 +08:00
|
|
|
if (!ParentDC)
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-27 13:35:12 +08:00
|
|
|
if (ParentDC != D->getDeclContext()) {
|
|
|
|
// We performed some kind of instantiation in the parent context,
|
|
|
|
// so now we need to look into the instantiated parent context to
|
|
|
|
// find the instantiation of the declaration D.
|
2010-03-01 23:56:25 +08:00
|
|
|
|
2010-03-10 11:28:59 +08:00
|
|
|
// If our context used to be dependent, we may need to instantiate
|
|
|
|
// it before performing lookup into that context.
|
2011-03-07 04:12:45 +08:00
|
|
|
bool IsBeingInstantiated = false;
|
2010-03-10 11:28:59 +08:00
|
|
|
if (CXXRecordDecl *Spec = dyn_cast<CXXRecordDecl>(ParentDC)) {
|
2010-03-01 23:56:25 +08:00
|
|
|
if (!Spec->isDependentContext()) {
|
|
|
|
QualType T = Context.getTypeDeclType(Spec);
|
2010-03-10 11:28:59 +08:00
|
|
|
const RecordType *Tag = T->getAs<RecordType>();
|
|
|
|
assert(Tag && "type of non-dependent record is not a RecordType");
|
2011-03-07 04:12:45 +08:00
|
|
|
if (Tag->isBeingDefined())
|
|
|
|
IsBeingInstantiated = true;
|
2010-03-10 11:28:59 +08:00
|
|
|
if (!Tag->isBeingDefined() &&
|
|
|
|
RequireCompleteType(Loc, T, diag::err_incomplete_type))
|
2014-05-26 14:22:03 +08:00
|
|
|
return nullptr;
|
2010-11-06 07:22:45 +08:00
|
|
|
|
|
|
|
ParentDC = Tag->getDecl();
|
2010-03-01 23:56:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-26 14:22:03 +08:00
|
|
|
NamedDecl *Result = nullptr;
|
2009-05-27 13:35:12 +08:00
|
|
|
if (D->getDeclName()) {
|
2009-06-30 10:36:12 +08:00
|
|
|
DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName());
|
2012-12-19 08:45:41 +08:00
|
|
|
Result = findInstantiationOf(Context, D, Found.begin(), Found.end());
|
2009-05-27 13:35:12 +08:00
|
|
|
} else {
|
|
|
|
// Since we don't have a name for the entity we're looking for,
|
|
|
|
// our only option is to walk through all of the declarations to
|
|
|
|
// find that name. This will occur in a few cases:
|
|
|
|
//
|
|
|
|
// - anonymous struct/union within a template
|
|
|
|
// - unnamed class/struct/union/enum within a template
|
|
|
|
//
|
|
|
|
// FIXME: Find a better way to find these instantiations!
|
2009-09-09 23:08:12 +08:00
|
|
|
Result = findInstantiationOf(Context, D,
|
2009-06-30 10:36:12 +08:00
|
|
|
ParentDC->decls_begin(),
|
|
|
|
ParentDC->decls_end());
|
2009-05-27 13:35:12 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-03-07 04:12:45 +08:00
|
|
|
if (!Result) {
|
|
|
|
if (isa<UsingShadowDecl>(D)) {
|
|
|
|
// UsingShadowDecls can instantiate to nothing because of using hiding.
|
|
|
|
} else if (Diags.hasErrorOccurred()) {
|
|
|
|
// We've already complained about something, so most likely this
|
|
|
|
// declaration failed to instantiate. There's no point in complaining
|
|
|
|
// further, since this is normal in invalid code.
|
|
|
|
} else if (IsBeingInstantiated) {
|
2011-10-08 19:31:46 +08:00
|
|
|
// The class in which this member exists is currently being
|
2011-03-07 04:12:45 +08:00
|
|
|
// instantiated, and we haven't gotten around to instantiating this
|
|
|
|
// member yet. This can happen when the code uses forward declarations
|
|
|
|
// of member classes, and introduces ordering dependencies via
|
|
|
|
// template instantiation.
|
|
|
|
Diag(Loc, diag::err_member_not_yet_instantiated)
|
|
|
|
<< D->getDeclName()
|
|
|
|
<< Context.getTypeDeclType(cast<CXXRecordDecl>(ParentDC));
|
|
|
|
Diag(D->getLocation(), diag::note_non_instantiated_member_here);
|
2012-03-27 04:28:16 +08:00
|
|
|
} else if (EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) {
|
|
|
|
// This enumeration constant was found when the template was defined,
|
|
|
|
// but can't be found in the instantiation. This can happen if an
|
|
|
|
// unscoped enumeration member is explicitly specialized.
|
|
|
|
EnumDecl *Enum = cast<EnumDecl>(ED->getLexicalDeclContext());
|
|
|
|
EnumDecl *Spec = cast<EnumDecl>(FindInstantiatedDecl(Loc, Enum,
|
|
|
|
TemplateArgs));
|
|
|
|
assert(Spec->getTemplateSpecializationKind() ==
|
|
|
|
TSK_ExplicitSpecialization);
|
|
|
|
Diag(Loc, diag::err_enumerator_does_not_exist)
|
|
|
|
<< D->getDeclName()
|
|
|
|
<< Context.getTypeDeclType(cast<TypeDecl>(Spec->getDeclContext()));
|
|
|
|
Diag(Spec->getLocation(), diag::note_enum_specialized_here)
|
|
|
|
<< Context.getTypeDeclType(Spec);
|
2011-03-07 04:12:45 +08:00
|
|
|
} else {
|
|
|
|
// We should have found something, but didn't.
|
|
|
|
llvm_unreachable("Unable to find instantiation of declaration!");
|
|
|
|
}
|
|
|
|
}
|
2011-10-08 19:31:46 +08:00
|
|
|
|
2009-05-27 13:35:12 +08:00
|
|
|
D = Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D;
|
|
|
|
}
|
2009-06-23 07:06:13 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// \brief Performs template instantiation for all implicit template
|
2009-06-23 07:06:13 +08:00
|
|
|
/// instantiations we have seen until this point.
|
2011-05-31 15:58:42 +08:00
|
|
|
void Sema::PerformPendingInstantiations(bool LocalOnly) {
|
2010-01-17 06:29:39 +08:00
|
|
|
while (!PendingLocalImplicitInstantiations.empty() ||
|
2010-08-25 16:44:16 +08:00
|
|
|
(!LocalOnly && !PendingInstantiations.empty())) {
|
2010-01-17 06:29:39 +08:00
|
|
|
PendingImplicitInstantiation Inst;
|
|
|
|
|
|
|
|
if (PendingLocalImplicitInstantiations.empty()) {
|
2010-08-25 16:44:16 +08:00
|
|
|
Inst = PendingInstantiations.front();
|
|
|
|
PendingInstantiations.pop_front();
|
2010-01-17 06:29:39 +08:00
|
|
|
} else {
|
|
|
|
Inst = PendingLocalImplicitInstantiations.front();
|
|
|
|
PendingLocalImplicitInstantiations.pop_front();
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-25 04:34:43 +08:00
|
|
|
// Instantiate function definitions
|
|
|
|
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) {
|
2010-08-27 07:41:50 +08:00
|
|
|
PrettyDeclStackTraceEntry CrashInfo(*this, Function, SourceLocation(),
|
|
|
|
"instantiating function definition");
|
2010-08-25 16:27:02 +08:00
|
|
|
bool DefinitionRequired = Function->getTemplateSpecializationKind() ==
|
|
|
|
TSK_ExplicitInstantiationDefinition;
|
|
|
|
InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true,
|
|
|
|
DefinitionRequired);
|
2009-07-25 04:34:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
// Instantiate variable definitions
|
2009-07-25 04:34:43 +08:00
|
|
|
VarDecl *Var = cast<VarDecl>(Inst.first);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
assert((Var->isStaticDataMember() ||
|
|
|
|
isa<VarTemplateSpecializationDecl>(Var)) &&
|
|
|
|
"Not a static data member, nor a variable template"
|
|
|
|
" specialization?");
|
2009-09-01 13:12:24 +08:00
|
|
|
|
2010-02-13 18:17:50 +08:00
|
|
|
// Don't try to instantiate declarations if the most recent redeclaration
|
|
|
|
// is invalid.
|
2012-01-15 00:38:05 +08:00
|
|
|
if (Var->getMostRecentDecl()->isInvalidDecl())
|
2010-02-13 18:17:50 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check if the most recent declaration has changed the specialization kind
|
|
|
|
// and removed the need for implicit instantiation.
|
2012-01-15 00:38:05 +08:00
|
|
|
switch (Var->getMostRecentDecl()->getTemplateSpecializationKind()) {
|
2010-02-13 18:17:50 +08:00
|
|
|
case TSK_Undeclared:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Cannot instantitiate an undeclared specialization.");
|
2010-02-13 18:17:50 +08:00
|
|
|
case TSK_ExplicitInstantiationDeclaration:
|
|
|
|
case TSK_ExplicitSpecialization:
|
2010-08-25 16:27:02 +08:00
|
|
|
continue; // No longer need to instantiate this type.
|
|
|
|
case TSK_ExplicitInstantiationDefinition:
|
|
|
|
// We only need an instantiation if the pending instantiation *is* the
|
|
|
|
// explicit instantiation.
|
2012-01-15 00:38:05 +08:00
|
|
|
if (Var != Var->getMostRecentDecl()) continue;
|
2010-02-13 18:17:50 +08:00
|
|
|
case TSK_ImplicitInstantiation:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
PrettyDeclStackTraceEntry CrashInfo(*this, Var, SourceLocation(),
|
|
|
|
"instantiating variable definition");
|
2010-08-25 16:27:02 +08:00
|
|
|
bool DefinitionRequired = Var->getTemplateSpecializationKind() ==
|
|
|
|
TSK_ExplicitInstantiationDefinition;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Instantiate static data member definitions or variable template
|
|
|
|
// specializations.
|
|
|
|
InstantiateVariableDefinition(/*FIXME:*/ Inst.second, Var, true,
|
|
|
|
DefinitionRequired);
|
2009-06-23 07:06:13 +08:00
|
|
|
}
|
|
|
|
}
|
2010-03-24 13:22:00 +08:00
|
|
|
|
|
|
|
void Sema::PerformDependentDiagnostics(const DeclContext *Pattern,
|
|
|
|
const MultiLevelTemplateArgumentList &TemplateArgs) {
|
2014-03-07 22:09:15 +08:00
|
|
|
for (auto DD : Pattern->ddiags()) {
|
2010-03-24 13:22:00 +08:00
|
|
|
switch (DD->getKind()) {
|
|
|
|
case DependentDiagnostic::Access:
|
|
|
|
HandleDependentAccessCheck(*DD, TemplateArgs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|