29 using namespace clang;
56 bool RelativeToPrimary,
70 dyn_cast<VarTemplateSpecializationDecl>(D)) {
73 !isa<VarTemplatePartialSpecializationDecl>(Spec))
80 assert(Spec->getSpecializedTemplate() &&
"No variable template?");
86 if (Partial->isMemberSpecialization())
89 VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
103 = dyn_cast<TemplateTemplateParmDecl>(D)) {
104 for (
unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
114 = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
117 !isa<ClassTemplatePartialSpecializationDecl>(Spec))
124 assert(Spec->getSpecializedTemplate() &&
"No class template?");
125 if (Spec->getSpecializedTemplate()->isMemberSpecialization())
129 else if (
FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
130 if (!RelativeToPrimary &&
131 (Function->getTemplateSpecializationKind() ==
133 !Function->getClassScopeSpecializationPattern()))
137 = Function->getTemplateSpecializationArgs()) {
143 assert(Function->getPrimaryTemplate() &&
"No function template?");
144 if (Function->getPrimaryTemplate()->isMemberSpecialization())
152 = Function->getDescribedFunctionTemplate()) {
161 if (Function->getFriendObjectKind() &&
162 Function->getDeclContext()->isFileContext() &&
164 Ctx = Function->getLexicalDeclContext();
165 RelativeToPrimary =
false;
168 }
else if (
CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
170 QualType T = ClassTemplate->getInjectedClassNameSpecialization();
175 if (ClassTemplate->isMemberSpecialization())
181 RelativeToPrimary =
false;
189 case TemplateInstantiation:
190 case ExceptionSpecInstantiation:
191 case DefaultTemplateArgumentInstantiation:
192 case DefaultFunctionArgumentInstantiation:
193 case ExplicitTemplateArgumentSubstitution:
194 case DeducedTemplateArgumentSubstitution:
195 case PriorTemplateArgumentSubstitution:
198 case DefaultTemplateArgumentChecking:
199 case DeclaringSpecialMember:
200 case DefiningSynthesizedFunction:
204 llvm_unreachable(
"Invalid SynthesisKind!");
221 Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
234 AlreadyInstantiating =
246 PointOfInstantiation, InstantiationRange, Entity) {}
253 PointOfInstantiation, InstantiationRange, Entity) {}
263 Template, TemplateArgs) {}
272 InstantiationRange, FunctionTemplate, nullptr,
273 TemplateArgs, &DeductionInfo) {
287 PointOfInstantiation, InstantiationRange, Template, nullptr,
288 TemplateArgs, &DeductionInfo) {}
298 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
299 TemplateArgs, &DeductionInfo) {}
309 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
310 TemplateArgs, &DeductionInfo) {}
318 PointOfInstantiation, InstantiationRange, Param, nullptr,
328 PointOfInstantiation, InstantiationRange, Param, Template,
338 PointOfInstantiation, InstantiationRange, Param, Template,
347 PointOfInstantiation, InstantiationRange, Param, Template,
362 if (!Active.isInstantiationRecord()) {
372 "forgot to remove a lookup module for a template instantiation");
391 if (!AlreadyInstantiating) {
394 std::make_pair(Active.Entity, Active.Kind));
403 bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
413 SemaRef.
Diag(PointOfInstantiation,
414 diag::err_template_recursion_depth_exceeded)
416 << InstantiationRange;
417 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
429 SkipStart = Limit / 2 + Limit % 2;
434 unsigned InstantiationIdx = 0;
439 ++Active, ++InstantiationIdx) {
441 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
442 if (InstantiationIdx == SkipStart) {
445 diag::note_instantiation_contexts_suppressed)
451 switch (Active->Kind) {
453 Decl *D = Active->Entity;
455 unsigned DiagID = diag::note_template_member_class_here;
456 if (isa<ClassTemplateSpecializationDecl>(Record))
457 DiagID = diag::note_template_class_instantiation_here;
459 << Record << Active->InstantiationRange;
460 }
else if (
FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
462 if (Function->getPrimaryTemplate())
463 DiagID = diag::note_function_template_spec_here;
465 DiagID = diag::note_template_member_function_here;
468 << Active->InstantiationRange;
469 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
471 VD->isStaticDataMember()?
472 diag::note_template_static_data_member_def_here
473 : diag::note_template_variable_def_here)
475 << Active->InstantiationRange;
476 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
478 diag::note_template_enum_def_here)
480 << Active->InstantiationRange;
481 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
483 diag::note_template_nsdmi_here)
484 << FD << Active->InstantiationRange;
487 diag::note_template_type_alias_instantiation_here)
488 << cast<TypeAliasTemplateDecl>(D)
489 << Active->InstantiationRange;
495 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
497 llvm::raw_svector_ostream OS(TemplateArgsStr);
502 diag::note_default_arg_instantiation_here)
504 << Active->InstantiationRange;
511 diag::note_explicit_template_arg_substitution_here)
514 Active->TemplateArgs,
515 Active->NumTemplateArgs)
516 << Active->InstantiationRange;
522 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
524 diag::note_function_template_deduction_instantiation_here)
527 Active->TemplateArgs,
528 Active->NumTemplateArgs)
529 << Active->InstantiationRange;
531 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
532 isa<VarTemplateSpecializationDecl>(Active->Entity);
533 bool IsTemplate =
false;
535 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
537 Params = D->getTemplateParameters();
538 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
540 Params = D->getTemplateParameters();
541 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
543 Params = D->getTemplateParameters();
545 llvm_unreachable(
"unexpected template kind");
549 diag::note_deduced_template_arg_substitution_here)
550 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
552 Active->NumTemplateArgs)
553 << Active->InstantiationRange;
559 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
563 llvm::raw_svector_ostream OS(TemplateArgsStr);
568 diag::note_default_function_arg_instantiation_here)
570 << Active->InstantiationRange;
575 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
578 Name = std::string(
" '") + Parm->
getName().str() +
"'";
581 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
582 TemplateParams = Template->getTemplateParameters();
585 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
586 ->getTemplateParameters();
588 diag::note_prior_template_arg_substitution)
589 << isa<TemplateTemplateParmDecl>(Parm)
592 Active->TemplateArgs,
593 Active->NumTemplateArgs)
594 << Active->InstantiationRange;
600 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
601 TemplateParams = Template->getTemplateParameters();
604 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
605 ->getTemplateParameters();
608 diag::note_template_default_arg_checking)
610 Active->TemplateArgs,
611 Active->NumTemplateArgs)
612 << Active->InstantiationRange;
618 diag::note_template_exception_spec_instantiation_here)
619 << cast<FunctionDecl>(Active->Entity)
620 << Active->InstantiationRange;
625 diag::note_in_declaration_of_implicit_special_member)
626 << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
631 auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity);
635 diag::note_member_synthesized_at)
653 switch (Active->Kind) {
657 if (isa<TypeAliasTemplateDecl>(Active->Entity))
677 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
678 return Active->DeductionInfo;
689 if (Active->SavedInNonInstantiationSFINAEContext)
697 static std::pair<unsigned, unsigned>
700 return std::make_pair(TTP->getDepth(), TTP->getIndex());
703 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
713 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
721 TemplateInstantiator(
Sema &SemaRef,
725 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
745 this->Entity = Entity;
751 bool &ShouldExpand,
bool &RetainExpansion,
753 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
754 PatternRange, Unexpanded,
761 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
771 unsigned Depth, Index;
774 Result = TemplateArgs(Depth, Index);
790 unsigned Depth, Index;
800 void transformAttrs(
Decl *Old,
Decl *New) {
804 void transformedLocalDecl(
Decl *Old,
Decl *New) {
811 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
812 NewTD->setInstantiatedFromMemberTemplate(
813 OldMD->getDescribedFunctionTemplate());
823 if (
auto *DC = dyn_cast<DeclContext>(Old))
859 NamedDecl *FirstQualifierInScope =
nullptr,
860 bool AllowInjectedClassName =
false);
862 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
870 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
888 return inherited::TransformFunctionProtoType(TLB, TL);
891 template<
typename Fn>
895 unsigned ThisTypeQuals,
896 Fn TransformExceptionSpec);
901 bool ExpectParameterPack);
921 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
925 Owner, TemplateArgs);
935 bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
942 getSema().MarkDeclarationsReferencedInType(Loc, T);
951 if (Arg.isPackExpansion())
961 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
966 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
972 if (TTP->isParameterPack()) {
974 "Missing argument pack");
980 "Wrong kind of template template argument");
992 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
996 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1001 TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *D,
1007 = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
1009 if (TTP->
getDepth() < TemplateArgs.getNumLevels()) {
1015 "Missing argument pack");
1017 if (getSema().ArgumentPackSubstitutionIndex == -1)
1025 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1028 return Tag->getDecl();
1031 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
1036 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1040 TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
1045 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
1046 StartLoc, NameLoc, Name);
1048 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1052 VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
1055 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1057 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1062 TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
1079 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
1094 TemplateName TemplateInstantiator::TransformTemplateName(
1097 bool AllowInjectedClassName) {
1100 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1105 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1106 TTP->getPosition()))
1111 if (TTP->isParameterPack()) {
1113 "Missing argument pack");
1115 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1119 return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
1126 assert(!Template.
isNull() &&
"Null template template argument");
1128 "template decl to substitute is qualified?");
1130 Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template);
1137 if (getSema().ArgumentPackSubstitutionIndex == -1)
1145 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1146 FirstQualifierInScope,
1147 AllowInjectedClassName);
1151 TemplateInstantiator::TransformPredefinedExpr(
PredefinedExpr *E) {
1159 TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *E,
1165 if (!TemplateArgs.hasTemplateArgument(NTTP->
getDepth(),
1171 if (TemplateArgs.getNumLevels() != TemplateArgs.getNumSubstitutedLevels()) {
1179 "unexpected pack arguments in partial substitution");
1183 "unexpected nontype template argument kind in partial substitution");
1189 "Missing argument pack");
1191 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1210 return transformNonTypeTemplateParmRef(NTTP, E->
getLocation(), Arg);
1213 const LoopHintAttr *
1214 TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
1215 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).
get();
1217 if (TransformedExpr == LH->getValue())
1221 if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
1226 return LoopHintAttr::CreateImplicit(
1227 getSema().
Context, LH->getSemanticSpelling(), LH->getOption(),
1228 LH->getState(), TransformedExpr, LH->getRange());
1231 ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1253 VD = cast_or_null<ValueDecl>(
1254 getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1267 isa<PackExpansionType>(parm->
getType())) {
1269 cast<PackExpansionType>(parm->
getType())->getPattern(),
1275 assert(!type.
isNull() &&
"type substitution failed for param type");
1279 if (!result.isInvalid()) type = result.get()->getType();
1289 Expr *resultExpr = result.
get();
1291 type, resultExpr->
getValueKind(), loc, parm, resultExpr);
1295 TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1310 TemplateInstantiator::RebuildParmVarDeclRefExpr(
ParmVarDecl *PD,
1313 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
1324 return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(VD), E->
getExprLoc());
1338 cast_or_null<ParmVarDecl>(TransformDecl(E->
getExprLoc(), *I));
1350 TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *E,
1353 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1354 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1355 assert(Found &&
"no instantiation for parameter pack");
1357 Decl *TransformedDecl;
1358 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1369 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1371 TransformedDecl = Found->get<
Decl*>();
1375 return RebuildParmVarDeclRefExpr(cast<ParmVarDecl>(TransformedDecl),
1380 TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *E) {
1386 if (NTTP->
getDepth() < TemplateArgs.getNumLevels())
1387 return TransformTemplateParmRefExpr(E, NTTP);
1396 return TransformFunctionParmPackRefExpr(E, PD);
1401 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1404 getDescribedFunctionTemplate() &&
1405 "Default arg expressions are never formed in dependent cases.");
1411 template<
typename Fn>
1415 unsigned ThisTypeQuals,
1416 Fn TransformExceptionSpec) {
1419 return inherited::TransformFunctionProtoType(
1420 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1424 TemplateInstantiator::TransformFunctionTypeParam(
ParmVarDecl *OldParm,
1425 int indexAdjustment,
1427 bool ExpectParameterPack) {
1429 NumExpansions, ExpectParameterPack);
1433 TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
1436 if (T->
getDepth() < TemplateArgs.getNumLevels()) {
1455 "Missing argument pack");
1457 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1462 = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg);
1473 "Template argument kind mismatch");
1479 = getSema().Context.getSubstTemplateTypeParmType(T, Replacement);
1492 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
1504 TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
1519 Result = getSema().Context.getSubstTemplateTypeParmType(
1562 bool AllowDeducedTST) {
1564 "Cannot perform an instantiation without some context on the " 1565 "instantiation stack");
1571 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1572 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
1573 : Instantiator.TransformType(T);
1581 "Cannot perform an instantiation without some context on the " 1582 "instantiation stack");
1596 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1611 "Cannot perform an instantiation without some context on the " 1612 "instantiation stack");
1619 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
1620 return Instantiator.TransformType(T);
1654 unsigned ThisTypeQuals) {
1656 "Cannot perform an instantiation without some context on the " 1657 "instantiation stack");
1662 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
1678 Result = Instantiator.TransformFunctionProtoType(
1679 TLB, Proto, ThisContext, ThisTypeQuals,
1681 bool &Changed) {
return false; });
1683 Result = Instantiator.TransformType(TLB, TL);
1697 bool Changed =
false;
1698 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
1699 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
1710 ESI, ExceptionStorage, Args))
1719 int indexAdjustment,
1721 bool ExpectParameterPack) {
1730 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
1741 }
else if (ExpectParameterPack) {
1747 diag::err_function_parameter_pack_without_parameter_packs)
1834 "Cannot perform an instantiation without some context on the " 1835 "instantiation stack");
1837 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
1839 return Instantiator.TransformFunctionTypeParams(
1840 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
1853 bool Invalid =
false;
1855 for (
const auto &
Base : Pattern->
bases()) {
1856 if (!
Base.getType()->isDependentType()) {
1858 if (RD->isInvalidDecl())
1867 if (
Base.isPackExpansion()) {
1873 bool ShouldExpand =
false;
1874 bool RetainExpansion =
false;
1877 Base.getSourceRange(),
1879 TemplateArgs, ShouldExpand,
1888 for (
unsigned I = 0; I != *NumExpansions; ++I) {
1893 Base.getSourceRange().getBegin(),
1902 Base.getSourceRange(),
1904 Base.getAccessSpecifierAsWritten(),
1907 InstantiatedBases.push_back(InstantiatedBase);
1916 EllipsisLoc =
Base.getEllipsisLoc();
1920 Base.getSourceRange().getBegin(),
1925 Base.getSourceRange().getBegin(),
1936 Base.getSourceRange(),
1938 Base.getAccessSpecifierAsWritten(),
1941 InstantiatedBases.push_back(InstantiatedBase);
1995 Pattern, PatternDef, TSK, Complain))
1997 Pattern = PatternDef;
2003 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2005 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
2006 Spec->setTemplateSpecializationKind(TSK);
2007 Spec->setPointOfInstantiation(PointOfInstantiation);
2015 "instantiating class definition");
2033 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
2058 for (
auto *Member : Pattern->
decls()) {
2068 if (Member->getDeclContext() != Pattern)
2071 if (Member->isInvalidDecl()) {
2076 Decl *NewMember = Instantiator.
Visit(Member);
2078 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
2079 Fields.push_back(Field);
2080 }
else if (
EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
2086 Enum->isCompleteDefinition()) {
2088 assert(MSInfo &&
"no spec info for member enum specialization");
2093 if (SA->isFailed()) {
2122 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
2123 E = LateAttrs.end(); I != E; ++I) {
2136 I->NewDecl->addAttr(NewAttr);
2164 P->first,
P->second)) {
2177 P->first,
P->second)) {
2221 Pattern, PatternDef, TSK,
true))
2223 Pattern = PatternDef;
2229 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2238 "instantiating enum definition");
2288 "pattern and instantiation disagree about init style");
2296 Diag(PointOfInstantiation,
2297 diag::err_in_class_initializer_not_yet_parsed)
2298 << OutermostClass << Pattern;
2299 Diag(Pattern->getLocEnd(), diag::note_in_class_initializer_not_yet_parsed);
2309 Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle)
2314 "instantiating default member init");
2330 Expr *Init = NewInit.get();
2331 assert((!Init || !isa<ParenListExpr>(Init)) &&
"call-style init in class");
2336 L->DefaultMemberInitializerInstantiated(Instantiation);
2345 struct PartialSpecMatchResult {
2360 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2393 typedef PartialSpecMatchResult MatchResult;
2398 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2410 Matched.push_back(PartialSpecMatchResult());
2411 Matched.back().Partial = Partial;
2412 Matched.back().Args = Info.take();
2420 if (Matched.size() >= 1) {
2422 if (Matched.size() == 1) {
2435 PEnd = Matched.end();
2438 P->Partial, Best->Partial, PointOfInstantiation) ==
P->Partial)
2444 bool Ambiguous =
false;
2446 PEnd = Matched.end();
2450 PointOfInstantiation) !=
2461 S.
Diag(PointOfInstantiation, diag::err_partial_spec_ordering_ambiguous)
2462 << ClassTemplateSpec;
2466 PEnd = Matched.end();
2468 S.
Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
2470 P->Partial->getTemplateParameters(), *
P->Args);
2487 Pattern = OrigPartialSpec;
2513 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
2519 *
this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain);
2543 "Unexpected template specialization kind!");
2544 for (
auto *D : Instantiation->
decls()) {
2545 bool SuppressNew =
false;
2546 if (
auto *Function = dyn_cast<FunctionDecl>(D)) {
2548 = Function->getInstantiatedFromMemberFunction()) {
2550 = Function->getMemberSpecializationInfo();
2551 assert(MSInfo &&
"No member specialization information?");
2573 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2575 if (Function->isDefined()) {
2583 std::make_pair(Function, PointOfInstantiation));
2586 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
2587 if (isa<VarTemplateSpecializationDecl>(Var))
2590 if (Var->isStaticDataMember()) {
2592 assert(MSInfo &&
"No member specialization information?");
2612 if (!Var->getInstantiatedFromStaticDataMember()->getDefinition())
2615 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2618 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2621 }
else if (
auto *Record = dyn_cast<CXXRecordDecl>(D)) {
2627 if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
2632 assert(MSInfo &&
"No member specialization information?");
2655 assert(Pattern &&
"Missing instantiated-from-template information");
2657 if (!Record->getDefinition()) {
2678 Record->getTemplateSpecializationKind() ==
2680 Record->setTemplateSpecializationKind(TSK);
2685 Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
2689 }
else if (
auto *Enum = dyn_cast<EnumDecl>(D)) {
2691 assert(MSInfo &&
"No member specialization information?");
2698 PointOfInstantiation, TSK, Enum,
2704 if (Enum->getDefinition())
2707 EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
2708 assert(Pattern &&
"Missing instantiated-from-template information");
2714 InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
2719 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
2726 ClassPattern->
lookup(Field->getDeclName());
2761 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2764 return Instantiator.TransformStmt(S);
2772 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2775 return Instantiator.TransformExpr(E);
2780 bool CXXDirectInit) {
2781 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2784 return Instantiator.TransformInitializer(Init, CXXDirectInit);
2793 TemplateInstantiator Instantiator(*
this, TemplateArgs,
2796 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
2806 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
2808 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
2815 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
2817 return Instantiator.TransformDeclarationNameInfo(NameInfo);
2824 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
2827 SS.
Adopt(QualifierLoc);
2828 return Instantiator.TransformTemplateName(SS, Name, Loc);
2834 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
2837 return Instantiator.TransformTemplateArguments(Args, NumArgs, Result);
2845 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
2846 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
2847 unsigned i = PV->getFunctionScopeIndex();
2850 if (FD->getParamDecl(i) == PV)
2858 llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
2862 Current = Current->Outer) {
2865 const Decl *CheckD = D;
2867 LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
2868 if (Found != Current->LocalDecls.end())
2869 return &Found->second;
2873 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
2880 if (!Current->CombineWithOuterScope)
2886 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
2887 isa<TemplateTemplateParmDecl>(D))
2892 if (RD->isLocalClass())
2897 if (isa<EnumDecl>(D))
2903 assert(isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
2909 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2910 if (Stored.isNull()) {
2914 while (Current->CombineWithOuterScope && Current->Outer) {
2915 Current = Current->Outer;
2916 assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
2917 "Instantiated local in inner and outer scopes");
2922 Pack->push_back(cast<ParmVarDecl>(Inst));
2924 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
2932 Pack->push_back(Inst);
2939 Current && Current->CombineWithOuterScope; Current = Current->Outer)
2940 assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
2941 "Creating local pack after instantiation of local");
2945 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2948 ArgumentPacks.push_back(Pack);
2953 unsigned NumExplicitArgs) {
2954 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
2955 "Already have a partially-substituted pack");
2956 assert((!PartiallySubstitutedPack
2957 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
2958 "Wrong number of arguments in partially-substituted pack");
2959 PartiallySubstitutedPack = Pack;
2960 ArgsInPartiallySubstitutedPack = ExplicitArgs;
2961 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
2966 unsigned *NumExplicitArgs)
const {
2968 *ExplicitArgs =
nullptr;
2969 if (NumExplicitArgs)
2970 *NumExplicitArgs = 0;
2973 Current = Current->Outer) {
2974 if (Current->PartiallySubstitutedPack) {
2976 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
2977 if (NumExplicitArgs)
2978 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
2980 return Current->PartiallySubstitutedPack;
2983 if (!Current->CombineWithOuterScope)
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
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.
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic...
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 ...
We are defining a synthesized function (such as a defaulted special member).
An instance of this class is created to represent a function declaration or definition.
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
no exception specification
const TypeClass * getTypePtr() const
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
A (possibly-)qualified type.
TemplateDeductionResult
Describes the result of template argument deduction.
void InstantiatedLocal(const Decl *D, Decl *Inst)
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
SourceRange getBraceRange() const
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
Decl * Entity
The entity that is being synthesized.
bool isMemberSpecialization()
Determines whether this class template partial specialization template was a specialization of a memb...
Stmt - This represents one statement.
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
Provides information about an attempted template argument deduction, whose success or failure was des...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed...
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...
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
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()
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation. ...
const RecordDecl * getParent() const
getParent - Returns the parent of this field declaration, which is the struct in which this field is ...
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...
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)
const TargetInfo & getTargetInfo() const
A container of type source information.
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...
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, NamedDecl *Instantiation, bool InstantiatedFromMember, const NamedDecl *Pattern, const NamedDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
We are instantiating a default argument for a template parameter.
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
TemplateTypeParmDecl * getDecl() const
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 CodeSynthesisContexts that are not template instantiations and, therefore, should not be counted as part of the instantiation depth.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given variable from its template.
LocalInstantiationScope * getStartingScope() 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).
unsigned getDepth() const
Get the nesting depth of the template parameter.
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
const T * getAs() const
Member-template getAs<specific type>'.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy.
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.
bool hasInheritedDefaultArg() const
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Represents a variable template specialization, which refers to a variable template with a given set o...
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
ParmVarDecl - Represents a parameter to a function.
QualType getIntegralType() const
Retrieve the type of the integral value.
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
bool isLexicallyWithinFunctionOrMethod() const
Returns true if this declaration lexically is inside a function.
Base wrapper for a particular "section" of type source info.
RecordDecl - Represents a struct/union/class.
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
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...
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
TemplateName getNameToSubstitute() const
Get the template name to substitute when this template name is used as a template template argument...
Expr * getAsExpr() const
Retrieve the template argument as an expression.
void setUninstantiatedDefaultArg(Expr *arg)
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.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
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...
The current expression is potentially evaluated at run time, which means that code may be generated t...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation, for substitutions of prior template arguments.
void startDefinition()
Starts the definition of this tag declaration.
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
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)
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()
QualType getParamTypeForDecl() const
Describes a module or submodule.
We are instantiating the exception specification for a function template which was deferred until it ...
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
void setNameLoc(SourceLocation Loc)
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class...
TagKind getTagKind() const
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
A convenient class for passing around template argument information.
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
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...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Wrapper for substituted template type parameters.
unsigned LastEmittedCodeSynthesisContextDepth
The depth of the context stack at the point when the most recent error or warning was produced...
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class 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
Retrieves the "canonical" declaration of the given declaration.
const TemplateArgument * getArgs() const
Retrieve the template arguments.
bool hasUnparsedDefaultArg() const
hasUnparsedDefaultArg - Determines whether this parameter has a default argument that has not yet bee...
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
Represents a C++ nested-name-specifier or a global scope specifier.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
const LangOptions & getLangOpts() const
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.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
A default argument (C++ [dcl.fct.default]).
void setLocStart(SourceLocation L)
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
RAII object used to change the argument pack substitution index within a Sema object.
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.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
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)
We are substituting explicit template arguments provided for a function template. ...
Sema - This implements semantic analysis and AST building for C.
Represents a prototype with parameter type info, e.g.
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
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...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
SourceLocation getLocation() const
We are instantiating a template declaration.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
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.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
unsigned getFunctionScopeDepth() const
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.
StringRef getKindName() const
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
bool hasUncompilableErrorOccurred() const
Errors that actually prevent compilation, not those that are upgraded from a warning by -Werror...
const FunctionProtoType * T
Declaration of a template type parameter.
unsigned getIndex() const
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...
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
We are substituting template argument determined as part of template argument deduction for either a ...
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...
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
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...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isFileContext() const
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
DeclContext * getDeclContext()
CXXRecordDecl * getDefinition() const
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.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
EnumDecl * getDefinition() const
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
void CheckCompletedCXXClass(CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
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 setLocation(SourceLocation L)
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization, retrieves the member specialization information.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
SourceLocation getLocation() const
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
SourceLocation getLocEnd() const LLVM_READONLY
ParmVarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation. ...
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all otuer scopes, down to the given outermost scope. ...
virtual void printName(raw_ostream &os) const
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
void pushCodeSynthesisContext(CodeSynthesisContext Ctx)
We are declaring an implicit special member function.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
ExceptionSpecificationType Type
The kind of exception specification this is.
TypeLoc IgnoreParens() const
A stack object to be created when performing template instantiation.
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
ExtProtoInfo getExtProtoInfo() const
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
Encodes a location in the source.
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
void setBraceRange(SourceRange R)
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
A structure for storing an already-substituted template template parameter pack.
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
DeclarationName getName() const
getName - Returns the embedded declaration name.
TagDecl - Represents the declaration of a struct/union/class/enum.
TemplateArgument getArgumentPack() const
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
SynthesisKind
The kind of template instantiation we are performing.
Represents a static or instance method of a struct/union/class.
We are checking the validity of a default template argument that has been used when naming a template...
bool isParameterPack() const
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
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...
void setTagKind(TagKind TK)
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
bool hasUninstantiatedDefaultArg() const
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...
IdentType getIdentType() const
Represents a C++11 static_assert declaration.
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...
ArrayRef< ParmVarDecl * > getParams() const
unsigned getFullDataSize() const
Returns the size of the type source info data block.
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
ParmVarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
void setHasInheritedDefaultArg(bool I=true)
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
getSpecialMember - get the special member enum for a method.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
SourceLocation getLocation() const
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.
Represents a reference to a function parameter pack that has been substituted but not yet expanded...
Represents a template argument.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
TagTypeKind
The kind of a tag type.
bool isNull() const
Determine whether this template name is NULL.
Dataflow Directional Tag Classes.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
[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...
The base class of all kinds of template declarations (e.g., class, function, etc.).
ASTMutationListener * getASTMutationListener() const
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.
We are instantiating a default argument for a function.
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...
This template specialization was instantiated from a template due to an explicit instantiation declar...
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
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.
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
EnumDecl - Represents an enum.
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
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...
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
bool isNull() const
Determine whether this template argument has no value.
Location wrapper for a TemplateArgument.
unsigned getNumArgs() const
Retrieve the number of template arguments.
void setUnparsedDefaultArg()
setUnparsedDefaultArg - Specify that this parameter has an unparsed default argument.
Expr * getUninstantiatedDefaultArg()
This template specialization was declared or defined by an explicit specialization (C++ [temp...
static std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a parameter pack.
TypeSourceInfo * getTypeSourceInfo() const
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.
Represents a base class of a C++ class.
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
A template argument list.
bool hasFatalErrorOccurred() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
ArgKind getKind() const
Return the kind of stored template argument.
unsigned getDepth() const
TranslationUnitDecl * getTranslationUnitDecl() const
Represents a C++ struct/union/class.
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier *> Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
void popCodeSynthesisContext()
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...
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...
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
SourceLocation getNameLoc() const
We are substituting prior template arguments into a new template parameter.
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, ParmVarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< ParmVarDecl *> Params)
const ParmVarDecl * getParam() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getAsType() const
Retrieve the type for a type template argument.
A reference to a declared variable, function, enum, etc.
Represents a type template specialization; the template must be a class template, a type alias templa...
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, bool AllowDeducedTST=false)
Perform substitution on the type T with a given set of template arguments.
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
ParmVarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Wrapper for template type parameters.
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
bool isTranslationUnit() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
NamedDecl * getAsNamedDecl(TemplateParameter P)
No keyword precedes the qualified type name.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl *> Fields, SourceLocation LBrac, SourceLocation RBrac, AttributeList *AttrList)
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...
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
SourceLocation getLocStart() const LLVM_READONLY
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
ExceptionSpecInfo ExceptionSpec
Declaration of a template function.
Attr - This represents one attribute.
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
static CXXRecordDecl * getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...