38#include "llvm/ADT/ScopeExit.h"
39#include "llvm/ADT/StringExtras.h"
40#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/TimeProfiler.h"
54 const Decl *NextDecl =
nullptr;
56 bool ClearRelativeToPrimary =
true;
57 static Response Done() {
62 static Response ChangeDecl(
const Decl *ND) {
67 static Response ChangeDecl(
const DeclContext *Ctx) {
73 static Response UseNextDecl(
const Decl *CurDecl) {
77 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
78 Response R = Response::UseNextDecl(CurDecl);
79 R.ClearRelativeToPrimary =
false;
87 bool SkipForSpecialization) {
91 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
95 !isa<VarTemplatePartialSpecializationDecl>(VarTemplSpec))
96 return Response::Done();
101 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
105 if (!SkipForSpecialization)
106 Result.addOuterTemplateArguments(
109 if (Partial->isMemberSpecialization())
110 return Response::Done();
113 if (!SkipForSpecialization)
114 Result.addOuterTemplateArguments(
118 return Response::Done();
120 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
132 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
133 Result.addOuterTemplateArguments(std::nullopt);
134 return Response::Done();
137Response HandlePartialClassTemplateSpec(
140 if (!SkipForSpecialization)
142 return Response::Done();
149 bool SkipForSpecialization) {
153 !isa<ClassTemplatePartialSpecializationDecl>(ClassTemplSpec))
154 return Response::Done();
156 if (!SkipForSpecialization)
157 Result.addOuterTemplateArguments(
166 return Response::Done();
174 return Response::ChangeDecl(InstFromPartialTempl->getLexicalDeclContext());
176 return Response::UseNextDecl(ClassTemplSpec);
182 bool ForConstraintInstantiation) {
184 if (!RelativeToPrimary &&
185 Function->getTemplateSpecializationKindForInstantiation() ==
187 return Response::Done();
189 if (!RelativeToPrimary &&
194 return Response::UseNextDecl(Function);
196 Function->getTemplateSpecializationArgs()) {
198 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
199 TemplateArgs->asArray(),
204 assert(Function->getPrimaryTemplate() &&
"No function template?");
205 if (Function->getPrimaryTemplate()->isMemberSpecialization())
206 return Response::Done();
209 if (!ForConstraintInstantiation &&
211 return Response::Done();
213 }
else if (Function->getDescribedFunctionTemplate()) {
215 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
216 "Outer template not instantiated?");
222 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
223 Function->getNonTransparentDeclContext()->isFileContext() &&
225 return Response::ChangeDecl(Function->getLexicalDeclContext());
227 return Response::UseNextDecl(Function);
232 if (!isa<ClassTemplateSpecializationDecl>(FTD->
getDeclContext())) {
233 Result.addOuterTemplateArguments(
243 Result.addOuterTemplateArguments(
258 bool ForConstraintInstantiation) {
261 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
262 "Outer template not instantiated?");
263 if (ClassTemplate->isMemberSpecialization())
264 return Response::Done();
265 if (ForConstraintInstantiation)
266 Result.addOuterTemplateArguments(
const_cast<CXXRecordDecl *
>(Rec),
267 ClassTemplate->getInjectedTemplateArgs(),
274 return Response::Done();
279 if (ForConstraintInstantiation && IsFriend &&
288 return Response::ChangeDecl(LCD);
290 return Response::UseNextDecl(Rec);
293Response HandleImplicitConceptSpecializationDecl(
296 Result.addOuterTemplateArguments(
300 return Response::UseNextDecl(CSD);
303Response HandleGenericDeclContext(
const Decl *CurDecl) {
304 return Response::UseNextDecl(CurDecl);
336 bool ForConstraintInstantiation,
bool SkipForSpecialization) {
337 assert(ND &&
"Can't find arguments for a decl if one isn't provided");
342 const Decl *CurDecl = ND;
346 CurDecl = Response::UseNextDecl(ND).NextDecl;
351 if (
const auto *VarTemplSpec =
352 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
353 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
354 }
else if (
const auto *PartialClassTemplSpec =
355 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
356 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
357 SkipForSpecialization);
358 }
else if (
const auto *ClassTemplSpec =
359 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
360 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
361 SkipForSpecialization);
362 }
else if (
const auto *Function = dyn_cast<FunctionDecl>(CurDecl)) {
363 R = HandleFunction(Function,
Result, Pattern, RelativeToPrimary,
364 ForConstraintInstantiation);
365 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
366 R = HandleRecordDecl(Rec,
Result,
Context, ForConstraintInstantiation);
367 }
else if (
const auto *CSD =
368 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
369 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
370 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
371 R = HandleFunctionTemplateDecl(FTD,
Result);
372 }
else if (!isa<DeclContext>(CurDecl)) {
373 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
375 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
376 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
380 R = HandleGenericDeclContext(CurDecl);
385 if (R.ClearRelativeToPrimary)
386 RelativeToPrimary =
false;
388 CurDecl = R.NextDecl;
430 llvm_unreachable(
"Invalid SynthesisKind!");
460 AlreadyInstantiating = !Inst.Entity ?
false :
462 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
473 PointOfInstantiation, InstantiationRange, Entity) {}
480 PointOfInstantiation, InstantiationRange, Entity) {}
490 Template, TemplateArgs) {}
500 TemplateArgs, &DeductionInfo) {
514 PointOfInstantiation, InstantiationRange, Template, nullptr,
515 TemplateArgs, &DeductionInfo) {}
525 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
526 TemplateArgs, &DeductionInfo) {}
536 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
537 TemplateArgs, &DeductionInfo) {}
545 PointOfInstantiation, InstantiationRange, Param, nullptr,
555 PointOfInstantiation, InstantiationRange, Param, Template,
565 PointOfInstantiation, InstantiationRange, Param, Template,
574 PointOfInstantiation, InstantiationRange, Param, Template,
583 PointOfInstantiation, InstantiationRange, nullptr,
584 nullptr,
std::nullopt, &DeductionInfo) {
593 PointOfInstantiation, InstantiationRange, nullptr,
594 nullptr,
std::nullopt) {}
601 PointOfInstantiation, InstantiationRange, nullptr,
602 nullptr,
std::nullopt, &DeductionInfo) {
611 PointOfInstantiation, InstantiationRange, Template, nullptr,
620 PointOfInstantiation, InstantiationRange, Template, nullptr,
621 {}, &DeductionInfo) {}
629 PointOfInstantiation, InstantiationRange, Template) {}
637 PointOfInstantiation, InstantiationRange, Template) {}
644 PointOfInstantiation, InstantiationRange, Entity) {}
664 if (!Active.isInstantiationRecord()) {
674 "forgot to remove a lookup module for a template instantiation");
693 if (!AlreadyInstantiating) {
697 {Active.Entity->getCanonicalDecl(), Active.Kind});
711 llvm::raw_string_ostream
OS(
Result);
712 llvm::ListSeparator Comma;
713 for (
const Expr *Arg : Args) {
715 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
721bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
731 SemaRef.
Diag(PointOfInstantiation,
732 diag::err_template_recursion_depth_exceeded)
734 << InstantiationRange;
735 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
747 SkipStart = Limit / 2 + Limit % 2;
752 unsigned InstantiationIdx = 0;
757 ++Active, ++InstantiationIdx) {
759 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
760 if (InstantiationIdx == SkipStart) {
763 diag::note_instantiation_contexts_suppressed)
769 switch (Active->Kind) {
771 Decl *D = Active->Entity;
773 unsigned DiagID = diag::note_template_member_class_here;
774 if (isa<ClassTemplateSpecializationDecl>(Record))
775 DiagID = diag::note_template_class_instantiation_here;
777 << Record << Active->InstantiationRange;
778 }
else if (
FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
780 if (Function->getPrimaryTemplate())
781 DiagID = diag::note_function_template_spec_here;
783 DiagID = diag::note_template_member_function_here;
786 << Active->InstantiationRange;
787 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
789 VD->isStaticDataMember()?
790 diag::note_template_static_data_member_def_here
791 : diag::note_template_variable_def_here)
793 << Active->InstantiationRange;
794 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
796 diag::note_template_enum_def_here)
798 << Active->InstantiationRange;
799 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
801 diag::note_template_nsdmi_here)
802 << FD << Active->InstantiationRange;
805 diag::note_template_type_alias_instantiation_here)
806 << cast<TypeAliasTemplateDecl>(D)
807 << Active->InstantiationRange;
813 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
815 llvm::raw_svector_ostream
OS(TemplateArgsStr);
820 diag::note_default_arg_instantiation_here)
822 << Active->InstantiationRange;
829 diag::note_explicit_template_arg_substitution_here)
832 Active->TemplateArgs,
833 Active->NumTemplateArgs)
834 << Active->InstantiationRange;
840 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
842 diag::note_function_template_deduction_instantiation_here)
845 Active->TemplateArgs,
846 Active->NumTemplateArgs)
847 << Active->InstantiationRange;
849 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
850 isa<VarTemplateSpecializationDecl>(Active->Entity);
851 bool IsTemplate =
false;
853 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
855 Params = D->getTemplateParameters();
856 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
858 Params = D->getTemplateParameters();
859 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
861 Params = D->getTemplateParameters();
863 llvm_unreachable(
"unexpected template kind");
867 diag::note_deduced_template_arg_substitution_here)
868 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
870 Active->NumTemplateArgs)
871 << Active->InstantiationRange;
877 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
881 llvm::raw_svector_ostream
OS(TemplateArgsStr);
886 diag::note_default_function_arg_instantiation_here)
888 << Active->InstantiationRange;
893 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
896 Name = std::string(
" '") + Parm->
getName().str() +
"'";
899 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
900 TemplateParams = Template->getTemplateParameters();
903 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
904 ->getTemplateParameters();
906 diag::note_prior_template_arg_substitution)
907 << isa<TemplateTemplateParmDecl>(Parm)
910 Active->TemplateArgs,
911 Active->NumTemplateArgs)
912 << Active->InstantiationRange;
918 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
919 TemplateParams = Template->getTemplateParameters();
922 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
923 ->getTemplateParameters();
926 diag::note_template_default_arg_checking)
928 Active->TemplateArgs,
929 Active->NumTemplateArgs)
930 << Active->InstantiationRange;
936 diag::note_evaluating_exception_spec_here)
937 << cast<FunctionDecl>(Active->Entity);
942 diag::note_template_exception_spec_instantiation_here)
943 << cast<FunctionDecl>(Active->Entity)
944 << Active->InstantiationRange;
949 diag::note_template_requirement_instantiation_here)
950 << Active->InstantiationRange;
954 diag::note_template_requirement_params_instantiation_here)
955 << Active->InstantiationRange;
960 diag::note_nested_requirement_here)
961 << Active->InstantiationRange;
966 diag::note_in_declaration_of_implicit_special_member)
967 << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
972 diag::note_in_declaration_of_implicit_equality_comparison);
978 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
982 auto *MD = cast<CXXMethodDecl>(FD);
984 diag::note_member_synthesized_at)
990 .getNonReferenceType()
991 .getUnqualifiedType();
993 diag::note_comparison_synthesized_at)
1001 diag::note_rewriting_operator_as_spaceship);
1006 diag::note_in_binding_decl_init)
1007 << cast<BindingDecl>(Active->Entity);
1012 diag::note_due_to_dllexported_class)
1013 << cast<CXXRecordDecl>(Active->Entity) << !
getLangOpts().CPlusPlus11;
1018 diag::note_building_builtin_dump_struct_call)
1028 diag::note_lambda_substitution_here);
1031 unsigned DiagID = 0;
1032 if (!Active->Entity) {
1034 diag::note_nested_requirement_here)
1035 << Active->InstantiationRange;
1038 if (isa<ConceptDecl>(Active->Entity))
1039 DiagID = diag::note_concept_specialization_here;
1040 else if (isa<TemplateDecl>(Active->Entity))
1041 DiagID = diag::note_checking_constraints_for_template_id_here;
1042 else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
1043 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1044 else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
1045 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1047 assert(isa<FunctionDecl>(Active->Entity));
1048 DiagID = diag::note_checking_constraints_for_function_here;
1051 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1053 if (!isa<FunctionDecl>(Active->Entity)) {
1057 Diags.
Report(Active->PointOfInstantiation, DiagID) <<
OS.str()
1058 << Active->InstantiationRange;
1063 diag::note_constraint_substitution_here)
1064 << Active->InstantiationRange;
1068 diag::note_constraint_normalization_here)
1069 << cast<NamedDecl>(Active->Entity)->getName()
1070 << Active->InstantiationRange;
1074 diag::note_parameter_mapping_substitution_here)
1075 << Active->InstantiationRange;
1078 llvm_unreachable(
"unexpected deduction guide in instantiation stack");
1085 return std::optional<TemplateDeductionInfo *>(
nullptr);
1090 Active != ActiveEnd;
1093 switch (Active->Kind) {
1097 if (isa<TypeAliasTemplateDecl>(Active->Entity))
1107 return std::nullopt;
1114 return std::nullopt;
1136 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1137 return Active->DeductionInfo;
1148 return std::nullopt;
1162 if (Active->SavedInNonInstantiationSFINAEContext)
1163 return std::optional<TemplateDeductionInfo *>(
nullptr);
1166 return std::nullopt;
1173 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1177 bool EvaluateConstraints =
true;
1182 TemplateInstantiator(
Sema &SemaRef,
1185 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1188 void setEvaluateConstraints(
bool B) {
1189 EvaluateConstraints = B;
1191 bool getEvaluateConstraints() {
1192 return EvaluateConstraints;
1200 bool AlreadyTransformed(
QualType T);
1212 this->Entity = Entity;
1215 unsigned TransformTemplateDepth(
unsigned Depth) {
1220 int Index = getSema().ArgumentPackSubstitutionIndex;
1222 return std::nullopt;
1229 bool &ShouldExpand,
bool &RetainExpansion,
1230 std::optional<unsigned> &NumExpansions) {
1231 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
1232 PatternRange, Unexpanded,
1239 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
1249 unsigned Depth, Index;
1252 Result = TemplateArgs(Depth, Index);
1268 unsigned Depth, Index;
1278 void transformAttrs(
Decl *Old,
Decl *New) {
1285 for (
auto *New : NewDecls)
1287 Old, cast<VarDecl>(New));
1291 assert(NewDecls.size() == 1 &&
1292 "should only have multiple expansions for a pack");
1293 Decl *New = NewDecls.front();
1298 auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1300 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1301 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1302 NewTD->setInstantiatedFromMemberTemplate(
1303 OldMD->getDescribedFunctionTemplate());
1305 NewMD->setInstantiationOfMemberFunction(OldMD,
1313 if (
auto *DC = dyn_cast<DeclContext>(Old);
1314 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1350 NamedDecl *FirstQualifierInScope =
nullptr,
1351 bool AllowInjectedClassName =
false);
1353 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1354 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1356 const NoInlineAttr *A);
1357 const AlwaysInlineAttr *
1358 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1359 const AlwaysInlineAttr *A);
1367 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1369 ExprResult TransformSubstNonTypeTemplateParmExpr(
1386 return inherited::TransformFunctionProtoType(TLB, TL);
1389 template<
typename Fn>
1394 Fn TransformExceptionSpec);
1397 TransformFunctionTypeParam(
ParmVarDecl *OldParm,
int indexAdjustment,
1398 std::optional<unsigned> NumExpansions,
1399 bool ExpectParameterPack);
1401 using inherited::TransformTemplateTypeParmType;
1406 bool SuppressObjCLifetime);
1408 QualType BuildSubstTemplateTypeParmType(
1410 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
1416 using inherited::TransformSubstTemplateTypeParmPackType;
1420 bool SuppressObjCLifetime);
1433 ExprResult Result = inherited::TransformLambdaExpr(E);
1434 if (Result.isInvalid())
1439 assert(PVD &&
"null in a parameter list");
1440 if (!PVD->hasDefaultArg())
1442 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1451 { UninstExpr }, UninstExpr->
getType());
1453 PVD->setDefaultArg(ErrorResult.
get());
1462 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1465 assert(TransReq.
get() != E &&
1466 "Do not change value of isSatisfied for the existing expression. "
1467 "Create a new expression instead.");
1474 if (Trap.hasErrorOccurred())
1480 bool TransformRequiresExprRequirements(
1483 bool SatisfactionDetermined =
false;
1486 if (!SatisfactionDetermined) {
1487 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1488 TransReq = TransformTypeRequirement(TypeReq);
1489 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1490 TransReq = TransformExprRequirement(ExprReq);
1492 TransReq = TransformNestedRequirement(
1493 cast<concepts::NestedRequirement>(Req));
1502 SatisfactionDetermined =
true;
1505 Transformed.push_back(TransReq);
1512 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1516 Owner, TemplateArgs);
1517 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1518 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1536 transformNonTypeTemplateParmRef(
Decl *AssociatedDecl,
1539 std::optional<unsigned> PackIndex);
1543bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
1550 getSema().MarkDeclarationsReferencedInType(Loc, T);
1575 TTP->getPosition()))
1580 if (TTP->isParameterPack()) {
1582 "Missing argument pack");
1588 "Wrong kind of template template argument");
1600 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
1604 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1609TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *D,
1623 "Missing argument pack");
1633 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1636 return Tag->getDecl();
1639 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
1644 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1648TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
1654 StartLoc, NameLoc, Name);
1656 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1660VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
1663 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1665 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1670TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
1687 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
1696 return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc, T);
1699TemplateName TemplateInstantiator::TransformTemplateName(
1702 bool AllowInjectedClassName) {
1704 = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1711 TTP->getPosition()))
1721 "unexpected pack arguments in template rewrite");
1725 "unexpected nontype template argument kind in template rewrite");
1729 auto [AssociatedDecl, Final] =
1731 std::optional<unsigned> PackIndex;
1734 "Missing argument pack");
1740 return getSema().Context.getSubstTemplateTemplateParmPack(
1741 Arg, AssociatedDecl, TTP->
getIndex(), Final);
1744 PackIndex = getPackIndex(Arg);
1749 assert(!Template.
isNull() &&
"Null template template argument");
1751 "template decl to substitute is qualified?");
1755 return getSema().Context.getSubstTemplateTemplateParm(
1756 Template, AssociatedDecl, TTP->
getIndex(), PackIndex);
1761 = Name.getAsSubstTemplateTemplateParmPack()) {
1768 if (SubstPack->getFinal())
1770 return getSema().Context.getSubstTemplateTemplateParm(
1772 SubstPack->getIndex(), getPackIndex(Pack));
1775 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1776 FirstQualifierInScope,
1777 AllowInjectedClassName);
1781TemplateInstantiator::TransformPredefinedExpr(
PredefinedExpr *E) {
1789TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *E,
1806 "unexpected pack arguments in template rewrite");
1810 "unexpected nontype template argument kind in template rewrite");
1817 std::optional<unsigned> PackIndex;
1820 "Missing argument pack");
1840 PackIndex = getPackIndex(Arg);
1844 return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP, E->
getLocation(),
1849TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
1850 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
1852 if (TransformedExpr == LH->getValue())
1861 return LoopHintAttr::CreateImplicit(getSema().
Context, LH->getOption(),
1862 LH->getState(), TransformedExpr, *LH);
1864const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
1865 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
1871const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
1872 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
1879ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1882 std::optional<unsigned> PackIndex) {
1887 auto SubstParamType = [&] {
1894 T = cast<PackExpansionType>(T)->getPattern();
1898 bool refParam =
false;
1904 Expr *argExpr =
arg.getAsExpr();
1909 QualType paramType = SubstParamType();
1921 VD =
arg.getAsDecl();
1925 VD = cast_or_null<ValueDecl>(
1934 QualType paramType = VD ?
arg.getParamTypeForDecl() :
arg.getNullPtrType();
1935 assert(!paramType.
isNull() &&
"type substitution failed for param type");
1936 assert(!paramType->
isDependentType() &&
"param type still dependent");
1943 arg.getIntegralType()));
1949 Expr *resultExpr = result.
get();
1953 AssociatedDecl, parm->
getIndex(), PackIndex, refParam);
1957TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1967 return transformNonTypeTemplateParmRef(
1973TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
1976 if (!isa<ConstantExpr>(SubstReplacement.
get()))
2006 SubstReplacement.
get(), SugaredConverted,
2018 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
2029 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2051 getSema().MarkFunctionParmPackReferenced(PackExpr);
2056TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *E,
2059 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
2060 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2061 assert(Found &&
"no instantiation for parameter pack");
2063 Decl *TransformedDecl;
2064 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
2073 getSema().MarkFunctionParmPackReferenced(PackExpr);
2077 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
2079 TransformedDecl = Found->get<
Decl*>();
2083 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->
getExprLoc());
2087TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *E) {
2094 return TransformTemplateParmRefExpr(E, NTTP);
2101 if (
VarDecl *PD = dyn_cast<VarDecl>(D))
2103 return TransformFunctionParmPackRefExpr(E, PD);
2105 return inherited::TransformDeclRefExpr(E);
2108ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2111 getDescribedFunctionTemplate() &&
2112 "Default arg expressions are never formed in dependent cases.");
2118template<
typename Fn>
2123 Fn TransformExceptionSpec) {
2126 return inherited::TransformFunctionProtoType(
2127 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2130ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2132 std::optional<unsigned> NumExpansions,
bool ExpectParameterPack) {
2134 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2135 ExpectParameterPack, EvaluateConstraints);
2141QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2143 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
2149 if (SuppressObjCLifetime) {
2162 QualType Result = getSema().Context.getSubstTemplateTypeParmType(
2163 Replacement, AssociatedDecl, Index, PackIndex);
2171TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
2173 bool SuppressObjCLifetime) {
2197 "unexpected pack arguments in template rewrite");
2201 "unexpected nontype template argument kind in template rewrite");
2203 assert(isa<TemplateTypeParmType>(NewT) &&
2204 "type parm not rewritten to type parm");
2210 auto [AssociatedDecl, Final] =
2212 std::optional<unsigned> PackIndex;
2215 "Missing argument pack");
2221 QualType Result = getSema().Context.getSubstTemplateTypeParmPackType(
2222 AssociatedDecl, T->
getIndex(), Final, Arg);
2230 PackIndex = getPackIndex(Arg);
2235 "Template argument kind mismatch");
2237 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2248 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2258QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2260 bool SuppressObjCLifetime) {
2269 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2279 return BuildSubstTemplateTypeParmType(
2294 ErrorLoc = PDA.first;
2298 char *MessageBuf =
new (S.
Context)
char[Message.size()];
2299 std::copy(Message.begin(), Message.end(), MessageBuf);
2301 llvm::raw_svector_ostream
OS(Entity);
2303 char *EntityBuf =
new (S.
Context)
char[Entity.size()];
2304 std::copy(Entity.begin(), Entity.end(), EntityBuf);
2306 StringRef(EntityBuf, Entity.size()), ErrorLoc,
2307 StringRef(MessageBuf, Message.size())};
2314 llvm::raw_svector_ostream
OS(Entity);
2316 char *EntityBuf =
new (S.
Context)
char[Entity.size()];
2317 llvm::copy(Entity, EntityBuf);
2319 StringRef(EntityBuf, Entity.size()),
2320 Location, StringRef()};
2323ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2337 if (getDerived().TransformFunctionTypeParams(
2338 KWLoc, Params,
nullptr,
nullptr, PTypes,
2339 &TransParams, PInfos, &ErrorIdx) ||
2340 Trap.hasErrorOccurred()) {
2346 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2347 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2349 TransReqs, RBraceLoc);
2360 if (AlwaysRebuild())
2361 return RebuildTypeRequirement(
2371 if (TypeInst.isInvalid())
2374 if (!TransType || Trap.hasErrorOccurred())
2376 [&] (llvm::raw_ostream&
OS) {
2379 return RebuildTypeRequirement(TransType);
2389 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2398 if (ExprInst.isInvalid())
2401 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2404 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2409 TransExpr = TransExprRes.
get();
2412 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2414 if (RetReq.isEmpty())
2415 TransRetReq.emplace();
2416 else if (RetReq.isSubstitutionFailure())
2417 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2418 else if (RetReq.isTypeConstraint()) {
2420 RetReq.getTypeConstraintTemplateParameterList();
2424 if (TPLInst.isInvalid())
2429 [&] (llvm::raw_ostream&
OS) {
2430 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2435 TransRetReq.emplace(TPL);
2438 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2439 if (
Expr *E = TransExpr.dyn_cast<
Expr *>())
2441 std::move(*TransRetReq));
2442 return RebuildExprRequirement(
2448TemplateInstantiator::TransformNestedRequirement(
2453 if (AlwaysRebuild())
2473 if (ConstrInst.isInvalid())
2477 nullptr, {Req->getConstraintExpr()},
Result, TemplateArgs,
2480 TransConstraint =
Result[0];
2481 assert(!Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
2482 "by CheckConstraintSatisfaction.");
2488 if (TransConstraint.
isInvalid() || !TransConstraint.
get() ||
2491 llvm::raw_svector_ostream
OS(Entity);
2494 char *EntityBuf =
new (SemaRef.
Context)
char[Entity.size()];
2495 std::copy(Entity.begin(), Entity.end(), EntityBuf);
2497 SemaRef.
Context, StringRef(EntityBuf, Entity.size()), Satisfaction);
2500 SemaRef.
Context, TransConstraint.
get(), Satisfaction);
2538 bool AllowDeducedTST) {
2540 "Cannot perform an instantiation without some context on the "
2541 "instantiation stack");
2547 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2548 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
2549 : Instantiator.TransformType(T);
2557 "Cannot perform an instantiation without some context on the "
2558 "instantiation stack");
2572 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2587 "Cannot perform an instantiation without some context on the "
2588 "instantiation stack");
2595 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
2596 return Instantiator.TransformType(T);
2631 bool EvaluateConstraints) {
2633 "Cannot perform an instantiation without some context on the "
2634 "instantiation stack");
2639 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2640 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2656 Result = Instantiator.TransformFunctionProtoType(
2657 TLB, Proto, ThisContext, ThisTypeQuals,
2659 bool &Changed) {
return false; });
2661 Result = Instantiator.TransformType(TLB, TL);
2675 bool Changed =
false;
2676 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
2677 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
2688 ESI, ExceptionStorage, Args))
2697 struct GetContainedInventedTypeParmVisitor :
2698 public TypeVisitor<GetContainedInventedTypeParmVisitor,
2699 TemplateTypeParmDecl *> {
2700 using TypeVisitor<GetContainedInventedTypeParmVisitor,
2753 return VisitFunctionType(T);
2786 bool EvaluateConstraints) {
2790 if (!EvaluateConstraints) {
2816 int indexAdjustment, std::optional<unsigned> NumExpansions,
2817 bool ExpectParameterPack,
bool EvaluateConstraint) {
2826 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
2837 }
else if (ExpectParameterPack) {
2843 diag::err_function_parameter_pack_without_parameter_packs)
2867 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
2869 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
2874 if (Inst && !Inst->getTypeConstraint()) {
2944 "Cannot perform an instantiation without some context on the "
2945 "instantiation stack");
2947 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
2949 return Instantiator.TransformFunctionTypeParams(
2950 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
2969 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
2981 std::unique_ptr<LocalInstantiationScope> LIS;
2989 LIS = std::make_unique<LocalInstantiationScope>(*
this);
2992 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3014 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3047 for (
const auto &
Base : Pattern->
bases()) {
3048 if (!
Base.getType()->isDependentType()) {
3050 if (RD->isInvalidDecl())
3059 if (
Base.isPackExpansion()) {
3065 bool ShouldExpand =
false;
3066 bool RetainExpansion =
false;
3067 std::optional<unsigned> NumExpansions;
3069 Base.getSourceRange(),
3071 TemplateArgs, ShouldExpand,
3080 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3085 Base.getSourceRange().getBegin(),
3094 Base.getSourceRange(),
3096 Base.getAccessSpecifierAsWritten(),
3099 InstantiatedBases.push_back(InstantiatedBase);
3108 EllipsisLoc =
Base.getEllipsisLoc();
3112 Base.getSourceRange().getBegin(),
3117 Base.getSourceRange().getBegin(),
3128 Base.getSourceRange(),
3130 Base.getAccessSpecifierAsWritten(),
3133 InstantiatedBases.push_back(InstantiatedBase);
3187 Pattern, PatternDef, TSK, Complain))
3190 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3192 llvm::raw_string_ostream
OS(Name);
3198 Pattern = PatternDef;
3204 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3206 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3207 Spec->setTemplateSpecializationKind(TSK);
3208 Spec->setPointOfInstantiation(PointOfInstantiation);
3216 "instantiating class definition");
3234 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3260 bool MightHaveConstexprVirtualFunctions =
false;
3271 if (
Member->getDeclContext() != Pattern)
3278 if (isa<BlockDecl>(
Member) ||
3279 (isa<CXXRecordDecl>(
Member) && cast<CXXRecordDecl>(
Member)->isLambda()))
3282 if (
Member->isInvalidDecl()) {
3289 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3290 Fields.push_back(Field);
3291 }
else if (
EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3297 Enum->isCompleteDefinition()) {
3299 assert(MSInfo &&
"no spec info for member enum specialization");
3304 if (SA->isFailed()) {
3310 }
else if (
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3313 MightHaveConstexprVirtualFunctions =
true;
3334 if (ParsingClassDepth == 0)
3339 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3340 E = LateAttrs.end(); I != E; ++I) {
3345 auto *ND = cast<NamedDecl>(I->NewDecl);
3346 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3348 ND->isCXXInstanceMember());
3353 I->NewDecl->addAttr(NewAttr);
3382 P->first,
P->second)) {
3395 P->first,
P->second)) {
3412 else if (MightHaveConstexprVirtualFunctions)
3444 Pattern, PatternDef, TSK,
true))
3446 Pattern = PatternDef;
3452 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3461 "instantiating enum definition");
3511 "pattern and instantiation disagree about init style");
3519 Diag(PointOfInstantiation,
3520 diag::err_default_member_initializer_not_yet_parsed)
3521 << OutermostClass << Pattern;
3522 Diag(Pattern->getEndLoc(),
3523 diag::note_default_member_initializer_not_yet_parsed);
3533 Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3538 "instantiating default member init");
3546 PointOfInstantiation, Instantiation,
CurContext};
3557 assert((!Init || !isa<ParenListExpr>(Init)) &&
"call-style init in class");
3559 Instantiation, Init ? Init->getBeginLoc() :
SourceLocation(), Init);
3562 L->DefaultMemberInitializerInstantiated(Instantiation);
3571 struct PartialSpecMatchResult {
3586 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3630 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3642 Matched.push_back(PartialSpecMatchResult());
3643 Matched.back().Partial = Partial;
3652 if (Matched.size() >= 1) {
3654 if (Matched.size() == 1) {
3667 PEnd = Matched.end();
3670 P->Partial, Best->Partial, PointOfInstantiation) ==
3677 bool Ambiguous =
false;
3679 PEnd = Matched.end();
3682 P->Partial, Best->Partial,
3683 PointOfInstantiation) != Best->Partial) {
3693 S.
Diag(PointOfInstantiation,
3694 diag::err_partial_spec_ordering_ambiguous)
3695 << ClassTemplateSpec;
3699 PEnd = Matched.end();
3701 S.
Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
3703 P->Partial->getTemplateParameters(), *
P->Args);
3718 if (
auto *PartialSpec =
3721 while (PartialSpec->getInstantiatedFromMember()) {
3724 if (PartialSpec->isMemberSpecialization())
3727 PartialSpec = PartialSpec->getInstantiatedFromMember();
3729 Pattern = PartialSpec;
3751 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
3758 ClassTemplateSpec, TSK);
3763 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
3782 "Unexpected template specialization kind!");
3783 for (
auto *D : Instantiation->
decls()) {
3784 bool SuppressNew =
false;
3785 if (
auto *Function = dyn_cast<FunctionDecl>(D)) {
3787 Function->getInstantiatedFromMemberFunction()) {
3789 if (Function->isIneligibleOrNotSelected())
3792 if (Function->getTrailingRequiresClause()) {
3800 if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3804 Function->getMemberSpecializationInfo();
3805 assert(MSInfo &&
"No member specialization information?");
3827 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3829 if (Function->isDefined()) {
3837 std::make_pair(Function, PointOfInstantiation));
3840 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
3841 if (isa<VarTemplateSpecializationDecl>(Var))
3845 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
3849 assert(MSInfo &&
"No member specialization information?");
3878 }
else if (
auto *Record = dyn_cast<CXXRecordDecl>(D)) {
3879 if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3887 if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
3892 assert(MSInfo &&
"No member specialization information?");
3917 CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
3918 assert(Pattern &&
"Missing instantiated-from-template information");
3920 if (!Record->getDefinition()) {
3941 Record->getTemplateSpecializationKind() ==
3943 Record->setTemplateSpecializationKind(TSK);
3948 Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
3952 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
3954 assert(MSInfo &&
"No member specialization information?");
3961 PointOfInstantiation, TSK,
Enum,
3967 if (
Enum->getDefinition())
3970 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
3971 assert(Pattern &&
"Missing instantiated-from-template information");
3982 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
3989 ClassPattern->
lookup(Field->getDeclName());
4025 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4028 return Instantiator.TransformStmt(S);
4035 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4037 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4045 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4048 return Instantiator.TransformExpr(E);
4059 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4061 return Instantiator.TransformExpr(E);
4066 bool CXXDirectInit) {
4067 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4069 return Instantiator.TransformInitializer(Init, CXXDirectInit);
4078 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4081 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4091 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4093 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4100 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4102 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4109 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
4112 SS.
Adopt(QualifierLoc);
4113 return Instantiator.TransformTemplateName(SS, Name, Loc);
4121 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4122 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4123 unsigned i = PV->getFunctionScopeIndex();
4126 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4134llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4138 Current = Current->Outer) {
4141 const Decl *CheckD = D;
4143 LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
4144 if (Found != Current->LocalDecls.end())
4145 return &Found->second;
4149 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4156 if (!Current->CombineWithOuterScope)
4162 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
4163 isa<TemplateTemplateParmDecl>(D))
4168 if (RD->isLocalClass())
4173 if (isa<EnumDecl>(D))
4178 if (isa<TypedefNameDecl>(D) &&
4185 assert(isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4191 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4192 if (Stored.isNull()) {
4196 while (Current->CombineWithOuterScope && Current->Outer) {
4197 Current = Current->Outer;
4198 assert(!Current->LocalDecls.contains(D) &&
4199 "Instantiated local in inner and outer scopes");
4204 Pack->push_back(cast<VarDecl>(Inst));
4206 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
4214 Pack->push_back(Inst);
4221 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4222 assert(!Current->LocalDecls.contains(D) &&
4223 "Creating local pack after instantiation of local");
4227 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4230 ArgumentPacks.push_back(Pack);
4235 if (llvm::is_contained(*Pack, D))
4242 unsigned NumExplicitArgs) {
4243 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4244 "Already have a partially-substituted pack");
4245 assert((!PartiallySubstitutedPack
4246 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4247 "Wrong number of arguments in partially-substituted pack");
4248 PartiallySubstitutedPack = Pack;
4249 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4250 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4255 unsigned *NumExplicitArgs)
const {
4257 *ExplicitArgs =
nullptr;
4258 if (NumExplicitArgs)
4259 *NumExplicitArgs = 0;
4262 Current = Current->Outer) {
4263 if (Current->PartiallySubstitutedPack) {
4265 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4266 if (NumExplicitArgs)
4267 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4269 return Current->PartiallySubstitutedPack;
4272 if (!Current->CombineWithOuterScope)
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the C++ template declaration subclasses.
Defines Expressions and AST nodes for C++2a concepts.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Defines the clang::LangOptions interface.
MatchFinder::MatchResult MatchResult
static const Decl * getCanonicalParmVarDecl(const Decl *D)
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, concepts::EntityPrinter Printer)
static ActionResult< CXXRecordDecl * > getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
Defines utilities for dealing with stack allocation and stack space.
C Language Family Type Representation.
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const clang::PrintingPolicy & getPrintingPolicy() const
const TargetInfo & getTargetInfo() const
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
QualType getOriginalType() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
An attributed type is a type to which a type attribute has been applied.
QualType getModifiedType() const
QualType getPointeeType() const
Represents a base class of a C++ class.
A default argument (C++ [dcl.fct.default]).
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXRecordDecl * getDefinition() const
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Represents a C++ nested-name-specifier or a global scope specifier.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)?...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
bool HasSubstitutionFailure()
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTranslationUnit() const
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
A reference to a declared variable, function, enum, etc.
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
bool isParameterPack() const
Whether this declaration is a parameter pack.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isFileContextDecl() const
static Decl * castFromDeclContext(const DeclContext *)
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setLocation(SourceLocation L)
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
The name of a declaration.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Information about one declarator, including the parsed type information and the identifier.
Represents an extended vector type where either the type or size is dependent.
QualType getElementType() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool hasFatalErrorOccurred() const
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
QualType getNamedType() const
Retrieve the type named by the qualified-id.
RAII object that enters a new expression evaluation context.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class,...
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
EnumDecl * getDefinition() const
This represents one expression.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Represents a function declaration or definition.
ArrayRef< ParmVarDecl * > parameters() const
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
VarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
VarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
VarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl * > Params)
Represents a prototype with parameter type info, e.g.
ExtProtoInfo getExtProtoInfo() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
ArrayRef< ParmVarDecl * > getParams() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
ArrayRef< TemplateArgument > getTemplateArguments() const
const TypeClass * getTypePtr() const
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Describes the sequence of initializations required to initialize a given object or reference with a s...
Describes an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
SourceLocation getBeginLoc() const LLVM_READONLY
A stack-allocated class that identifies which local variable declaration instantiations are present i...
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
void InstantiatedLocal(const Decl *D, Decl *Inst)
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
void MakeInstantiatedLocalArgPack(const Decl *D)
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
QualType getUnderlyingType() const
A pointer to member type per C++ 8.3.3 - Pointers to members.
QualType getPointeeType() const
Provides information a specialization of a member of a class template, which may be a member function...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Describes a module or submodule.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Represents a pack expansion of types.
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Sugar for parentheses used when specifying types.
QualType getInnerType() const
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
void setDefaultArg(Expr *defarg)
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
void setUninstantiatedDefaultArg(Expr *arg)
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
bool hasUninstantiatedDefaultArg() const
bool hasInheritedDefaultArg() const
Expr * getUninstantiatedDefaultArg()
unsigned getFunctionScopeDepth() const
void setHasInheritedDefaultArg(bool I=true)
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
SourceLocation getLocation() const
IdentKind getIdentKind() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
A (possibly-)qualified type.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
The collection of all-type qualifiers we support.
void removeObjCLifetime()
Represents a struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeTypeAsWritten() const
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
RAII object used to change the argument pack substitution index within a Sema object.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
For a defaulted function, the kind of defaulted function that it is.
DefaultedComparisonKind asComparison() const
bool isSpecialMember() const
CXXSpecialMember asSpecialMember() const
bool isComparison() const
A helper class for building up ExtParameterInfos.
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Sema - This implements semantic analysis and AST building for C.
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, const MultiLevelTemplateArgumentList &TemplateArgs, bool EvaluateConstraint)
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD)
Determine the kind of defaulting that would be done for a given function.
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, bool &RetainExpansion, std::optional< unsigned > &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, std::optional< unsigned > NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
void ActOnFinishCXXNonNestedClass()
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
void ActOnFinishDelayedMemberInitializers(Decl *Record)
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, bool Final=false, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
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...
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization,...
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
void deduceOpenCLAddressSpace(ValueDecl *decl)
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
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...
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
DiagnosticsEngine & getDiagnostics() const
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
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.
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.
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
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...
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain=true)
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
const LangOptions & getLangOpts() const
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 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...
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
ExprResult BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
Construct a new expression that refers to the given integral template argument with the given source-...
bool CheckConstraintSatisfaction(const NamedDecl *Template, ArrayRef< const Expr * > ConstraintExprs, const MultiLevelTemplateArgumentList &TemplateArgLists, SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction)
Check whether the given list of constraint expressions are satisfied (as if in a 'conjunction') given...
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 ...
TemplateDeductionResult
Describes the result of template argument deduction.
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained).
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
void popCodeSynthesisContext()
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
void pushCodeSynthesisContext(CodeSynthesisContext Ctx)
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
A mapping from parameters with unparsed default arguments to the set of instantiations of each parame...
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...
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
bool CheckFunctionConstraints(const FunctionDecl *FD, ConstraintSatisfaction &Satisfaction, SourceLocation UsageLoc=SourceLocation(), bool ForOverloadResolution=false)
Check whether the given function decl's trailing requires clause is satisfied, if any.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, Expr *Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member,...
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param, Expr *Init=nullptr)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed.
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.