28 using namespace clang;
55 bool RelativeToPrimary,
65 Ctx = D->getDeclContext();
69 dyn_cast<VarTemplateSpecializationDecl>(D)) {
72 !isa<VarTemplatePartialSpecializationDecl>(Spec))
79 assert(Spec->getSpecializedTemplate() &&
"No variable template?");
85 if (Partial->isMemberSpecialization())
88 VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
102 = dyn_cast<TemplateTemplateParmDecl>(D)) {
103 for (
unsigned I = 0, N = TTP->getDepth() + 1;
I != N; ++
I)
113 = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
116 !isa<ClassTemplatePartialSpecializationDecl>(Spec))
123 assert(Spec->getSpecializedTemplate() &&
"No class template?");
124 if (Spec->getSpecializedTemplate()->isMemberSpecialization())
128 else if (
FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
129 if (!RelativeToPrimary &&
130 (Function->getTemplateSpecializationKind() ==
132 !Function->getClassScopeSpecializationPattern()))
136 = Function->getTemplateSpecializationArgs()) {
142 assert(Function->getPrimaryTemplate() &&
"No function template?");
143 if (Function->getPrimaryTemplate()->isMemberSpecialization())
151 = Function->getDescribedFunctionTemplate()) {
160 if (Function->getFriendObjectKind() &&
161 Function->getDeclContext()->isFileContext() &&
162 (!Pattern || !Pattern->getLexicalDeclContext()->
isFileContext())) {
163 Ctx = Function->getLexicalDeclContext();
164 RelativeToPrimary =
false;
167 }
else if (
CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
169 QualType T = ClassTemplate->getInjectedClassNameSpecialization();
173 llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs()));
174 if (ClassTemplate->isMemberSpecialization())
180 RelativeToPrimary =
false;
188 case TemplateInstantiation:
189 case ExceptionSpecInstantiation:
190 case DefaultTemplateArgumentInstantiation:
191 case DefaultFunctionArgumentInstantiation:
192 case ExplicitTemplateArgumentSubstitution:
193 case DeducedTemplateArgumentSubstitution:
194 case PriorTemplateArgumentSubstitution:
197 case DefaultTemplateArgumentChecking:
201 llvm_unreachable(
"Invalid InstantiationKind!");
209 : SemaRef(SemaRef), SavedInNonInstantiationSFINAEContext(
210 SemaRef.InNonInstantiationSFINAEContext) {
217 Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
224 Inst.TemplateArgs = TemplateArgs.data();
225 Inst.NumTemplateArgs = TemplateArgs.size();
230 if (!Inst.isInstantiationRecord())
240 PointOfInstantiation, InstantiationRange, Entity) {}
247 PointOfInstantiation, InstantiationRange, Entity) {}
255 PointOfInstantiation, InstantiationRange, Template, nullptr,
265 InstantiationRange, FunctionTemplate, nullptr,
266 TemplateArgs, &DeductionInfo) {}
276 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
277 TemplateArgs, &DeductionInfo) {}
287 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
288 TemplateArgs, &DeductionInfo) {}
296 PointOfInstantiation, InstantiationRange, Param, nullptr,
306 PointOfInstantiation, InstantiationRange, Param, Template,
316 PointOfInstantiation, InstantiationRange, Param, Template,
325 PointOfInstantiation, InstantiationRange, Param, Template,
335 = SavedInNonInstantiationSFINAEContext;
340 "forgot to remove a lookup module for a template instantiation");
353 bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
363 SemaRef.
Diag(PointOfInstantiation,
364 diag::err_template_recursion_depth_exceeded)
366 << InstantiationRange;
367 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
379 SkipStart = Limit / 2 + Limit % 2;
384 unsigned InstantiationIdx = 0;
389 ++Active, ++InstantiationIdx) {
391 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
392 if (InstantiationIdx == SkipStart) {
395 diag::note_instantiation_contexts_suppressed)
401 switch (Active->Kind) {
403 Decl *D = Active->Entity;
405 unsigned DiagID = diag::note_template_member_class_here;
406 if (isa<ClassTemplateSpecializationDecl>(Record))
407 DiagID = diag::note_template_class_instantiation_here;
410 << Active->InstantiationRange;
411 }
else if (
FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
413 if (Function->getPrimaryTemplate())
414 DiagID = diag::note_function_template_spec_here;
416 DiagID = diag::note_template_member_function_here;
419 << Active->InstantiationRange;
420 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
422 VD->isStaticDataMember()?
423 diag::note_template_static_data_member_def_here
424 : diag::note_template_variable_def_here)
426 << Active->InstantiationRange;
427 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
429 diag::note_template_enum_def_here)
431 << Active->InstantiationRange;
432 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
434 diag::note_template_nsdmi_here)
435 << FD << Active->InstantiationRange;
438 diag::note_template_type_alias_instantiation_here)
439 << cast<TypeAliasTemplateDecl>(D)
440 << Active->InstantiationRange;
446 TemplateDecl *Template = cast<TemplateDecl>(Active->Entity);
448 llvm::raw_svector_ostream OS(TemplateArgsStr);
453 diag::note_default_arg_instantiation_here)
455 << Active->InstantiationRange;
462 diag::note_explicit_template_arg_substitution_here)
465 Active->TemplateArgs,
466 Active->NumTemplateArgs)
467 << Active->InstantiationRange;
473 dyn_cast<ClassTemplatePartialSpecializationDecl>(Active->Entity)) {
475 diag::note_partial_spec_deduct_instantiation_here)
478 PartialSpec->getTemplateParameters(),
479 Active->TemplateArgs,
480 Active->NumTemplateArgs)
481 << Active->InstantiationRange;
484 = cast<FunctionTemplateDecl>(Active->Entity);
486 diag::note_function_template_deduction_instantiation_here)
489 Active->TemplateArgs,
490 Active->NumTemplateArgs)
491 << Active->InstantiationRange;
496 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
497 FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
500 llvm::raw_svector_ostream OS(TemplateArgsStr);
505 diag::note_default_function_arg_instantiation_here)
507 << Active->InstantiationRange;
512 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
515 Name = std::string(
" '") + Parm->
getName().str() +
"'";
518 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
519 TemplateParams = Template->getTemplateParameters();
522 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
523 ->getTemplateParameters();
525 diag::note_prior_template_arg_substitution)
526 << isa<TemplateTemplateParmDecl>(Parm)
529 Active->TemplateArgs,
530 Active->NumTemplateArgs)
531 << Active->InstantiationRange;
537 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
538 TemplateParams = Template->getTemplateParameters();
541 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
542 ->getTemplateParameters();
545 diag::note_template_default_arg_checking)
547 Active->TemplateArgs,
548 Active->NumTemplateArgs)
549 << Active->InstantiationRange;
555 diag::note_template_exception_spec_instantiation_here)
556 << cast<FunctionDecl>(Active->Entity)
557 << Active->InstantiationRange;
573 switch(Active->Kind) {
577 if (isa<TypeAliasTemplateDecl>(Active->Entity))
597 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
598 return Active->DeductionInfo;
606 static std::pair<unsigned, unsigned>
609 return std::make_pair(TTP->getDepth(), TTP->getIndex());
612 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
622 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
630 TemplateInstantiator(
Sema &SemaRef,
634 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
642 bool AlreadyTransformed(
QualType T);
654 this->Entity = Entity;
660 bool &ShouldExpand,
bool &RetainExpansion,
662 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
663 PatternRange, Unexpanded,
670 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
680 unsigned Depth, Index;
683 Result = TemplateArgs(Depth, Index);
699 unsigned Depth, Index;
709 void transformAttrs(
Decl *Old,
Decl *New) {
713 void transformedLocalDecl(
Decl *Old,
Decl *New) {
720 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
721 NewTD->setInstantiatedFromMemberTemplate(
722 OldMD->getDescribedFunctionTemplate());
732 if (
auto *DC = dyn_cast<DeclContext>(Old))
768 NamedDecl *FirstQualifierInScope =
nullptr);
770 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
778 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
796 return inherited::TransformFunctionProtoType(TLB, TL);
799 template<
typename Fn>
803 unsigned ThisTypeQuals,
804 Fn TransformExceptionSpec);
809 bool ExpectParameterPack);
829 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
833 Owner, TemplateArgs);
834 return DeclInstantiator.SubstTemplateParams(OrigTPL);
843 bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
850 getSema().MarkDeclarationsReferencedInType(Loc, T);
859 if (Arg.isPackExpansion())
880 if (TTP->isParameterPack()) {
882 "Missing argument pack");
888 "Wrong kind of template template argument");
900 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
904 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
909 TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *D,
915 = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
923 "Missing argument pack");
925 if (getSema().ArgumentPackSubstitutionIndex == -1)
933 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
936 return Tag->getDecl();
939 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
944 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
948 TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
953 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
954 StartLoc, NameLoc, Name);
956 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
960 VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
963 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
965 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
970 TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
987 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
991 SemaRef.
Diag(TD->getLocation(), diag::note_previous_use);
1015 TTP->getPosition()))
1022 "Missing argument pack");
1024 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1028 return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
1035 assert(!Template.
isNull() &&
"Null template template argument");
1043 Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template);
1050 if (getSema().ArgumentPackSubstitutionIndex == -1)
1058 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1059 FirstQualifierInScope);
1071 TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *E,
1084 "Missing argument pack");
1086 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1105 return transformNonTypeTemplateParmRef(NTTP, E->
getLocation(), Arg);
1108 const LoopHintAttr *
1109 TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
1110 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).
get();
1112 if (TransformedExpr == LH->getValue())
1116 if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
1121 return LoopHintAttr::CreateImplicit(
1122 getSema().
Context, LH->getSemanticSpelling(), LH->getOption(),
1123 LH->getState(), TransformedExpr, LH->getRange());
1126 ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1148 VD = cast_or_null<ValueDecl>(
1149 getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1162 isa<PackExpansionType>(parm->
getType())) {
1164 cast<PackExpansionType>(parm->
getType())->getPattern(),
1170 assert(!type.
isNull() &&
"type substitution failed for param type");
1174 if (!result.isInvalid()) type = result.get()->getType();
1182 if (result.isInvalid())
return ExprError();
1184 Expr *resultExpr = result.get();
1186 type, resultExpr->
getValueKind(), loc, parm, resultExpr);
1190 TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1205 TemplateInstantiator::RebuildParmVarDeclRefExpr(
ParmVarDecl *PD,
1208 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
1219 return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(VD), E->
getExprLoc());
1233 cast_or_null<ParmVarDecl>(TransformDecl(E->
getExprLoc(), *
I));
1245 TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *E,
1248 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1249 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1250 assert(Found &&
"no instantiation for parameter pack");
1252 Decl *TransformedDecl;
1253 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1264 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1266 TransformedDecl = Found->get<
Decl*>();
1270 return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(TransformedDecl),
1275 TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *E) {
1282 return TransformTemplateParmRefExpr(E, NTTP);
1291 return TransformFunctionParmPackRefExpr(E, PD);
1296 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1298 assert(!cast<FunctionDecl>(E->
getParam()->getDeclContext())->
1299 getDescribedFunctionTemplate() &&
1300 "Default arg expressions are never formed in dependent cases.");
1302 cast<FunctionDecl>(E->
getParam()->getDeclContext()),
1306 template<
typename Fn>
1310 unsigned ThisTypeQuals,
1311 Fn TransformExceptionSpec) {
1314 return inherited::TransformFunctionProtoType(
1315 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1319 TemplateInstantiator::TransformFunctionTypeParam(
ParmVarDecl *OldParm,
1320 int indexAdjustment,
1322 bool ExpectParameterPack) {
1324 NumExpansions, ExpectParameterPack);
1328 TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
1350 "Missing argument pack");
1352 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1357 = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg);
1368 "Template argument kind mismatch");
1374 = getSema().Context.getSubstTemplateTypeParmType(T, Replacement);
1387 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
1391 = getSema().Context.getTemplateTypeParmType(T->
getDepth()
1402 TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
1417 Result = getSema().Context.getSubstTemplateTypeParmType(
1458 "Cannot perform an instantiation without some context on the "
1459 "instantiation stack");
1465 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1466 return Instantiator.TransformType(T);
1474 "Cannot perform an instantiation without some context on the "
1475 "instantiation stack");
1489 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1492 QualType Result = Instantiator.TransformType(TLB, TL);
1504 "Cannot perform an instantiation without some context on the "
1505 "instantiation stack");
1512 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
1513 return Instantiator.TransformType(T);
1547 unsigned ThisTypeQuals) {
1549 "Cannot perform an instantiation without some context on the "
1550 "instantiation stack");
1555 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1571 Result = Instantiator.TransformFunctionProtoType(
1572 TLB, Proto, ThisContext, ThisTypeQuals,
1574 bool &Changed) {
return false; });
1576 Result = Instantiator.TransformType(TLB, TL);
1590 TemplateInstantiator Instantiator(*
this, Args, New->getLocation(),
1594 bool Changed =
false;
1595 if (Instantiator.TransformExceptionSpec(
1597 ExceptionStorage, Changed))
1606 int indexAdjustment,
1608 bool ExpectParameterPack) {
1617 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
1628 }
else if (ExpectParameterPack) {
1633 Diag(OldParm->getLocation(),
1634 diag::err_function_parameter_pack_without_parameter_packs)
1639 NewDI =
SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
1647 Diag(OldParm->getLocation(), diag::err_param_with_void_type);
1653 OldParm->getLocation(),
1668 FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext());
1669 if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
1721 "Cannot perform an instantiation without some context on the "
1722 "instantiation stack");
1724 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
1726 return Instantiator.TransformFunctionTypeParams(
1727 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
1740 bool Invalid =
false;
1742 for (
const auto &
Base : Pattern->
bases()) {
1743 if (!
Base.getType()->isDependentType()) {
1745 if (RD->isInvalidDecl())
1746 Instantiation->setInvalidDecl();
1754 if (
Base.isPackExpansion()) {
1760 bool ShouldExpand =
false;
1761 bool RetainExpansion =
false;
1764 Base.getSourceRange(),
1766 TemplateArgs, ShouldExpand,
1775 for (
unsigned I = 0;
I != *NumExpansions; ++
I) {
1780 Base.getSourceRange().getBegin(),
1789 Base.getSourceRange(),
1791 Base.getAccessSpecifierAsWritten(),
1794 InstantiatedBases.push_back(InstantiatedBase);
1803 EllipsisLoc =
Base.getEllipsisLoc();
1807 Base.getSourceRange().getBegin(),
1812 Base.getSourceRange().getBegin(),
1823 Base.getSourceRange(),
1825 Base.getAccessSpecifierAsWritten(),
1828 InstantiatedBases.push_back(InstantiatedBase);
1852 bool InstantiatedFromMember,
1856 bool Complain =
true) {
1871 if (!Complain || (PatternDef && PatternDef->isInvalidDecl())) {
1873 }
else if (PatternDef) {
1875 S.
Diag(PointOfInstantiation,
1876 diag::err_template_instantiate_within_definition)
1881 Instantiation->setInvalidDecl();
1882 }
else if (InstantiatedFromMember) {
1883 S.
Diag(PointOfInstantiation,
1884 diag::err_implicit_instantiate_member_undefined)
1886 S.
Diag(Pattern->getLocation(), diag::note_member_declared_at);
1888 S.
Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)
1891 S.
Diag(Pattern->getLocation(), diag::note_template_decl_here);
1899 Instantiation->setInvalidDecl();
1935 Pattern, PatternDef, TSK, Complain))
1937 Pattern = PatternDef;
1943 MSInfo->setPointOfInstantiation(PointOfInstantiation);
1945 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
1946 Spec->setTemplateSpecializationKind(TSK);
1947 Spec->setPointOfInstantiation(PointOfInstantiation);
1954 "instantiating class definition");
1965 bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
1990 Instantiation->setInvalidDecl();
1998 for (
auto *Member : Pattern->
decls()) {
2008 if (Member->getDeclContext() != Pattern)
2011 if (Member->isInvalidDecl()) {
2012 Instantiation->setInvalidDecl();
2016 Decl *NewMember = Instantiator.
Visit(Member);
2018 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
2019 Fields.push_back(Field);
2020 }
else if (
EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
2026 Enum->isCompleteDefinition()) {
2028 assert(MSInfo &&
"no spec info for member enum specialization");
2033 if (SA->isFailed()) {
2036 Instantiation->setInvalidDecl();
2041 if (NewMember->isInvalidDecl())
2042 Instantiation->setInvalidDecl();
2052 ActOnFields(
nullptr, Instantiation->getLocation(), Instantiation, Fields,
2066 E = LateAttrs.end();
I !=
E; ++
I) {
2073 dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
2079 I->NewDecl->addAttr(NewAttr);
2091 Instantiation->setLocation(Pattern->getLocation());
2096 if (!Instantiation->isInvalidDecl()) {
2107 P->first,
P->second)) {
2108 Instantiation->setInvalidDecl();
2120 P->first,
P->second)) {
2121 Instantiation->setInvalidDecl();
2130 if (!Instantiation->isInvalidDecl()) {
2139 return Instantiation->isInvalidDecl();
2164 Pattern, PatternDef, TSK,
true))
2166 Pattern = PatternDef;
2172 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2179 "instantiating enum definition");
2202 return Instantiation->isInvalidDecl();
2229 "pattern and instantiation disagree about init style");
2237 if (OutermostClass == PatternRD) {
2238 Diag(Pattern->getLocEnd(), diag::err_in_class_initializer_not_yet_parsed)
2239 << PatternRD << Pattern;
2241 Diag(Pattern->getLocEnd(),
2242 diag::err_in_class_initializer_not_yet_parsed_outer_class)
2243 << PatternRD << OutermostClass << Pattern;
2245 Instantiation->setInvalidDecl();
2253 "instantiating default member init");
2269 Expr *Init = NewInit.get();
2270 assert((!Init || !isa<ParenListExpr>(Init)) &&
"call-style init in class");
2272 Instantiation, Init ? Init->getLocStart() :
SourceLocation(), Init);
2284 struct PartialSpecMatchResult {
2295 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
2297 if (ClassTemplateSpec->isInvalidDecl())
2311 typedef PartialSpecMatchResult MatchResult;
2316 for (
unsigned I = 0, N = PartialSpecs.size();
I != N; ++
I) {
2330 Matched.push_back(PartialSpecMatchResult());
2331 Matched.back().Partial = Partial;
2332 Matched.back().Args = Info.take();
2340 if (Matched.size() >= 1) {
2342 if (Matched.size() == 1) {
2355 PEnd = Matched.end();
2358 PointOfInstantiation)
2365 bool Ambiguous =
false;
2367 PEnd = Matched.end();
2371 PointOfInstantiation)
2380 ClassTemplateSpec->setInvalidDecl();
2381 Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous)
2382 << ClassTemplateSpec;
2386 PEnd = Matched.end();
2388 Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
2390 P->Partial->getTemplateParameters(),
2408 Pattern = OrigPartialSpec;
2450 "Unexpected template specialization kind!");
2451 for (
auto *D : Instantiation->
decls()) {
2452 bool SuppressNew =
false;
2453 if (
auto *Function = dyn_cast<FunctionDecl>(D)) {
2455 = Function->getInstantiatedFromMemberFunction()) {
2457 = Function->getMemberSpecializationInfo();
2458 assert(MSInfo &&
"No member specialization information?");
2480 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2482 if (Function->isDefined()) {
2490 std::make_pair(Function, PointOfInstantiation));
2493 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
2494 if (isa<VarTemplateSpecializationDecl>(Var))
2499 assert(MSInfo &&
"No member specialization information?");
2528 }
else if (
auto *Record = dyn_cast<CXXRecordDecl>(D)) {
2534 if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
2539 assert(MSInfo &&
"No member specialization information?");
2561 assert(Pattern &&
"Missing instantiated-from-template information");
2563 if (!Record->getDefinition()) {
2584 Record->getTemplateSpecializationKind() ==
2586 Record->setTemplateSpecializationKind(TSK);
2591 Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
2595 }
else if (
auto *Enum = dyn_cast<EnumDecl>(D)) {
2597 assert(MSInfo &&
"No member specialization information?");
2604 PointOfInstantiation, TSK, Enum,
2610 if (Enum->getDefinition())
2613 EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
2614 assert(Pattern &&
"Missing instantiated-from-template information");
2620 InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
2625 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
2632 ClassPattern->
lookup(Field->getDeclName());
2667 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2670 return Instantiator.TransformStmt(S);
2678 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2681 return Instantiator.TransformExpr(E);
2686 bool CXXDirectInit) {
2687 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2690 return Instantiator.TransformInitializer(Init, CXXDirectInit);
2699 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2702 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
2712 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
2714 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
2721 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
2723 return Instantiator.TransformDeclarationNameInfo(NameInfo);
2730 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
2733 SS.
Adopt(QualifierLoc);
2734 return Instantiator.TransformTemplateName(SS, Name, Loc);
2740 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
2743 return Instantiator.TransformTemplateArguments(Args, NumArgs, Result);
2751 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
2752 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
2753 unsigned i = PV->getFunctionScopeIndex();
2756 if (FD->getParamDecl(i) == PV)
2757 return FD->getCanonicalDecl()->getParamDecl(i);
2764 llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
2771 const Decl *CheckD = D;
2774 if (Found !=
Current->LocalDecls.end())
2775 return &Found->second;
2779 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
2780 CheckD = Tag->getPreviousDecl();
2786 if (!
Current->CombineWithOuterScope)
2792 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
2793 isa<TemplateTemplateParmDecl>(D))
2798 if (RD->isLocalClass())
2803 if (isa<EnumDecl>(D))
2809 assert(isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
2815 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2816 if (Stored.isNull()) {
2820 while (Current->CombineWithOuterScope && Current->Outer) {
2821 Current = Current->Outer;
2822 assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
2823 "Instantiated local in inner and outer scopes");
2827 }
else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
2828 Pack->push_back(cast<ParmVarDecl>(Inst));
2830 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
2837 DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
2838 Pack->push_back(Inst);
2846 assert(
Current->LocalDecls.find(D) ==
Current->LocalDecls.end() &&
2847 "Creating local pack after instantiation of local");
2851 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2852 DeclArgumentPack *Pack =
new DeclArgumentPack;
2854 ArgumentPacks.push_back(Pack);
2859 unsigned NumExplicitArgs) {
2860 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
2861 "Already have a partially-substituted pack");
2862 assert((!PartiallySubstitutedPack
2863 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
2864 "Wrong number of arguments in partially-substituted pack");
2865 PartiallySubstitutedPack = Pack;
2866 ArgsInPartiallySubstitutedPack = ExplicitArgs;
2867 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
2872 unsigned *NumExplicitArgs)
const {
2874 *ExplicitArgs =
nullptr;
2875 if (NumExplicitArgs)
2876 *NumExplicitArgs = 0;
2880 if (
Current->PartiallySubstitutedPack) {
2882 *ExplicitArgs =
Current->ArgsInPartiallySubstitutedPack;
2883 if (NumExplicitArgs)
2884 *NumExplicitArgs =
Current->NumArgsInPartiallySubstitutedPack;
2886 return Current->PartiallySubstitutedPack;
2889 if (!
Current->CombineWithOuterScope)
ExprResult BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
Construct a new expression that refers to the given integral template argument with the given source-...
Defines the clang::ASTContext interface.
void ActOnFinishDelayedMemberInitializers(Decl *Record)
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
void InstantiateClassMembers(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiates the definitions of all of the member of the given class, which is an instantiation of a ...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
ParmVarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
SmallVector< Module *, 16 > ActiveTemplateInstantiationLookupModules
Extra modules inspected when performing a lookup during a template instantiation. ...
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier * > Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
unsigned getDepth() const
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
no exception specification
We are instantiating a default argument for a template parameter.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization, retrieves the member specialization information.
A (possibly-)qualified type.
void setHidden(bool Hide)
Set whether this declaration is hidden from name lookup.
TemplateDeductionResult
Describes the result of template argument deduction.
void InstantiatedLocal(const Decl *D, Decl *Inst)
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
A stack-allocated class that identifies which local variable declaration instantiations are present i...
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic...
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
const LangOptions & getLangOpts() const
bool isMemberSpecialization()
Determines whether this class template partial specialization template was a specialization of a memb...
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Provides information about an attempted template argument deduction, whose success or failure was des...
We are substituting prior template arguments into a new template parameter.
We are instantiating a default argument for a function.
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed...
The current expression is potentially evaluated at run time, which means that code may be generated t...
bool SubstParmTypes(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const FunctionProtoType::ExtParameterInfo *ExtParamInfos, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< QualType > &ParamTypes, SmallVectorImpl< ParmVarDecl * > *OutParams, ExtParameterInfoBuilder &ParamInfos)
Substitute the given template arguments into the given set of parameters, producing the set of parame...
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments...
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Defines the C++ template declaration subclasses.
void disableLateAttributeInstantiation()
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain=true)
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Declaration of a variable template.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
NamedDecl * getParam(unsigned Idx)
A container of type source information.
unsigned getIndex() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
static bool DiagnoseUninstantiableTemplate(Sema &S, SourceLocation PointOfInstantiation, TagDecl *Instantiation, bool InstantiatedFromMember, TagDecl *Pattern, TagDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned NonInstantiationEntries
The number of ActiveTemplateInstantiation entries in ActiveTemplateInstantiations that are not actual...
We are instantiating a template declaration.
Expr * getInClassInitializer() const
getInClassInitializer - Get the C++11 in-class initializer for this member, or null if one has not be...
InClassInitStyle getInClassInitStyle() const
getInClassInitStyle - Get the kind of (C++11) in-class initializer which this field has...
enum clang::Sema::ActiveTemplateInstantiation::InstantiationKind Kind
IdentType getIdentType() const
void ActOnFinishCXXNonNestedClass(Decl *D)
This file provides some common utility functions for processing Lambda related AST Constructs...
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
void InstantiatedLocalPackArg(const Decl *D, ParmVarDecl *Inst)
RAII object that enters a new expression evaluation context.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Information about one declarator, including the parsed type information and the identifier.
DiagnosticsEngine & Diags
TypeSourceInfo * SubstFunctionDeclType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, unsigned ThisTypeQuals)
A form of SubstType intended specifically for instantiating the type of a FunctionDecl.
Represents a variable template specialization, which refers to a variable template with a given set o...
SmallVector< CXXRecordDecl *, 4 > DelayedDllExportClasses
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
TemplateTypeParmDecl * getDecl() const
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Stores a list of template parameters for a TemplateDecl and its derived classes.
const ParmVarDecl * getParam() const
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
ParmVarDecl - Represents a parameter to a function.
SourceLocation PointOfInstantiation
The point of instantiation within the source code.
SourceLocation getLocation() const
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Base wrapper for a particular "section" of type source info.
RecordDecl - Represents a struct/union/class.
bool hasUninstantiatedDefaultArg() const
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
DeclarationName getName() const
getName - Returns the embedded declaration name.
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
void setUninstantiatedDefaultArg(Expr *arg)
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
The results of name lookup within a DeclContext.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Decl * Entity
The entity that is being instantiated.
void startDefinition()
Starts the definition of this tag declaration.
CXXRecordDecl * getDefinition() const
bool isTranslationUnit() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
TagKind getTagKind() const
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, bool &RetainExpansion, Optional< unsigned > &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
We are checking the validity of a default template argument that has been used when naming a template...
Describes a module or submodule.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateArgument getArgumentPack() const
void setNameLoc(SourceLocation Loc)
const TargetInfo & getTargetInfo() const
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class...
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
A convenient class for passing around template argument information.
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
We are substituting template argument determined as part of template argument deduction for either a ...
Wrapper for substituted template type parameters.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
ParmVarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
Wrapper for substituted template type parameters.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
We are substituting explicit template arguments provided for a function template. ...
Scope - A scope is a transient data structure that is used while parsing the program.
bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template, alias template, or a member thereof.
CXXRecordDecl * getCanonicalDecl() override
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
Represents a C++ nested-name-specifier or a global scope specifier.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
bool isLambdaCallOperator(const CXXMethodDecl *MD)
SourceLocation getLocation() const
detail::InMemoryDirectory::const_iterator I
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
A default argument (C++ [dcl.fct.default]).
void setLocStart(SourceLocation L)
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
RAII object used to change the argument pack substitution index within a Sema object.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, FunctionDecl *Function, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given function from its template.
A helper class for building up ExtParameterInfos.
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Perform substitution on the base class specifiers of the given class template specialization.
void MakeInstantiatedLocalArgPack(const Decl *D)
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
Sema - This implements semantic analysis and AST building for C.
Represents a prototype with parameter type info, e.g.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
bool CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, TemplateSpecializationKind NewTSK, NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK, SourceLocation PrevPtOfInstantiation, bool &SuppressNew)
Diagnose cases where we have an explicit template specialization before/after an explicit template in...
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization, retrieves the member specialization information.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations, which must be passed to InstantiateClassTemplatePartialSpecialization once the class definition has been completed.
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
Defines the clang::LangOptions interface.
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
bool hasFatalErrorOccurred() const
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
Declaration of a template type parameter.
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
ExprResult BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc)
Given a non-type template argument that refers to a declaration and the type of its corresponding non...
TranslationUnitDecl * getTranslationUnitDecl() const
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
SourceLocation getLocation() const
ArgKind getKind() const
Return the kind of stored template argument.
ExtProtoInfo getExtProtoInfo() const
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, Expr *Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member, and after instantiating an in-class initializer in a class template.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
QualType getType() const
Get the type for which this source info wrapper provides information.
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
void CheckCompletedCXXClass(CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Data structure that captures multiple levels of template argument lists for use in template instantia...
void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
SmallVector< ActiveTemplateInstantiation, 16 > ActiveTemplateInstantiations
List of active template instantiations.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
SourceLocation getLocEnd() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
const TypeClass * getTypePtr() const
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all otuer scopes, down to the given outermost scope. ...
ActiveTemplateInstantiation()
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
ExceptionSpecificationType Type
The kind of exception specification this is.
A stack object to be created when performing template instantiation.
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Encodes a location in the source.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
const TemplateArgument * iterator
void setBraceRange(SourceRange R)
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
A structure for storing an already-substituted template template parameter pack.
SourceRange getBraceRange() const
void InstantiateStaticDataMemberDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive=false, bool DefinitionRequired=false)
Instantiate the definition of the given variable from its template.
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
TagDecl - Represents the declaration of a struct/union/class/enum.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
void printName(raw_ostream &os) const
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Represents a static or instance method of a struct/union/class.
SourceLocation getNameLoc() const
bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a visible definition.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
static const Decl * getCanonicalParmVarDecl(const Decl *D)
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
void setTagKind(TagKind TK)
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
ParmVarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
This template specialization was instantiated from a template due to an explicit instantiation defini...
bool isFileContext() const
static void PrintTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
Represents a C++11 static_assert declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema's representation of template deduction information to the form used in overload-can...
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList)
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
void setHasInheritedDefaultArg(bool I=true)
QualType getType() const
Return the type wrapped by this type source info.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization, which was named as part of an explicit instantiation.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template...
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
Represents a reference to a function parameter pack that has been substituted but not yet expanded...
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
Represents a template name that was expressed as a qualified name.
TagTypeKind
The kind of a tag type.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
[C99 6.4.2.2] - A predefined identifier such as func.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
LocalInstantiationScope * getStartingScope() const
The base class of all kinds of template declarations (e.g., class, function, etc.).
A template instantiation that is currently in progress.
bool hasUnparsedDefaultArg() const
hasUnparsedDefaultArg - Determines whether this parameter has a default argument that has not yet bee...
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
TypeLoc IgnoreParens() const
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
This template specialization was instantiated from a template due to an explicit instantiation declar...
bool isParameterPack() const
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
DeclarationName - The name of a declaration.
bool InstantiateClass(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK, bool Complain=true)
Instantiate the definition of a class from a given pattern.
void setInstantiationOfMemberFunction(FunctionDecl *FD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member function FD.
bool isNull() const
Determine whether this template argument has no value.
EnumDecl - Represents an enum.
unsigned getFunctionScopeDepth() const
detail::InMemoryDirectory::const_iterator E
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
unsigned getDepth() const
Get the nesting depth of the template parameter.
bool hasInheritedDefaultArg() const
Location wrapper for a TemplateArgument.
void setUnparsedDefaultArg()
setUnparsedDefaultArg - Specify that this parameter has an unparsed default argument.
Expr * getUninstantiatedDefaultArg()
const T * getAs() const
Member-template getAs<specific type>'.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
This template specialization was declared or defined by an explicit specialization (C++ [temp...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
static std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a parameter pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool isNull() const
Determine whether this template name is NULL.
UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
A mapping from parameters with unparsed default arguments to the set of instantiations of each parame...
The template argument is a type.
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
The template argument is actually a parameter pack.
bool isStaticDataMember() const
Determines whether this is a static data member.
Represents a base class of a C++ class.
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, ParmVarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< ParmVarDecl * > Params)
A template argument list.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned getFullDataSize() const
Returns the size of the type source info data block.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation, for substitutions of prior template arguments.
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
bool SubstExprs(ArrayRef< Expr * > Exprs, bool IsCall, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< Expr * > &Outputs)
Substitute the given template arguments into a list of expressions, expanding pack expansions if requ...
void Clear()
Note that we have finished instantiating this template.
Provides information a specialization of a member of a class template, which may be a member function...
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs)
Find the instantiation of the given declaration within the current instantiation. ...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Declaration of a class template.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
ArrayRef< ParmVarDecl * > getParams() const
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
A reference to a declared variable, function, enum, etc.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
InstantiationKind
The kind of template instantiation we are performing.
We are instantiating the exception specification for a function template which was deferred until it ...
StringRef getKindName() const
Wrapper for template type parameters.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
EnumDecl * getDefinition() const
No keyword precedes the qualified type name.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
TemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon, QualType Aliased)
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
ExceptionSpecInfo ExceptionSpec
Declaration of a template function.
Attr - This represents one attribute.
const RecordDecl * getParent() const
getParent - Returns the parent of this field declaration, which is the struct in which this method is...
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity)
Perform substitution on the type T with a given set of template arguments.
bool hasInClassInitializer() const
hasInClassInitializer - Determine whether this member has a C++11 in-class initializer.