39#include "llvm/ADT/STLForwardCompat.h"
40#include "llvm/ADT/StringExtras.h"
41#include "llvm/Support/ErrorHandling.h"
42#include "llvm/Support/SaveAndRestore.h"
43#include "llvm/Support/TimeProfiler.h"
56 const Decl *NextDecl =
nullptr;
58 bool ClearRelativeToPrimary =
true;
59 static Response Done() {
64 static Response ChangeDecl(
const Decl *ND) {
69 static Response ChangeDecl(
const DeclContext *Ctx) {
75 static Response UseNextDecl(
const Decl *CurDecl) {
79 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
80 Response R = Response::UseNextDecl(CurDecl);
81 R.ClearRelativeToPrimary =
false;
90getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
92 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
94 FTD && FTD->getInstantiatedFromMemberTemplate()) {
96 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
97 }
else if (
auto *Prev = cast<CXXMethodDecl>(LambdaCallOperator)
98 ->getInstantiatedFromMemberFunction())
99 LambdaCallOperator = Prev;
103 return LambdaCallOperator;
106struct EnclosingTypeAliasTemplateDetails {
111 explicit operator bool()
noexcept {
return Template; }
116EnclosingTypeAliasTemplateDetails
117getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
120 TypeAliasTemplateInstantiation)
122 EnclosingTypeAliasTemplateDetails Result;
123 auto *TATD = cast<TypeAliasTemplateDecl>(CSC.Entity),
124 *Next = TATD->getInstantiatedFromMemberTemplate();
128 CSC.template_arguments(),
131 Result.PrimaryTypeAliasDecl = Next;
132 Next = Next->getInstantiatedFromMemberTemplate();
149bool isLambdaEnclosedByTypeAliasDecl(
152 return cast<CXXRecordDecl>(PrimaryLambdaCallOperator->
getDeclContext())
156 const_cast<FunctionDecl *
>(PrimaryLambdaCallOperator)) ==
164 bool SkipForSpecialization) {
168 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
172 !isa<VarTemplatePartialSpecializationDecl>(VarTemplSpec))
173 return Response::Done();
178 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
182 if (!SkipForSpecialization)
183 Result.addOuterTemplateArguments(
186 if (Partial->isMemberSpecialization())
187 return Response::Done();
190 if (!SkipForSpecialization)
191 Result.addOuterTemplateArguments(
195 return Response::Done();
197 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
209 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
210 Result.addOuterTemplateArguments(std::nullopt);
211 return Response::Done();
214Response HandlePartialClassTemplateSpec(
217 if (!SkipForSpecialization)
219 return Response::Done();
226 bool SkipForSpecialization) {
230 !isa<ClassTemplatePartialSpecializationDecl>(ClassTemplSpec))
231 return Response::Done();
233 if (!SkipForSpecialization)
234 Result.addOuterTemplateArguments(
243 return Response::Done();
251 return Response::ChangeDecl(InstFromPartialTempl->getLexicalDeclContext());
253 return Response::UseNextDecl(ClassTemplSpec);
259 bool ForConstraintInstantiation) {
261 if (!RelativeToPrimary &&
262 Function->getTemplateSpecializationKindForInstantiation() ==
264 return Response::Done();
266 if (!RelativeToPrimary &&
271 return Response::UseNextDecl(
Function);
273 Function->getTemplateSpecializationArgs()) {
276 TemplateArgs->asArray(),
279 if (RelativeToPrimary &&
280 (
Function->getTemplateSpecializationKind() ==
283 !
Function->getPrimaryTemplate()->getFriendObjectKind())))
284 return Response::UseNextDecl(
Function);
288 assert(
Function->getPrimaryTemplate() &&
"No function template?");
289 if (
Function->getPrimaryTemplate()->isMemberSpecialization())
290 return Response::Done();
293 if (!ForConstraintInstantiation &&
302 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
303 if (isLambdaEnclosedByTypeAliasDecl(
304 getPrimaryTemplateOfGenericLambda(
306 TypeAlias.PrimaryTypeAliasDecl))
307 return Response::UseNextDecl(
Function);
309 return Response::Done();
312 }
else if (
Function->getDescribedFunctionTemplate()) {
314 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
315 "Outer template not instantiated?");
322 Function->getNonTransparentDeclContext()->isFileContext() &&
324 return Response::ChangeDecl(
Function->getLexicalDeclContext());
327 if (ForConstraintInstantiation &&
Function->getFriendObjectKind())
328 return Response::ChangeDecl(
Function->getLexicalDeclContext());
329 return Response::UseNextDecl(
Function);
334 if (!isa<ClassTemplateSpecializationDecl>(FTD->
getDeclContext())) {
335 Result.addOuterTemplateArguments(
363 if (TSTy->isCurrentInstantiation()) {
364 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
366 Arguments = CTD->getInjectedTemplateArgs();
368 dyn_cast<ClassTemplateSpecializationDecl>(RD))
372 Result.addOuterTemplateArguments(
388 bool ForConstraintInstantiation) {
391 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
392 "Outer template not instantiated?");
393 if (ClassTemplate->isMemberSpecialization())
394 return Response::Done();
395 if (ForConstraintInstantiation)
396 Result.addOuterTemplateArguments(
const_cast<CXXRecordDecl *
>(Rec),
397 ClassTemplate->getInjectedTemplateArgs(),
404 return Response::Done();
409 if (ForConstraintInstantiation && IsFriend &&
418 return Response::ChangeDecl(LCD);
422 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
425 if (isLambdaEnclosedByTypeAliasDecl(PrimaryLambdaCallOperator,
426 TypeAlias.PrimaryTypeAliasDecl)) {
427 Result.addOuterTemplateArguments(TypeAlias.Template,
428 TypeAlias.AssociatedTemplateArguments,
443 return Response::ChangeDecl(TypeAlias.Template->getDeclContext());
448 return Response::UseNextDecl(Rec);
451Response HandleImplicitConceptSpecializationDecl(
454 Result.addOuterTemplateArguments(
458 return Response::UseNextDecl(CSD);
461Response HandleGenericDeclContext(
const Decl *CurDecl) {
462 return Response::UseNextDecl(CurDecl);
470 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
471 bool SkipForSpecialization) {
472 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
477 const Decl *CurDecl = ND;
483 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
493 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
494 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
495 CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
500 if (
const auto *VarTemplSpec =
501 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
502 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
503 }
else if (
const auto *PartialClassTemplSpec =
504 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
505 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
506 SkipForSpecialization);
507 }
else if (
const auto *ClassTemplSpec =
508 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
509 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
510 SkipForSpecialization);
511 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
512 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
513 ForConstraintInstantiation);
514 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
516 ForConstraintInstantiation);
517 }
else if (
const auto *CSD =
518 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
519 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
520 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
521 R = HandleFunctionTemplateDecl(FTD,
Result);
522 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
523 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
524 }
else if (!isa<DeclContext>(CurDecl)) {
525 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
526 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
527 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
530 R = HandleGenericDeclContext(CurDecl);
535 if (R.ClearRelativeToPrimary)
536 RelativeToPrimary =
false;
538 CurDecl = R.NextDecl;
581 llvm_unreachable(
"Invalid SynthesisKind!");
611 AlreadyInstantiating = !Inst.Entity ?
false :
613 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
624 PointOfInstantiation, InstantiationRange, Entity) {}
631 PointOfInstantiation, InstantiationRange, Entity) {}
641 Template, TemplateArgs) {}
651 TemplateArgs, &DeductionInfo) {
665 PointOfInstantiation, InstantiationRange, Template, nullptr,
666 TemplateArgs, &DeductionInfo) {}
676 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
677 TemplateArgs, &DeductionInfo) {}
687 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
688 TemplateArgs, &DeductionInfo) {}
696 PointOfInstantiation, InstantiationRange, Param, nullptr,
706 PointOfInstantiation, InstantiationRange, Param, Template,
716 PointOfInstantiation, InstantiationRange, Param, Template,
725 PointOfInstantiation, InstantiationRange, Entity,
726 nullptr, TemplateArgs) {}
734 PointOfInstantiation, InstantiationRange, Param, Template,
743 PointOfInstantiation, InstantiationRange, nullptr,
744 nullptr,
std::nullopt, &DeductionInfo) {
753 PointOfInstantiation, InstantiationRange, nullptr,
754 nullptr,
std::nullopt) {}
761 PointOfInstantiation, InstantiationRange, nullptr,
762 nullptr,
std::nullopt, &DeductionInfo) {
771 PointOfInstantiation, InstantiationRange, Template, nullptr,
780 PointOfInstantiation, InstantiationRange, Template, nullptr,
781 {}, &DeductionInfo) {}
789 PointOfInstantiation, InstantiationRange, Template) {}
797 PointOfInstantiation, InstantiationRange, Template) {}
804 PointOfInstantiation, InstantiationRange, Entity) {}
824 if (!Active.isInstantiationRecord()) {
834 "forgot to remove a lookup module for a template instantiation");
853 if (!AlreadyInstantiating) {
857 {Active.Entity->getCanonicalDecl(), Active.Kind});
871 llvm::raw_string_ostream
OS(
Result);
872 llvm::ListSeparator Comma;
873 for (
const Expr *Arg : Args) {
875 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
881bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
892 diag::err_template_recursion_depth_exceeded)
894 << InstantiationRange;
895 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
905 SkipStart = Limit / 2 + Limit % 2;
910 unsigned InstantiationIdx = 0;
915 ++Active, ++InstantiationIdx) {
917 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
918 if (InstantiationIdx == SkipStart) {
921 diag::note_instantiation_contexts_suppressed)
927 switch (Active->Kind) {
929 Decl *
D = Active->Entity;
931 unsigned DiagID = diag::note_template_member_class_here;
932 if (isa<ClassTemplateSpecializationDecl>(
Record))
933 DiagID = diag::note_template_class_instantiation_here;
935 <<
Record << Active->InstantiationRange;
939 DiagID = diag::note_function_template_spec_here;
941 DiagID = diag::note_template_member_function_here;
944 << Active->InstantiationRange;
945 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(
D)) {
947 VD->isStaticDataMember()?
948 diag::note_template_static_data_member_def_here
949 : diag::note_template_variable_def_here)
951 << Active->InstantiationRange;
952 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(
D)) {
954 diag::note_template_enum_def_here)
956 << Active->InstantiationRange;
957 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(
D)) {
959 diag::note_template_nsdmi_here)
960 << FD << Active->InstantiationRange;
963 diag::note_template_class_instantiation_here)
964 << CTD << Active->InstantiationRange;
970 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
972 llvm::raw_svector_ostream
OS(TemplateArgsStr);
977 diag::note_default_arg_instantiation_here)
979 << Active->InstantiationRange;
986 diag::note_explicit_template_arg_substitution_here)
989 Active->TemplateArgs,
990 Active->NumTemplateArgs)
991 << Active->InstantiationRange;
997 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
999 diag::note_function_template_deduction_instantiation_here)
1002 Active->TemplateArgs,
1003 Active->NumTemplateArgs)
1004 << Active->InstantiationRange;
1006 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
1007 isa<VarTemplateSpecializationDecl>(Active->Entity);
1008 bool IsTemplate =
false;
1010 if (
auto *
D = dyn_cast<TemplateDecl>(Active->Entity)) {
1012 Params =
D->getTemplateParameters();
1013 }
else if (
auto *
D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1015 Params =
D->getTemplateParameters();
1016 }
else if (
auto *
D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1018 Params =
D->getTemplateParameters();
1020 llvm_unreachable(
"unexpected template kind");
1024 diag::note_deduced_template_arg_substitution_here)
1025 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
1027 Active->NumTemplateArgs)
1028 << Active->InstantiationRange;
1034 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
1038 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1043 diag::note_default_function_arg_instantiation_here)
1045 << Active->InstantiationRange;
1050 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
1053 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1056 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1057 TemplateParams = Template->getTemplateParameters();
1060 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1061 ->getTemplateParameters();
1063 diag::note_prior_template_arg_substitution)
1064 << isa<TemplateTemplateParmDecl>(Parm)
1067 Active->TemplateArgs,
1068 Active->NumTemplateArgs)
1069 << Active->InstantiationRange;
1075 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1076 TemplateParams = Template->getTemplateParameters();
1079 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1080 ->getTemplateParameters();
1083 diag::note_template_default_arg_checking)
1085 Active->TemplateArgs,
1086 Active->NumTemplateArgs)
1087 << Active->InstantiationRange;
1093 diag::note_evaluating_exception_spec_here)
1094 << cast<FunctionDecl>(Active->Entity);
1099 diag::note_template_exception_spec_instantiation_here)
1100 << cast<FunctionDecl>(Active->Entity)
1101 << Active->InstantiationRange;
1106 diag::note_template_requirement_instantiation_here)
1107 << Active->InstantiationRange;
1111 diag::note_template_requirement_params_instantiation_here)
1112 << Active->InstantiationRange;
1117 diag::note_nested_requirement_here)
1118 << Active->InstantiationRange;
1123 diag::note_in_declaration_of_implicit_special_member)
1124 << cast<CXXRecordDecl>(Active->Entity)
1125 << llvm::to_underlying(Active->SpecialMember);
1130 diag::note_in_declaration_of_implicit_equality_comparison);
1136 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1140 auto *MD = cast<CXXMethodDecl>(FD);
1142 diag::note_member_synthesized_at)
1143 << MD->isExplicitlyDefaulted()
1149 .getNonReferenceType()
1150 .getUnqualifiedType();
1152 diag::note_comparison_synthesized_at)
1160 diag::note_rewriting_operator_as_spaceship);
1165 diag::note_in_binding_decl_init)
1166 << cast<BindingDecl>(Active->Entity);
1171 diag::note_due_to_dllexported_class)
1172 << cast<CXXRecordDecl>(Active->Entity) << !
getLangOpts().CPlusPlus11;
1177 diag::note_building_builtin_dump_struct_call)
1187 diag::note_lambda_substitution_here);
1190 unsigned DiagID = 0;
1191 if (!Active->Entity) {
1193 diag::note_nested_requirement_here)
1194 << Active->InstantiationRange;
1197 if (isa<ConceptDecl>(Active->Entity))
1198 DiagID = diag::note_concept_specialization_here;
1199 else if (isa<TemplateDecl>(Active->Entity))
1200 DiagID = diag::note_checking_constraints_for_template_id_here;
1201 else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
1202 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1203 else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
1204 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1206 assert(isa<FunctionDecl>(Active->Entity));
1207 DiagID = diag::note_checking_constraints_for_function_here;
1210 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1212 if (!isa<FunctionDecl>(Active->Entity)) {
1216 Diags.
Report(Active->PointOfInstantiation, DiagID) <<
OS.str()
1217 << Active->InstantiationRange;
1222 diag::note_constraint_substitution_here)
1223 << Active->InstantiationRange;
1227 diag::note_constraint_normalization_here)
1228 << cast<NamedDecl>(Active->Entity)->getName()
1229 << Active->InstantiationRange;
1233 diag::note_parameter_mapping_substitution_here)
1234 << Active->InstantiationRange;
1238 diag::note_building_deduction_guide_here);
1242 diag::note_template_type_alias_instantiation_here)
1243 << cast<TypeAliasTemplateDecl>(Active->Entity)
1244 << Active->InstantiationRange;
1252 return std::optional<TemplateDeductionInfo *>(
nullptr);
1257 Active != ActiveEnd;
1260 switch (Active->Kind) {
1264 if (isa<TypeAliasTemplateDecl>(Active->Entity))
1275 return std::nullopt;
1282 return std::nullopt;
1303 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1304 return Active->DeductionInfo;
1315 return std::nullopt;
1329 if (Active->SavedInNonInstantiationSFINAEContext)
1330 return std::optional<TemplateDeductionInfo *>(
nullptr);
1333 return std::nullopt;
1340 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1345 bool EvaluateConstraints =
true;
1350 TemplateInstantiator(
Sema &SemaRef,
1353 : inherited(SemaRef), TemplateArgs(TemplateArgs),
Loc(
Loc),
1356 void setEvaluateConstraints(
bool B) {
1357 EvaluateConstraints = B;
1359 bool getEvaluateConstraints() {
1360 return EvaluateConstraints;
1380 this->Entity = Entity;
1383 unsigned TransformTemplateDepth(
unsigned Depth) {
1388 int Index = getSema().ArgumentPackSubstitutionIndex;
1390 return std::nullopt;
1397 bool &ShouldExpand,
bool &RetainExpansion,
1398 std::optional<unsigned> &NumExpansions) {
1399 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
1400 PatternRange, Unexpanded,
1407 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
1417 unsigned Depth, Index;
1420 Result = TemplateArgs(Depth, Index);
1436 unsigned Depth, Index;
1446 void transformAttrs(
Decl *Old,
Decl *New) {
1452 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1454 for (
auto *New : NewDecls)
1456 Old, cast<VarDecl>(New));
1460 assert(NewDecls.size() == 1 &&
1461 "should only have multiple expansions for a pack");
1462 Decl *New = NewDecls.front();
1467 auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1469 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1470 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1471 NewTD->setInstantiatedFromMemberTemplate(
1472 OldMD->getDescribedFunctionTemplate());
1474 NewMD->setInstantiationOfMemberFunction(OldMD,
1482 if (
auto *DC = dyn_cast<DeclContext>(Old);
1483 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1524 NamedDecl *FirstQualifierInScope =
nullptr,
1525 bool AllowInjectedClassName =
false);
1527 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1528 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1529 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1531 const NoInlineAttr *A);
1532 const AlwaysInlineAttr *
1533 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1534 const AlwaysInlineAttr *A);
1535 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1542 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1544 ExprResult TransformSubstNonTypeTemplateParmExpr(
1561 return inherited::TransformFunctionProtoType(TLB, TL);
1566 auto Type = inherited::TransformInjectedClassNameType(TLB, TL);
1569 if (
Type.isNull() &&
1576 inherited::TransformType(ICT->getInjectedSpecializationType());
1587 bool Uneval =
false) {
1589 std::vector<TemplateArgument> TArgs;
1609 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1612 template<
typename Fn>
1617 Fn TransformExceptionSpec);
1620 TransformFunctionTypeParam(
ParmVarDecl *OldParm,
int indexAdjustment,
1621 std::optional<unsigned> NumExpansions,
1622 bool ExpectParameterPack);
1624 using inherited::TransformTemplateTypeParmType;
1629 bool SuppressObjCLifetime);
1631 QualType BuildSubstTemplateTypeParmType(
1633 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
1639 using inherited::TransformSubstTemplateTypeParmPackType;
1643 bool SuppressObjCLifetime);
1650 unsigned TypeAliasDeclDepth = CCS.Entity->getTemplateDepth();
1652 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1654 return inherited::ComputeLambdaDependency(LSI);
1661 return inherited::TransformLambdaExpr(
E);
1668 assert(PVD &&
"null in a parameter list");
1669 if (!PVD->hasDefaultArg())
1671 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1680 { UninstExpr }, UninstExpr->
getType());
1682 PVD->setDefaultArg(ErrorResult.
get());
1685 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1699 return inherited::TransformLambdaBody(
E, Body);
1704 ExprResult TransReq = inherited::TransformRequiresExpr(
E);
1707 assert(TransReq.
get() !=
E &&
1708 "Do not change value of isSatisfied for the existing expression. "
1709 "Create a new expression instead.");
1710 if (
E->getBody()->isDependentContext()) {
1716 if (Trap.hasErrorOccurred())
1722 bool TransformRequiresExprRequirements(
1725 bool SatisfactionDetermined =
false;
1728 if (!SatisfactionDetermined) {
1729 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1730 TransReq = TransformTypeRequirement(TypeReq);
1731 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1732 TransReq = TransformExprRequirement(ExprReq);
1734 TransReq = TransformNestedRequirement(
1735 cast<concepts::NestedRequirement>(Req));
1744 SatisfactionDetermined =
true;
1747 Transformed.push_back(TransReq);
1754 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1758 Owner, TemplateArgs);
1759 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1760 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1778 transformNonTypeTemplateParmRef(
Decl *AssociatedDecl,
1781 std::optional<unsigned> PackIndex);
1785bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
1792 getSema().MarkDeclarationsReferencedInType(
Loc,
T);
1817 TTP->getPosition()))
1822 if (TTP->isParameterPack()) {
1824 "Missing argument pack");
1830 "Wrong kind of template template argument");
1842 Decl *Inst = getSema().SubstDecl(
D, getSema().
CurContext, TemplateArgs);
1846 getSema().CurrentInstantiationScope->InstantiatedLocal(
D, Inst);
1850bool TemplateInstantiator::TransformExceptionSpec(
1857 return inherited::TransformExceptionSpec(
Loc, ESI, Exceptions, Changed);
1861TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *
D,
1875 "Missing argument pack");
1885 return cast_or_null<NamedDecl>(TransformDecl(
Loc,
D));
1888 return Tag->getDecl();
1891 getSema().Diag(
Loc, diag::err_nested_name_spec_non_tag) <<
T;
1896 return cast_or_null<NamedDecl>(TransformDecl(
Loc,
D));
1900TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
1906 StartLoc, NameLoc, Name);
1908 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1912VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
1915 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
1917 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1922TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
1940 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
1949 return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc,
T);
1952TemplateName TemplateInstantiator::TransformTemplateName(
1955 bool AllowInjectedClassName) {
1957 = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1964 TTP->getPosition()))
1974 "unexpected pack arguments in template rewrite");
1978 "unexpected nontype template argument kind in template rewrite");
1982 auto [AssociatedDecl, Final] =
1984 std::optional<unsigned> PackIndex;
1987 "Missing argument pack");
1993 return getSema().Context.getSubstTemplateTemplateParmPack(
1994 Arg, AssociatedDecl, TTP->
getIndex(), Final);
1997 PackIndex = getPackIndex(Arg);
2002 assert(!Template.
isNull() &&
"Null template template argument");
2006 return getSema().Context.getSubstTemplateTemplateParm(
2007 Template, AssociatedDecl, TTP->
getIndex(), PackIndex);
2012 = Name.getAsSubstTemplateTemplateParmPack()) {
2019 if (SubstPack->getFinal())
2021 return getSema().Context.getSubstTemplateTemplateParm(
2022 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2023 getPackIndex(Pack));
2026 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
2027 FirstQualifierInScope,
2028 AllowInjectedClassName);
2036 return getSema().BuildPredefinedExpr(
E->getLocation(),
E->getIdentKind());
2040TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *
E,
2057 "unexpected pack arguments in template rewrite");
2061 "unexpected nontype template argument kind in template rewrite");
2068 std::optional<unsigned> PackIndex;
2071 "Missing argument pack");
2089 E->getLocation(), Arg, AssociatedDecl, NTTP->
getPosition());
2091 PackIndex = getPackIndex(Arg);
2095 return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP,
E->getLocation(),
2099const CXXAssumeAttr *
2100TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2101 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2105 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2110 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2115TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2116 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2118 if (TransformedExpr == LH->getValue())
2123 LH->getSemanticSpelling() ==
2124 LoopHintAttr::Pragma_unroll))
2127 LoopHintAttr::OptionType Option = LH->getOption();
2128 LoopHintAttr::LoopHintState State = LH->getState();
2130 llvm::APSInt ValueAPS =
2133 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2134 Option = LoopHintAttr::Unroll;
2135 State = LoopHintAttr::Disable;
2140 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2141 TransformedExpr, *LH);
2143const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2144 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2150const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2151 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2158const CodeAlignAttr *
2159TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2160 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2161 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2164ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
2167 std::optional<unsigned> PackIndex) {
2172 auto SubstParamType = [&] {
2179 T = cast<PackExpansionType>(
T)->getPattern();
2183 bool refParam =
false;
2189 Expr *argExpr =
arg.getAsExpr();
2194 QualType paramType = SubstParamType();
2209 VD = cast_or_null<ValueDecl>(
2215 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2216 assert(!paramType.
isNull() &&
"type substitution failed for param type");
2217 assert(!paramType->
isDependentType() &&
"param type still dependent");
2221 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2232 Expr *resultExpr = result.
get();
2236 AssociatedDecl, parm->
getIndex(), PackIndex, refParam);
2240TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
2250 return transformNonTypeTemplateParmRef(
2251 E->getAssociatedDecl(),
E->getParameterPack(),
2252 E->getParameterPackLocation(), Arg, getPackIndex(Pack));
2256TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
2258 ExprResult SubstReplacement =
E->getReplacement();
2259 if (!isa<ConstantExpr>(SubstReplacement.
get()))
2260 SubstReplacement = TransformExpr(
E->getReplacement());
2289 SubstReplacement.
get(), SugaredConverted,
2293 return transformNonTypeTemplateParmRef(
E->getAssociatedDecl(),
2295 SugaredConverted,
E->getPackIndex());
2301 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
2312 return RebuildVarDeclRefExpr(VD,
E->
getExprLoc());
2322 Vars.reserve(
E->getNumExpansions());
2333 E->getParameterPackLocation(), Vars);
2334 getSema().MarkFunctionParmPackReferenced(PackExpr);
2339TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *
E,
2342 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found
2343 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2344 assert(
Found &&
"no instantiation for parameter pack");
2346 Decl *TransformedDecl;
2347 if (DeclArgumentPack *Pack =
Found->dyn_cast<DeclArgumentPack *>()) {
2356 getSema().MarkFunctionParmPackReferenced(PackExpr);
2360 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
2366 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl),
E->
getExprLoc());
2370TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *
E) {
2377 return TransformTemplateParmRefExpr(
E, NTTP);
2384 if (
VarDecl *PD = dyn_cast<VarDecl>(
D))
2386 return TransformFunctionParmPackRefExpr(
E, PD);
2388 return inherited::TransformDeclRefExpr(
E);
2391ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2393 assert(!cast<FunctionDecl>(
E->getParam()->getDeclContext())->
2394 getDescribedFunctionTemplate() &&
2395 "Default arg expressions are never formed in dependent cases.");
2397 E->getUsedLocation(), cast<FunctionDecl>(
E->getParam()->getDeclContext()),
2401template<
typename Fn>
2406 Fn TransformExceptionSpec) {
2409 return inherited::TransformFunctionProtoType(
2410 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2413ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2415 std::optional<unsigned> NumExpansions,
bool ExpectParameterPack) {
2417 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2418 ExpectParameterPack, EvaluateConstraints);
2424QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2426 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
2432 if (SuppressObjCLifetime) {
2434 RQs = Replacement.getQualifiers();
2445 QualType Result = getSema().Context.getSubstTemplateTypeParmType(
2446 Replacement, AssociatedDecl, Index, PackIndex);
2454TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
2456 bool SuppressObjCLifetime) {
2480 "unexpected pack arguments in template rewrite");
2484 "unexpected nontype template argument kind in template rewrite");
2490 auto [AssociatedDecl, Final] =
2492 std::optional<unsigned> PackIndex;
2493 if (
T->isParameterPack()) {
2495 "Missing argument pack");
2501 QualType Result = getSema().Context.getSubstTemplateTypeParmPackType(
2502 AssociatedDecl,
T->getIndex(), Final, Arg);
2510 PackIndex = getPackIndex(Arg);
2515 "Template argument kind mismatch");
2517 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2518 AssociatedDecl,
T->getIndex(),
2528 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2532 T->isParameterPack(), NewTTPDecl);
2538QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2540 bool SuppressObjCLifetime) {
2543 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2548 if (NewReplaced !=
T->getAssociatedDecl())
2549 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2550 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2559 return BuildSubstTemplateTypeParmType(
2560 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2574 ErrorLoc = PDA.first;
2579 llvm::raw_svector_ostream
OS(Entity);
2583 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2590 llvm::raw_svector_ostream
OS(Entity);
2594 C.backupStr(Entity),
2595 Location, StringRef()};
2598ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2612 if (getDerived().TransformFunctionTypeParams(
2613 KWLoc, Params,
nullptr,
nullptr, PTypes,
2614 &TransParams, PInfos, &ErrorIdx) ||
2615 Trap.hasErrorOccurred()) {
2621 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2622 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2624 TransReqs, RBraceLoc);
2635 if (AlwaysRebuild())
2636 return RebuildTypeRequirement(
2646 if (TypeInst.isInvalid())
2649 if (!TransType || Trap.hasErrorOccurred())
2651 [&] (llvm::raw_ostream&
OS) {
2654 return RebuildTypeRequirement(TransType);
2664 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2673 if (ExprInst.isInvalid())
2676 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2679 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2684 TransExpr = TransExprRes.
get();
2687 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2689 if (RetReq.isEmpty())
2690 TransRetReq.emplace();
2691 else if (RetReq.isSubstitutionFailure())
2692 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2693 else if (RetReq.isTypeConstraint()) {
2695 RetReq.getTypeConstraintTemplateParameterList();
2699 if (TPLInst.isInvalid())
2702 if (!TPL || Trap.hasErrorOccurred())
2704 [&] (llvm::raw_ostream&
OS) {
2705 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2710 TransRetReq.emplace(TPL);
2713 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2714 if (
Expr *
E = TransExpr.dyn_cast<
Expr *>())
2716 std::move(*TransRetReq));
2717 return RebuildExprRequirement(
2723TemplateInstantiator::TransformNestedRequirement(
2728 if (AlwaysRebuild())
2737 if (!getEvaluateConstraints()) {
2739 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2759 if (ConstrInst.isInvalid())
2763 nullptr, {Req->getConstraintExpr()},
Result, TemplateArgs,
2766 TransConstraint =
Result[0];
2767 assert(!Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
2768 "by CheckConstraintSatisfaction.");
2774 if (TransConstraint.
isInvalid() || !TransConstraint.
get() ||
2777 llvm::raw_svector_ostream
OS(Entity);
2791 bool AllowDeducedTST) {
2793 "Cannot perform an instantiation without some context on the "
2794 "instantiation stack");
2800 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2801 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2802 : Instantiator.TransformType(
T);
2810 "Cannot perform an instantiation without some context on the "
2811 "instantiation stack");
2825 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2840 "Cannot perform an instantiation without some context on the "
2841 "instantiation stack");
2848 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc, Entity);
2849 return Instantiator.TransformType(
T);
2857 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2880 bool EvaluateConstraints) {
2882 "Cannot perform an instantiation without some context on the "
2883 "instantiation stack");
2888 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2889 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2905 Result = Instantiator.TransformFunctionProtoType(
2906 TLB, Proto, ThisContext, ThisTypeQuals,
2908 bool &Changed) {
return false; });
2910 Result = Instantiator.TransformType(TLB, TL);
2924 bool Changed =
false;
2926 return Instantiator.TransformExceptionSpec(
Loc, ESI, ExceptionStorage,
2937 ESI, ExceptionStorage, Args))
2946 struct GetContainedInventedTypeParmVisitor :
2947 public TypeVisitor<GetContainedInventedTypeParmVisitor,
2948 TemplateTypeParmDecl *> {
2949 using TypeVisitor<GetContainedInventedTypeParmVisitor,
2955 return Visit(
T.getTypePtr());
2960 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
2962 return T->getDecl();
2969 return Visit(
T->getNamedType());
2981 return Visit(
T->getPointeeTypeAsWritten());
2989 return Visit(
T->getElementType());
2994 return Visit(
T->getElementType());
2998 return Visit(
T->getElementType());
3002 return VisitFunctionType(
T);
3010 return Visit(
T->getInnerType());
3014 return Visit(
T->getModifiedType());
3018 return Visit(
T->getUnderlyingType());
3022 return Visit(
T->getOriginalType());
3026 return Visit(
T->getPattern());
3035 bool EvaluateConstraints) {
3039 if (!EvaluateConstraints) {
3066 int indexAdjustment, std::optional<unsigned> NumExpansions,
3067 bool ExpectParameterPack,
bool EvaluateConstraint) {
3076 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
3087 }
else if (ExpectParameterPack) {
3093 diag::err_function_parameter_pack_without_parameter_packs)
3117 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
3119 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3124 if (Inst && !Inst->getTypeConstraint()) {
3193 "Cannot perform an instantiation without some context on the "
3194 "instantiation stack");
3196 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc,
3198 return Instantiator.TransformFunctionTypeParams(
3199 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3217 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
3229 std::unique_ptr<LocalInstantiationScope> LIS;
3238 LIS = std::make_unique<LocalInstantiationScope>(*
this);
3241 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3244 if (PrimaryTemplate && PrimaryTemplate->
isOutOfLine()) {
3250 CurrentTemplateArgumentList->
asArray(),
true);
3272 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3299 for (
const auto &
Base : Pattern->
bases()) {
3300 if (!
Base.getType()->isDependentType()) {
3302 if (RD->isInvalidDecl())
3311 if (
Base.isPackExpansion()) {
3317 bool ShouldExpand =
false;
3318 bool RetainExpansion =
false;
3319 std::optional<unsigned> NumExpansions;
3321 Base.getSourceRange(),
3323 TemplateArgs, ShouldExpand,
3332 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3337 Base.getSourceRange().getBegin(),
3346 Base.getSourceRange(),
3348 Base.getAccessSpecifierAsWritten(),
3351 InstantiatedBases.push_back(InstantiatedBase);
3360 EllipsisLoc =
Base.getEllipsisLoc();
3364 Base.getSourceRange().getBegin(),
3369 Base.getSourceRange().getBegin(),
3380 Base.getSourceRange(),
3382 Base.getAccessSpecifierAsWritten(),
3385 InstantiatedBases.push_back(InstantiatedBase);
3417 Pattern, PatternDef, TSK, Complain))
3420 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3421 llvm::TimeTraceMetadata M;
3422 llvm::raw_string_ostream
OS(M.Detail);
3425 if (llvm::isTimeTraceVerbose()) {
3433 Pattern = PatternDef;
3439 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3441 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3442 Spec->setTemplateSpecializationKind(TSK);
3443 Spec->setPointOfInstantiation(PointOfInstantiation);
3451 "instantiating class definition");
3469 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3495 bool MightHaveConstexprVirtualFunctions =
false;
3506 if (
Member->getDeclContext() != Pattern)
3513 if (isa<BlockDecl>(
Member) ||
3514 (isa<CXXRecordDecl>(
Member) && cast<CXXRecordDecl>(
Member)->isLambda()))
3517 if (
Member->isInvalidDecl()) {
3524 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3525 Fields.push_back(Field);
3526 }
else if (
EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3532 Enum->isCompleteDefinition()) {
3534 assert(MSInfo &&
"no spec info for member enum specialization");
3539 if (SA->isFailed()) {
3545 }
else if (
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3548 MightHaveConstexprVirtualFunctions =
true;
3569 if (ParsingClassDepth == 0)
3574 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3575 E = LateAttrs.end(); I !=
E; ++I) {
3580 auto *ND = cast<NamedDecl>(I->NewDecl);
3581 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3583 ND->isCXXInstanceMember());
3588 I->NewDecl->addAttr(NewAttr);
3617 P->first,
P->second)) {
3630 P->first,
P->second)) {
3647 else if (MightHaveConstexprVirtualFunctions)
3664 Pattern, PatternDef, TSK,
true))
3666 Pattern = PatternDef;
3672 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3681 "instantiating enum definition");
3716 "pattern and instantiation disagree about init style");
3724 Diag(PointOfInstantiation,
3725 diag::err_default_member_initializer_not_yet_parsed)
3726 << OutermostClass << Pattern;
3727 Diag(Pattern->getEndLoc(),
3728 diag::note_default_member_initializer_not_yet_parsed);
3738 Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3743 "instantiating default member init");
3751 PointOfInstantiation, Instantiation,
CurContext};
3762 assert((!
Init || !isa<ParenListExpr>(
Init)) &&
"call-style init in class");
3767 L->DefaultMemberInitializerInstantiated(Instantiation);
3776 struct PartialSpecMatchResult {
3791 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3836 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3849 Matched.push_back(PartialSpecMatchResult());
3850 Matched.back().Partial = Partial;
3859 if (Matched.size() >= 1) {
3861 if (Matched.size() == 1) {
3874 PEnd = Matched.end();
3877 P->Partial, Best->Partial, PointOfInstantiation) ==
3884 bool Ambiguous =
false;
3886 PEnd = Matched.end();
3889 P->Partial, Best->Partial,
3890 PointOfInstantiation) != Best->Partial) {
3900 S.
Diag(PointOfInstantiation,
3901 diag::err_partial_spec_ordering_ambiguous)
3902 << ClassTemplateSpec;
3906 PEnd = Matched.end();
3908 S.
Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
3910 P->Partial->getTemplateParameters(), *
P->Args);
3925 if (
auto *PartialSpec =
3928 while (PartialSpec->getInstantiatedFromMember()) {
3931 if (PartialSpec->isMemberSpecialization())
3934 PartialSpec = PartialSpec->getInstantiatedFromMember();
3936 Pattern = PartialSpec;
3958 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
3965 ClassTemplateSpec, TSK);
3970 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
3986 "Unexpected template specialization kind!");
3987 for (
auto *
D : Instantiation->
decls()) {
3988 bool SuppressNew =
false;
3989 if (
auto *
Function = dyn_cast<FunctionDecl>(
D)) {
3991 Function->getInstantiatedFromMemberFunction()) {
3993 if (
Function->isIneligibleOrNotSelected())
3996 if (
Function->getTrailingRequiresClause()) {
4004 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4008 Function->getMemberSpecializationInfo();
4009 assert(MSInfo &&
"No member specialization information?");
4031 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4041 std::make_pair(
Function, PointOfInstantiation));
4044 }
else if (
auto *Var = dyn_cast<VarDecl>(
D)) {
4045 if (isa<VarTemplateSpecializationDecl>(Var))
4049 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4053 assert(MSInfo &&
"No member specialization information?");
4082 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(
D)) {
4083 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4091 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4096 assert(MSInfo &&
"No member specialization information?");
4122 assert(Pattern &&
"Missing instantiated-from-template information");
4124 if (!
Record->getDefinition()) {
4145 Record->getTemplateSpecializationKind() ==
4147 Record->setTemplateSpecializationKind(TSK);
4152 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4156 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(
D)) {
4158 assert(MSInfo &&
"No member specialization information?");
4165 PointOfInstantiation, TSK,
Enum,
4171 if (
Enum->getDefinition())
4174 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4175 assert(Pattern &&
"Missing instantiated-from-template information");
4186 }
else if (
auto *Field = dyn_cast<FieldDecl>(
D)) {
4193 ClassPattern->
lookup(Field->getDeclName());
4226 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4229 return Instantiator.TransformStmt(S);
4237 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc, Entity);
4238 return Instantiator.TransformTemplateArgument(Input, Output);
4245 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4247 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4255 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4258 return Instantiator.TransformExpr(
E);
4274 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4276 Instantiator.setEvaluateConstraints(
false);
4277 return Instantiator.TransformExpr(
E);
4282 bool CXXDirectInit) {
4283 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4285 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4294 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4297 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4307 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4309 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4315 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4317 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4324 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc,
4327 SS.
Adopt(QualifierLoc);
4328 return Instantiator.TransformTemplateName(SS, Name,
Loc);
4336 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(
D)) {
4337 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4338 unsigned i = PV->getFunctionScopeIndex();
4341 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4349llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4353 Current = Current->Outer) {
4356 const Decl *CheckD =
D;
4358 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4359 if (
Found != Current->LocalDecls.end())
4360 return &
Found->second;
4364 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4365 CheckD = Tag->getPreviousDecl();
4371 if (!Current->CombineWithOuterScope)
4377 if (isa<NonTypeTemplateParmDecl>(
D) || isa<TemplateTypeParmDecl>(
D) ||
4378 isa<TemplateTemplateParmDecl>(
D))
4383 if (RD->isLocalClass())
4388 if (isa<EnumDecl>(
D))
4393 if (isa<TypedefNameDecl>(
D) &&
4400 assert(isa<LabelDecl>(
D) &&
"declaration not instantiated in this scope");
4406 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[
D];
4407 if (Stored.isNull()) {
4411 while (Current->CombineWithOuterScope && Current->Outer) {
4412 Current = Current->Outer;
4413 assert(!Current->LocalDecls.contains(
D) &&
4414 "Instantiated local in inner and outer scopes");
4419 Pack->push_back(cast<VarDecl>(Inst));
4421 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
4429 Pack->push_back(Inst);
4436 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4437 assert(!Current->LocalDecls.contains(
D) &&
4438 "Creating local pack after instantiation of local");
4442 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[
D];
4445 ArgumentPacks.push_back(Pack);
4450 if (llvm::is_contained(*Pack,
D))
4457 unsigned NumExplicitArgs) {
4458 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4459 "Already have a partially-substituted pack");
4460 assert((!PartiallySubstitutedPack
4461 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4462 "Wrong number of arguments in partially-substituted pack");
4463 PartiallySubstitutedPack = Pack;
4464 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4465 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4470 unsigned *NumExplicitArgs)
const {
4472 *ExplicitArgs =
nullptr;
4473 if (NumExplicitArgs)
4474 *NumExplicitArgs = 0;
4477 Current = Current->Outer) {
4478 if (Current->PartiallySubstitutedPack) {
4480 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4481 if (NumExplicitArgs)
4482 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4484 return Current->PartiallySubstitutedPack;
4487 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.
llvm::MachO::Record Record
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.
Defines the clang::TypeLoc interface and its subclasses.
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.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Attr - This represents one attribute.
An attributed type is a type to which a type attribute has been applied.
Represents a base class of a C++ class.
A default argument (C++ [dcl.fct.default]).
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,...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
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...
NamedDecl * getFoundDecl() const
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.
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.
Decl - This represents one declaration (or definition), e.g.
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
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.
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,...
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.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
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...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
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 *const * iterator
Iterators over the parameters which the parameter pack expanded into.
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.
Wrapper for source info for injected class names of class templates.
The injected class name of a C++ class template or class template partial specialization.
A C++ lambda expression, which produces a function object (of unspecified type) that can be i