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,
260 bool ForDefaultArgumentSubstitution) {
262 if (!RelativeToPrimary &&
263 Function->getTemplateSpecializationKindForInstantiation() ==
265 return Response::Done();
267 if (!RelativeToPrimary &&
272 return Response::UseNextDecl(
Function);
274 Function->getTemplateSpecializationArgs()) {
277 TemplateArgs->asArray(),
280 if (RelativeToPrimary &&
281 (
Function->getTemplateSpecializationKind() ==
284 !
Function->getPrimaryTemplate()->getFriendObjectKind())))
285 return Response::UseNextDecl(
Function);
289 assert(
Function->getPrimaryTemplate() &&
"No function template?");
290 if (!ForDefaultArgumentSubstitution &&
291 Function->getPrimaryTemplate()->isMemberSpecialization())
292 return Response::Done();
295 if (!ForConstraintInstantiation &&
304 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
305 if (isLambdaEnclosedByTypeAliasDecl(
306 getPrimaryTemplateOfGenericLambda(
308 TypeAlias.PrimaryTypeAliasDecl))
309 return Response::UseNextDecl(
Function);
311 return Response::Done();
314 }
else if (
Function->getDescribedFunctionTemplate()) {
316 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
317 "Outer template not instantiated?");
324 Function->getNonTransparentDeclContext()->isFileContext() &&
326 return Response::ChangeDecl(
Function->getLexicalDeclContext());
329 if (ForConstraintInstantiation &&
Function->getFriendObjectKind())
330 return Response::ChangeDecl(
Function->getLexicalDeclContext());
331 return Response::UseNextDecl(
Function);
336 if (!isa<ClassTemplateSpecializationDecl>(FTD->
getDeclContext())) {
337 Result.addOuterTemplateArguments(
365 if (TSTy->isCurrentInstantiation()) {
366 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
368 Arguments = CTD->getInjectedTemplateArgs();
370 dyn_cast<ClassTemplateSpecializationDecl>(RD))
374 Result.addOuterTemplateArguments(
390 bool ForConstraintInstantiation) {
393 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
394 "Outer template not instantiated?");
395 if (ClassTemplate->isMemberSpecialization())
396 return Response::Done();
397 if (ForConstraintInstantiation)
398 Result.addOuterTemplateArguments(
const_cast<CXXRecordDecl *
>(Rec),
399 ClassTemplate->getInjectedTemplateArgs(),
406 return Response::Done();
411 if (ForConstraintInstantiation && IsFriend &&
420 return Response::ChangeDecl(LCD);
424 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
427 if (isLambdaEnclosedByTypeAliasDecl(PrimaryLambdaCallOperator,
428 TypeAlias.PrimaryTypeAliasDecl)) {
429 Result.addOuterTemplateArguments(TypeAlias.Template,
430 TypeAlias.AssociatedTemplateArguments,
445 return Response::ChangeDecl(TypeAlias.Template->getDeclContext());
450 return Response::UseNextDecl(Rec);
453Response HandleImplicitConceptSpecializationDecl(
456 Result.addOuterTemplateArguments(
460 return Response::UseNextDecl(CSD);
463Response HandleGenericDeclContext(
const Decl *CurDecl) {
464 return Response::UseNextDecl(CurDecl);
472 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
473 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
474 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
479 const Decl *CurDecl = ND;
485 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
495 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
496 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
497 CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
502 if (
const auto *VarTemplSpec =
503 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
504 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
505 }
else if (
const auto *PartialClassTemplSpec =
506 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
507 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
508 SkipForSpecialization);
509 }
else if (
const auto *ClassTemplSpec =
510 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
511 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
512 SkipForSpecialization);
513 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
514 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
515 ForConstraintInstantiation,
516 ForDefaultArgumentSubstitution);
517 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
519 ForConstraintInstantiation);
520 }
else if (
const auto *CSD =
521 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
522 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
523 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
524 R = HandleFunctionTemplateDecl(FTD,
Result);
525 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
526 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
527 }
else if (!isa<DeclContext>(CurDecl)) {
528 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
529 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
530 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
533 R = HandleGenericDeclContext(CurDecl);
538 if (R.ClearRelativeToPrimary)
539 RelativeToPrimary =
false;
541 CurDecl = R.NextDecl;
584 llvm_unreachable(
"Invalid SynthesisKind!");
614 AlreadyInstantiating = !Inst.Entity ?
false :
616 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
627 PointOfInstantiation, InstantiationRange, Entity) {}
634 PointOfInstantiation, InstantiationRange, Entity) {}
644 Template, TemplateArgs) {}
654 TemplateArgs, &DeductionInfo) {
668 PointOfInstantiation, InstantiationRange, Template, nullptr,
669 TemplateArgs, &DeductionInfo) {}
679 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
680 TemplateArgs, &DeductionInfo) {}
690 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
691 TemplateArgs, &DeductionInfo) {}
699 PointOfInstantiation, InstantiationRange, Param, nullptr,
709 PointOfInstantiation, InstantiationRange, Param, Template,
719 PointOfInstantiation, InstantiationRange, Param, Template,
728 PointOfInstantiation, InstantiationRange, Entity,
729 nullptr, TemplateArgs) {}
737 PointOfInstantiation, InstantiationRange, Param, Template,
746 PointOfInstantiation, InstantiationRange, nullptr,
747 nullptr,
std::nullopt, &DeductionInfo) {
756 PointOfInstantiation, InstantiationRange, nullptr,
757 nullptr,
std::nullopt) {}
764 PointOfInstantiation, InstantiationRange, nullptr,
765 nullptr,
std::nullopt, &DeductionInfo) {
774 PointOfInstantiation, InstantiationRange, Template, nullptr,
783 PointOfInstantiation, InstantiationRange, Template, nullptr,
784 {}, &DeductionInfo) {}
792 PointOfInstantiation, InstantiationRange, Template) {}
800 PointOfInstantiation, InstantiationRange, Template) {}
807 PointOfInstantiation, InstantiationRange, Entity) {}
827 if (!Active.isInstantiationRecord()) {
837 "forgot to remove a lookup module for a template instantiation");
856 if (!AlreadyInstantiating) {
860 {Active.Entity->getCanonicalDecl(), Active.Kind});
874 llvm::raw_string_ostream
OS(
Result);
875 llvm::ListSeparator Comma;
876 for (
const Expr *Arg : Args) {
878 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
884bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
895 diag::err_template_recursion_depth_exceeded)
897 << InstantiationRange;
898 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
908 SkipStart = Limit / 2 + Limit % 2;
913 unsigned InstantiationIdx = 0;
918 ++Active, ++InstantiationIdx) {
920 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
921 if (InstantiationIdx == SkipStart) {
924 diag::note_instantiation_contexts_suppressed)
930 switch (Active->Kind) {
932 Decl *
D = Active->Entity;
934 unsigned DiagID = diag::note_template_member_class_here;
935 if (isa<ClassTemplateSpecializationDecl>(
Record))
936 DiagID = diag::note_template_class_instantiation_here;
938 <<
Record << Active->InstantiationRange;
942 DiagID = diag::note_function_template_spec_here;
944 DiagID = diag::note_template_member_function_here;
947 << Active->InstantiationRange;
948 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(
D)) {
950 VD->isStaticDataMember()?
951 diag::note_template_static_data_member_def_here
952 : diag::note_template_variable_def_here)
954 << Active->InstantiationRange;
955 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(
D)) {
957 diag::note_template_enum_def_here)
959 << Active->InstantiationRange;
960 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(
D)) {
962 diag::note_template_nsdmi_here)
963 << FD << Active->InstantiationRange;
966 diag::note_template_class_instantiation_here)
967 << CTD << Active->InstantiationRange;
973 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
975 llvm::raw_svector_ostream
OS(TemplateArgsStr);
980 diag::note_default_arg_instantiation_here)
982 << Active->InstantiationRange;
989 diag::note_explicit_template_arg_substitution_here)
992 Active->TemplateArgs,
993 Active->NumTemplateArgs)
994 << Active->InstantiationRange;
1000 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1002 diag::note_function_template_deduction_instantiation_here)
1005 Active->TemplateArgs,
1006 Active->NumTemplateArgs)
1007 << Active->InstantiationRange;
1009 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
1010 isa<VarTemplateSpecializationDecl>(Active->Entity);
1011 bool IsTemplate =
false;
1013 if (
auto *
D = dyn_cast<TemplateDecl>(Active->Entity)) {
1015 Params =
D->getTemplateParameters();
1016 }
else if (
auto *
D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1018 Params =
D->getTemplateParameters();
1019 }
else if (
auto *
D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1021 Params =
D->getTemplateParameters();
1023 llvm_unreachable(
"unexpected template kind");
1027 diag::note_deduced_template_arg_substitution_here)
1028 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
1030 Active->NumTemplateArgs)
1031 << Active->InstantiationRange;
1037 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
1041 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1046 diag::note_default_function_arg_instantiation_here)
1048 << Active->InstantiationRange;
1053 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
1056 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1059 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1060 TemplateParams = Template->getTemplateParameters();
1063 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1064 ->getTemplateParameters();
1066 diag::note_prior_template_arg_substitution)
1067 << isa<TemplateTemplateParmDecl>(Parm)
1070 Active->TemplateArgs,
1071 Active->NumTemplateArgs)
1072 << Active->InstantiationRange;
1078 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1079 TemplateParams = Template->getTemplateParameters();
1082 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1083 ->getTemplateParameters();
1086 diag::note_template_default_arg_checking)
1088 Active->TemplateArgs,
1089 Active->NumTemplateArgs)
1090 << Active->InstantiationRange;
1096 diag::note_evaluating_exception_spec_here)
1097 << cast<FunctionDecl>(Active->Entity);
1102 diag::note_template_exception_spec_instantiation_here)
1103 << cast<FunctionDecl>(Active->Entity)
1104 << Active->InstantiationRange;
1109 diag::note_template_requirement_instantiation_here)
1110 << Active->InstantiationRange;
1114 diag::note_template_requirement_params_instantiation_here)
1115 << Active->InstantiationRange;
1120 diag::note_nested_requirement_here)
1121 << Active->InstantiationRange;
1126 diag::note_in_declaration_of_implicit_special_member)
1127 << cast<CXXRecordDecl>(Active->Entity)
1128 << llvm::to_underlying(Active->SpecialMember);
1133 diag::note_in_declaration_of_implicit_equality_comparison);
1139 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1143 auto *MD = cast<CXXMethodDecl>(FD);
1145 diag::note_member_synthesized_at)
1146 << MD->isExplicitlyDefaulted()
1152 .getNonReferenceType()
1153 .getUnqualifiedType();
1155 diag::note_comparison_synthesized_at)
1163 diag::note_rewriting_operator_as_spaceship);
1168 diag::note_in_binding_decl_init)
1169 << cast<BindingDecl>(Active->Entity);
1174 diag::note_due_to_dllexported_class)
1175 << cast<CXXRecordDecl>(Active->Entity) << !
getLangOpts().CPlusPlus11;
1180 diag::note_building_builtin_dump_struct_call)
1190 diag::note_lambda_substitution_here);
1193 unsigned DiagID = 0;
1194 if (!Active->Entity) {
1196 diag::note_nested_requirement_here)
1197 << Active->InstantiationRange;
1200 if (isa<ConceptDecl>(Active->Entity))
1201 DiagID = diag::note_concept_specialization_here;
1202 else if (isa<TemplateDecl>(Active->Entity))
1203 DiagID = diag::note_checking_constraints_for_template_id_here;
1204 else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
1205 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1206 else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
1207 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1209 assert(isa<FunctionDecl>(Active->Entity));
1210 DiagID = diag::note_checking_constraints_for_function_here;
1213 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1215 if (!isa<FunctionDecl>(Active->Entity)) {
1219 Diags.
Report(Active->PointOfInstantiation, DiagID) <<
OS.str()
1220 << Active->InstantiationRange;
1225 diag::note_constraint_substitution_here)
1226 << Active->InstantiationRange;
1230 diag::note_constraint_normalization_here)
1231 << cast<NamedDecl>(Active->Entity)->getName()
1232 << Active->InstantiationRange;
1236 diag::note_parameter_mapping_substitution_here)
1237 << Active->InstantiationRange;
1241 diag::note_building_deduction_guide_here);
1245 diag::note_template_type_alias_instantiation_here)
1246 << cast<TypeAliasTemplateDecl>(Active->Entity)
1247 << Active->InstantiationRange;
1255 return std::optional<TemplateDeductionInfo *>(
nullptr);
1260 Active != ActiveEnd;
1263 switch (Active->Kind) {
1267 if (isa<TypeAliasTemplateDecl>(Active->Entity))
1278 return std::nullopt;
1285 return std::nullopt;
1306 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1307 return Active->DeductionInfo;
1318 return std::nullopt;
1332 if (Active->SavedInNonInstantiationSFINAEContext)
1333 return std::optional<TemplateDeductionInfo *>(
nullptr);
1336 return std::nullopt;
1343 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1348 bool EvaluateConstraints =
true;
1353 TemplateInstantiator(
Sema &SemaRef,
1356 : inherited(SemaRef), TemplateArgs(TemplateArgs),
Loc(
Loc),
1359 void setEvaluateConstraints(
bool B) {
1360 EvaluateConstraints = B;
1362 bool getEvaluateConstraints() {
1363 return EvaluateConstraints;
1383 this->Entity = Entity;
1386 unsigned TransformTemplateDepth(
unsigned Depth) {
1391 int Index = getSema().ArgumentPackSubstitutionIndex;
1393 return std::nullopt;
1400 bool &ShouldExpand,
bool &RetainExpansion,
1401 std::optional<unsigned> &NumExpansions) {
1402 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
1403 PatternRange, Unexpanded,
1410 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
1420 unsigned Depth, Index;
1423 Result = TemplateArgs(Depth, Index);
1439 unsigned Depth, Index;
1449 void transformAttrs(
Decl *Old,
Decl *New) {
1455 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1457 for (
auto *New : NewDecls)
1459 Old, cast<VarDecl>(New));
1463 assert(NewDecls.size() == 1 &&
1464 "should only have multiple expansions for a pack");
1465 Decl *New = NewDecls.front();
1470 auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1472 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1473 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1474 NewTD->setInstantiatedFromMemberTemplate(
1475 OldMD->getDescribedFunctionTemplate());
1477 NewMD->setInstantiationOfMemberFunction(OldMD,
1485 if (
auto *DC = dyn_cast<DeclContext>(Old);
1486 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1527 NamedDecl *FirstQualifierInScope =
nullptr,
1528 bool AllowInjectedClassName =
false);
1530 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1531 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1532 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1534 const NoInlineAttr *A);
1535 const AlwaysInlineAttr *
1536 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1537 const AlwaysInlineAttr *A);
1538 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1545 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1547 ExprResult TransformSubstNonTypeTemplateParmExpr(
1564 return inherited::TransformFunctionProtoType(TLB, TL);
1569 auto Type = inherited::TransformInjectedClassNameType(TLB, TL);
1572 if (
Type.isNull() &&
1579 inherited::TransformType(ICT->getInjectedSpecializationType());
1590 bool Uneval =
false) {
1592 std::vector<TemplateArgument> TArgs;
1612 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1615 template<
typename Fn>
1620 Fn TransformExceptionSpec);
1623 TransformFunctionTypeParam(
ParmVarDecl *OldParm,
int indexAdjustment,
1624 std::optional<unsigned> NumExpansions,
1625 bool ExpectParameterPack);
1627 using inherited::TransformTemplateTypeParmType;
1632 bool SuppressObjCLifetime);
1634 QualType BuildSubstTemplateTypeParmType(
1636 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
1642 using inherited::TransformSubstTemplateTypeParmPackType;
1646 bool SuppressObjCLifetime);
1653 unsigned TypeAliasDeclDepth = CCS.Entity->getTemplateDepth();
1655 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1657 return inherited::ComputeLambdaDependency(LSI);
1664 return inherited::TransformLambdaExpr(
E);
1671 assert(PVD &&
"null in a parameter list");
1672 if (!PVD->hasDefaultArg())
1674 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1683 { UninstExpr }, UninstExpr->
getType());
1685 PVD->setDefaultArg(ErrorResult.
get());
1688 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1702 return inherited::TransformLambdaBody(
E, Body);
1707 ExprResult TransReq = inherited::TransformRequiresExpr(
E);
1710 assert(TransReq.
get() !=
E &&
1711 "Do not change value of isSatisfied for the existing expression. "
1712 "Create a new expression instead.");
1713 if (
E->getBody()->isDependentContext()) {
1719 if (Trap.hasErrorOccurred())
1725 bool TransformRequiresExprRequirements(
1728 bool SatisfactionDetermined =
false;
1731 if (!SatisfactionDetermined) {
1732 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1733 TransReq = TransformTypeRequirement(TypeReq);
1734 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1735 TransReq = TransformExprRequirement(ExprReq);
1737 TransReq = TransformNestedRequirement(
1738 cast<concepts::NestedRequirement>(Req));
1747 SatisfactionDetermined =
true;
1750 Transformed.push_back(TransReq);
1757 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1761 Owner, TemplateArgs);
1762 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1763 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1781 transformNonTypeTemplateParmRef(
Decl *AssociatedDecl,
1784 std::optional<unsigned> PackIndex);
1788bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
1795 getSema().MarkDeclarationsReferencedInType(
Loc,
T);
1820 TTP->getPosition()))
1825 if (TTP->isParameterPack()) {
1827 "Missing argument pack");
1833 "Wrong kind of template template argument");
1845 Decl *Inst = getSema().SubstDecl(
D, getSema().
CurContext, TemplateArgs);
1849 getSema().CurrentInstantiationScope->InstantiatedLocal(
D, Inst);
1853bool TemplateInstantiator::TransformExceptionSpec(
1860 return inherited::TransformExceptionSpec(
Loc, ESI, Exceptions, Changed);
1864TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *
D,
1878 "Missing argument pack");
1888 return cast_or_null<NamedDecl>(TransformDecl(
Loc,
D));
1891 return Tag->getDecl();
1894 getSema().Diag(
Loc, diag::err_nested_name_spec_non_tag) <<
T;
1899 return cast_or_null<NamedDecl>(TransformDecl(
Loc,
D));
1903TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
1909 StartLoc, NameLoc, Name);
1911 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1915VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
1918 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
1920 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1925TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
1943 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
1952 return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc,
T);
1955TemplateName TemplateInstantiator::TransformTemplateName(
1958 bool AllowInjectedClassName) {
1960 = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1967 TTP->getPosition()))
1977 "unexpected pack arguments in template rewrite");
1981 "unexpected nontype template argument kind in template rewrite");
1985 auto [AssociatedDecl, Final] =
1987 std::optional<unsigned> PackIndex;
1990 "Missing argument pack");
1996 return getSema().Context.getSubstTemplateTemplateParmPack(
1997 Arg, AssociatedDecl, TTP->
getIndex(), Final);
2000 PackIndex = getPackIndex(Arg);
2005 assert(!Template.
isNull() &&
"Null template template argument");
2009 return getSema().Context.getSubstTemplateTemplateParm(
2010 Template, AssociatedDecl, TTP->
getIndex(), PackIndex);
2015 = Name.getAsSubstTemplateTemplateParmPack()) {
2022 if (SubstPack->getFinal())
2024 return getSema().Context.getSubstTemplateTemplateParm(
2025 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2026 getPackIndex(Pack));
2029 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
2030 FirstQualifierInScope,
2031 AllowInjectedClassName);
2039 return getSema().BuildPredefinedExpr(
E->getLocation(),
E->getIdentKind());
2043TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *
E,
2060 "unexpected pack arguments in template rewrite");
2064 "unexpected nontype template argument kind in template rewrite");
2071 std::optional<unsigned> PackIndex;
2074 "Missing argument pack");
2092 E->getLocation(), Arg, AssociatedDecl, NTTP->
getPosition());
2094 PackIndex = getPackIndex(Arg);
2098 return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP,
E->getLocation(),
2102const CXXAssumeAttr *
2103TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2104 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2108 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2113 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2118TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2119 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2121 if (TransformedExpr == LH->getValue())
2126 LH->getSemanticSpelling() ==
2127 LoopHintAttr::Pragma_unroll))
2130 LoopHintAttr::OptionType Option = LH->getOption();
2131 LoopHintAttr::LoopHintState State = LH->getState();
2133 llvm::APSInt ValueAPS =
2136 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2137 Option = LoopHintAttr::Unroll;
2138 State = LoopHintAttr::Disable;
2143 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2144 TransformedExpr, *LH);
2146const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2147 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2153const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2154 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2161const CodeAlignAttr *
2162TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2163 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2164 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2167ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
2170 std::optional<unsigned> PackIndex) {
2175 auto SubstParamType = [&] {
2182 T = cast<PackExpansionType>(
T)->getPattern();
2186 bool refParam =
false;
2192 Expr *argExpr =
arg.getAsExpr();
2197 QualType paramType = SubstParamType();
2212 VD = cast_or_null<ValueDecl>(
2218 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2219 assert(!paramType.
isNull() &&
"type substitution failed for param type");
2220 assert(!paramType->
isDependentType() &&
"param type still dependent");
2224 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2235 Expr *resultExpr = result.
get();
2239 AssociatedDecl, parm->
getIndex(), PackIndex, refParam);
2243TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
2253 return transformNonTypeTemplateParmRef(
2254 E->getAssociatedDecl(),
E->getParameterPack(),
2255 E->getParameterPackLocation(), Arg, getPackIndex(Pack));
2259TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
2261 ExprResult SubstReplacement =
E->getReplacement();
2262 if (!isa<ConstantExpr>(SubstReplacement.
get()))
2263 SubstReplacement = TransformExpr(
E->getReplacement());
2292 SubstReplacement.
get(), SugaredConverted,
2296 return transformNonTypeTemplateParmRef(
E->getAssociatedDecl(),
2298 SugaredConverted,
E->getPackIndex());
2304 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
2315 return RebuildVarDeclRefExpr(VD,
E->
getExprLoc());
2325 Vars.reserve(
E->getNumExpansions());
2336 E->getParameterPackLocation(), Vars);
2337 getSema().MarkFunctionParmPackReferenced(PackExpr);
2342TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *
E,
2345 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found
2346 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2347 assert(
Found &&
"no instantiation for parameter pack");
2349 Decl *TransformedDecl;
2350 if (DeclArgumentPack *Pack =
Found->dyn_cast<DeclArgumentPack *>()) {
2359 getSema().MarkFunctionParmPackReferenced(PackExpr);
2363 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
2369 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl),
E->
getExprLoc());
2373TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *
E) {
2380 return TransformTemplateParmRefExpr(
E, NTTP);
2387 if (
VarDecl *PD = dyn_cast<VarDecl>(
D))
2389 return TransformFunctionParmPackRefExpr(
E, PD);
2391 return inherited::TransformDeclRefExpr(
E);
2394ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2396 assert(!cast<FunctionDecl>(
E->getParam()->getDeclContext())->
2397 getDescribedFunctionTemplate() &&
2398 "Default arg expressions are never formed in dependent cases.");
2400 E->getUsedLocation(), cast<FunctionDecl>(
E->getParam()->getDeclContext()),
2404template<
typename Fn>
2409 Fn TransformExceptionSpec) {
2412 return inherited::TransformFunctionProtoType(
2413 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2416ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2418 std::optional<unsigned> NumExpansions,
bool ExpectParameterPack) {
2420 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2421 ExpectParameterPack, EvaluateConstraints);
2427QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2429 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
2435 if (SuppressObjCLifetime) {
2437 RQs = Replacement.getQualifiers();
2448 QualType Result = getSema().Context.getSubstTemplateTypeParmType(
2449 Replacement, AssociatedDecl, Index, PackIndex);
2457TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
2459 bool SuppressObjCLifetime) {
2483 "unexpected pack arguments in template rewrite");
2487 "unexpected nontype template argument kind in template rewrite");
2493 auto [AssociatedDecl, Final] =
2495 std::optional<unsigned> PackIndex;
2496 if (
T->isParameterPack()) {
2498 "Missing argument pack");
2504 QualType Result = getSema().Context.getSubstTemplateTypeParmPackType(
2505 AssociatedDecl,
T->getIndex(), Final, Arg);
2513 PackIndex = getPackIndex(Arg);
2518 "Template argument kind mismatch");
2520 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2521 AssociatedDecl,
T->getIndex(),
2531 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2535 T->isParameterPack(), NewTTPDecl);
2541QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2543 bool SuppressObjCLifetime) {
2546 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2551 if (NewReplaced !=
T->getAssociatedDecl())
2552 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2553 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2562 return BuildSubstTemplateTypeParmType(
2563 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2577 ErrorLoc = PDA.first;
2582 llvm::raw_svector_ostream
OS(Entity);
2586 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2593 llvm::raw_svector_ostream
OS(Entity);
2597 C.backupStr(Entity),
2598 Location, StringRef()};
2601ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2615 if (getDerived().TransformFunctionTypeParams(
2616 KWLoc, Params,
nullptr,
nullptr, PTypes,
2617 &TransParams, PInfos, &ErrorIdx) ||
2618 Trap.hasErrorOccurred()) {
2624 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2625 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2627 TransReqs, RBraceLoc);
2638 if (AlwaysRebuild())
2639 return RebuildTypeRequirement(
2649 if (TypeInst.isInvalid())
2652 if (!TransType || Trap.hasErrorOccurred())
2654 [&] (llvm::raw_ostream&
OS) {
2657 return RebuildTypeRequirement(TransType);
2667 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2676 if (ExprInst.isInvalid())
2679 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2682 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2687 TransExpr = TransExprRes.
get();
2690 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2692 if (RetReq.isEmpty())
2693 TransRetReq.emplace();
2694 else if (RetReq.isSubstitutionFailure())
2695 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2696 else if (RetReq.isTypeConstraint()) {
2698 RetReq.getTypeConstraintTemplateParameterList();
2702 if (TPLInst.isInvalid())
2705 if (!TPL || Trap.hasErrorOccurred())
2707 [&] (llvm::raw_ostream&
OS) {
2708 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2713 TransRetReq.emplace(TPL);
2716 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2717 if (
Expr *
E = TransExpr.dyn_cast<
Expr *>())
2719 std::move(*TransRetReq));
2720 return RebuildExprRequirement(
2726TemplateInstantiator::TransformNestedRequirement(
2731 if (AlwaysRebuild())
2740 if (!getEvaluateConstraints()) {
2742 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2762 if (ConstrInst.isInvalid())
2766 nullptr, {Req->getConstraintExpr()},
Result, TemplateArgs,
2769 TransConstraint =
Result[0];
2770 assert(!Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
2771 "by CheckConstraintSatisfaction.");
2777 if (TransConstraint.
isInvalid() || !TransConstraint.
get() ||
2780 llvm::raw_svector_ostream
OS(Entity);
2794 bool AllowDeducedTST) {
2796 "Cannot perform an instantiation without some context on the "
2797 "instantiation stack");
2803 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2804 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2805 : Instantiator.TransformType(
T);
2813 "Cannot perform an instantiation without some context on the "
2814 "instantiation stack");
2828 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2843 "Cannot perform an instantiation without some context on the "
2844 "instantiation stack");
2851 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc, Entity);
2852 return Instantiator.TransformType(
T);
2860 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2883 bool EvaluateConstraints) {
2885 "Cannot perform an instantiation without some context on the "
2886 "instantiation stack");
2891 TemplateInstantiator Instantiator(*
this, Args,
Loc, Entity);
2892 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2908 Result = Instantiator.TransformFunctionProtoType(
2909 TLB, Proto, ThisContext, ThisTypeQuals,
2911 bool &Changed) {
return false; });
2913 Result = Instantiator.TransformType(TLB, TL);
2927 bool Changed =
false;
2929 return Instantiator.TransformExceptionSpec(
Loc, ESI, ExceptionStorage,
2940 ESI, ExceptionStorage, Args))
2949 struct GetContainedInventedTypeParmVisitor :
2950 public TypeVisitor<GetContainedInventedTypeParmVisitor,
2951 TemplateTypeParmDecl *> {
2952 using TypeVisitor<GetContainedInventedTypeParmVisitor,
2958 return Visit(
T.getTypePtr());
2963 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
2965 return T->getDecl();
2972 return Visit(
T->getNamedType());
2984 return Visit(
T->getPointeeTypeAsWritten());
2992 return Visit(
T->getElementType());
2997 return Visit(
T->getElementType());
3001 return Visit(
T->getElementType());
3005 return VisitFunctionType(
T);
3013 return Visit(
T->getInnerType());
3017 return Visit(
T->getModifiedType());
3021 return Visit(
T->getUnderlyingType());
3025 return Visit(
T->getOriginalType());
3029 return Visit(
T->getPattern());
3038 bool EvaluateConstraints) {
3042 if (!EvaluateConstraints) {
3069 int indexAdjustment, std::optional<unsigned> NumExpansions,
3070 bool ExpectParameterPack,
bool EvaluateConstraint) {
3079 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
3090 }
else if (ExpectParameterPack) {
3096 diag::err_function_parameter_pack_without_parameter_packs)
3120 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
3122 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3127 if (Inst && !Inst->getTypeConstraint()) {
3196 "Cannot perform an instantiation without some context on the "
3197 "instantiation stack");
3199 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc,
3201 return Instantiator.TransformFunctionTypeParams(
3202 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3220 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
3232 std::unique_ptr<LocalInstantiationScope> LIS;
3240 LIS = std::make_unique<LocalInstantiationScope>(*
this);
3243 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3265 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3292 for (
const auto &
Base : Pattern->
bases()) {
3293 if (!
Base.getType()->isDependentType()) {
3295 if (RD->isInvalidDecl())
3304 if (
Base.isPackExpansion()) {
3310 bool ShouldExpand =
false;
3311 bool RetainExpansion =
false;
3312 std::optional<unsigned> NumExpansions;
3314 Base.getSourceRange(),
3316 TemplateArgs, ShouldExpand,
3325 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3330 Base.getSourceRange().getBegin(),
3339 Base.getSourceRange(),
3341 Base.getAccessSpecifierAsWritten(),
3344 InstantiatedBases.push_back(InstantiatedBase);
3353 EllipsisLoc =
Base.getEllipsisLoc();
3357 Base.getSourceRange().getBegin(),
3362 Base.getSourceRange().getBegin(),
3373 Base.getSourceRange(),
3375 Base.getAccessSpecifierAsWritten(),
3378 InstantiatedBases.push_back(InstantiatedBase);
3410 Pattern, PatternDef, TSK, Complain))
3413 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3414 llvm::TimeTraceMetadata M;
3415 llvm::raw_string_ostream
OS(M.Detail);
3418 if (llvm::isTimeTraceVerbose()) {
3426 Pattern = PatternDef;
3432 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3434 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3435 Spec->setTemplateSpecializationKind(TSK);
3436 Spec->setPointOfInstantiation(PointOfInstantiation);
3444 "instantiating class definition");
3462 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3488 bool MightHaveConstexprVirtualFunctions =
false;
3499 if (
Member->getDeclContext() != Pattern)
3506 if (isa<BlockDecl>(
Member) ||
3507 (isa<CXXRecordDecl>(
Member) && cast<CXXRecordDecl>(
Member)->isLambda()))
3510 if (
Member->isInvalidDecl()) {
3517 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3518 Fields.push_back(Field);
3519 }
else if (
EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3525 Enum->isCompleteDefinition()) {
3527 assert(MSInfo &&
"no spec info for member enum specialization");
3532 if (SA->isFailed()) {
3538 }
else if (
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3541 MightHaveConstexprVirtualFunctions =
true;
3562 if (ParsingClassDepth == 0)
3567 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3568 E = LateAttrs.end(); I !=
E; ++I) {
3573 auto *ND = cast<NamedDecl>(I->NewDecl);
3574 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3576 ND->isCXXInstanceMember());
3581 I->NewDecl->addAttr(NewAttr);
3610 P->first,
P->second)) {
3623 P->first,
P->second)) {
3640 else if (MightHaveConstexprVirtualFunctions)
3657 Pattern, PatternDef, TSK,
true))
3659 Pattern = PatternDef;
3665 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3674 "instantiating enum definition");
3709 "pattern and instantiation disagree about init style");
3717 Diag(PointOfInstantiation,
3718 diag::err_default_member_initializer_not_yet_parsed)
3719 << OutermostClass << Pattern;
3720 Diag(Pattern->getEndLoc(),
3721 diag::note_default_member_initializer_not_yet_parsed);
3731 Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3736 "instantiating default member init");
3744 PointOfInstantiation, Instantiation,
CurContext};
3755 assert((!
Init || !isa<ParenListExpr>(
Init)) &&
"call-style init in class");
3760 L->DefaultMemberInitializerInstantiated(Instantiation);
3769 struct PartialSpecMatchResult {
3784 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3829 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3842 Matched.push_back(PartialSpecMatchResult());
3843 Matched.back().Partial = Partial;
3852 if (Matched.size() >= 1) {
3854 if (Matched.size() == 1) {
3867 PEnd = Matched.end();
3870 P->Partial, Best->Partial, PointOfInstantiation) ==
3877 bool Ambiguous =
false;
3879 PEnd = Matched.end();
3882 P->Partial, Best->Partial,
3883 PointOfInstantiation) != Best->Partial) {
3893 S.
Diag(PointOfInstantiation,
3894 diag::err_partial_spec_ordering_ambiguous)
3895 << ClassTemplateSpec;
3899 PEnd = Matched.end();
3901 S.
Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
3903 P->Partial->getTemplateParameters(), *
P->Args);
3918 if (
auto *PartialSpec =
3921 while (PartialSpec->getInstantiatedFromMember()) {
3924 if (PartialSpec->isMemberSpecialization())
3927 PartialSpec = PartialSpec->getInstantiatedFromMember();
3929 Pattern = PartialSpec;
3951 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
3958 ClassTemplateSpec, TSK);
3963 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
3979 "Unexpected template specialization kind!");
3980 for (
auto *
D : Instantiation->
decls()) {
3981 bool SuppressNew =
false;
3982 if (
auto *
Function = dyn_cast<FunctionDecl>(
D)) {
3984 Function->getInstantiatedFromMemberFunction()) {
3986 if (
Function->isIneligibleOrNotSelected())
3989 if (
Function->getTrailingRequiresClause()) {
3997 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4001 Function->getMemberSpecializationInfo();
4002 assert(MSInfo &&
"No member specialization information?");
4024 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4034 std::make_pair(
Function, PointOfInstantiation));
4037 }
else if (
auto *Var = dyn_cast<VarDecl>(
D)) {
4038 if (isa<VarTemplateSpecializationDecl>(Var))
4042 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4046 assert(MSInfo &&
"No member specialization information?");
4075 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(
D)) {
4076 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4084 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4089 assert(MSInfo &&
"No member specialization information?");
4115 assert(Pattern &&
"Missing instantiated-from-template information");
4117 if (!
Record->getDefinition()) {
4138 Record->getTemplateSpecializationKind() ==
4140 Record->setTemplateSpecializationKind(TSK);
4145 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4149 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(
D)) {
4151 assert(MSInfo &&
"No member specialization information?");
4158 PointOfInstantiation, TSK,
Enum,
4164 if (
Enum->getDefinition())
4167 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4168 assert(Pattern &&
"Missing instantiated-from-template information");
4179 }
else if (
auto *Field = dyn_cast<FieldDecl>(
D)) {
4186 ClassPattern->
lookup(Field->getDeclName());
4219 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4222 return Instantiator.TransformStmt(S);
4230 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc, Entity);
4231 return Instantiator.TransformTemplateArgument(Input, Output);
4238 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4240 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4248 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4251 return Instantiator.TransformExpr(
E);
4267 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4269 Instantiator.setEvaluateConstraints(
false);
4270 return Instantiator.TransformExpr(
E);
4275 bool CXXDirectInit) {
4276 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4278 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4287 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4290 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4300 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4302 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4308 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4310 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4317 TemplateInstantiator Instantiator(*
this, TemplateArgs,
Loc,
4320 SS.
Adopt(QualifierLoc);
4321 return Instantiator.TransformTemplateName(SS, Name,
Loc);
4329 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(
D)) {
4330 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4331 unsigned i = PV->getFunctionScopeIndex();
4334 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4342llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4346 Current = Current->Outer) {
4349 const Decl *CheckD =
D;
4351 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4352 if (
Found != Current->LocalDecls.end())
4353 return &
Found->second;
4357 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4358 CheckD = Tag->getPreviousDecl();
4364 if (!Current->CombineWithOuterScope)
4370 if (isa<NonTypeTemplateParmDecl>(
D) || isa<TemplateTypeParmDecl>(
D) ||
4371 isa<TemplateTemplateParmDecl>(
D))
4376 if (RD->isLocalClass())
4381 if (isa<EnumDecl>(
D))
4386 if (isa<TypedefNameDecl>(
D) &&
4393 assert(isa<LabelDecl>(
D) &&
"declaration not instantiated in this scope");
4399 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[
D];
4400 if (Stored.isNull()) {
4404 while (Current->CombineWithOuterScope && Current->Outer) {
4405 Current = Current->Outer;
4406 assert(!Current->LocalDecls.contains(
D) &&
4407 "Instantiated local in inner and outer scopes");
4412 Pack->push_back(cast<VarDecl>(Inst));
4414 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
4422 Pack->push_back(Inst);
4429 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4430 assert(!Current->LocalDecls.contains(
D) &&
4431 "Creating local pack after instantiation of local");
4435 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[
D];
4438 ArgumentPacks.push_back(Pack);
4443 if (llvm::is_contained(*Pack,
D))
4450 unsigned NumExplicitArgs) {
4451 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4452 "Already have a partially-substituted pack");
4453 assert((!PartiallySubstitutedPack
4454 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4455 "Wrong number of arguments in partially-substituted pack");
4456 PartiallySubstitutedPack = Pack;
4457 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4458 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4463 unsigned *NumExplicitArgs)
const {
4465 *ExplicitArgs =
nullptr;
4466 if (NumExplicitArgs)
4467 *NumExplicitArgs = 0;
4470 Current = Current->Outer) {
4471 if (Current->PartiallySubstitutedPack) {
4473 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4474 if (NumExplicitArgs)
4475 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4477 return Current->PartiallySubstitutedPack;
4480 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 &ASTCtx, QualType Ty)
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,...
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...
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 invoked l...
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.
A pointer to member type per C++ 8.3.3 - Pointers to members.
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.
Sugar for parentheses used when specifying types.
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)
SourceLocation getExplicitObjectParamThisLoc() const
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
void setExplicitObjectParameterLoc(SourceLocation Loc)
Expr * getUninstantiatedDefaultArg()
unsigned getFunctionScopeDepth() const
void setHasInheritedDefaultArg(bool I=true)
PointerType - C99 6.7.5.1 - Pointer Declarators.
[C99 6.4.2.2] - A predefined identifier such as func.
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.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
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.
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
Scope - A scope is a transient data structure that is used while parsing the program.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
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
bool isComparison() const
CXXSpecialMemberKind asSpecialMember() 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.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
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.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc, NamedDecl *TemplateParam=nullptr)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
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.
void ActOnFinishDelayedMemberInitializers(Decl *Record)
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)
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.
ExprResult BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
ExprResult SubstConstraintExprWithoutSatisfaction(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
ASTContext & getASTContext() const
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
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
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 ...
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
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)
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero)
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)
Check the validity of a C++ base class 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.
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const DeclContext *DC=nullptr, bool Final=false, std::optional< ArrayRef< TemplateArgument > > Innermost=std::nullopt, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false, bool ForDefaultArgumentSubstitution=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, const IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
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.
bool CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, TemplateSpecializationKind ActOnExplicitInstantiationNewTSK, NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK, SourceLocation PrevPtOfInstantiation, bool &SuppressNew)
Diagnose cases where we have an explicit template specialization before/after an explicit template in...
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.
bool InstantiateClass(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK, bool Complain=true)
Instantiate the definition of a class from a given pattern.
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, ConceptDecl *NamedConcept, NamedDecl *FoundDecl, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentLoc &Output, SourceLocation Loc={}, const DeclarationName &Entity={})
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, FunctionDecl *Function, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given function from its template.
bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, const MultiLevelTemplateArgumentList &TemplateArgs, bool ForCallExpr=false)
Substitute the given template arguments into the default argument.
ExprResult SubstConstraintExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
unsigned LastEmittedCodeSynthesisContextDepth
The depth of the context stack at the point when the most recent error or warning was produced.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &SugaredConverted, SmallVectorImpl< TemplateArgument > &CanonicalConverted, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
SourceManager & SourceMgr
DiagnosticsEngine & Diags
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier * > Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation.
ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
ExprResult BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc, NamedDecl *TemplateParam=nullptr)
Given a non-type template argument that refers to a declaration and the type of its corresponding non...
bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Perform substitution on the base class specifiers of the given class template specialization.
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
ASTMutationListener * getASTMutationListener() const
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
TypeSourceInfo * SubstFunctionDeclType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, bool EvaluateConstraints=true)
A form of SubstType intended specifically for instantiating the type of a FunctionDecl.
Encodes a location in the source.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
A trivial tuple used to represent a source range.
Represents a C++11 static_assert declaration.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
A structure for storing an already-substituted template template parameter pack.
Wrapper for substituted template type parameters.
Represents the result of substituting a set of types for a template type parameter pack.
Wrapper for substituted template type parameters.
Represents the declaration of a struct/union/class/enum.
void setTagKind(TagKind TK)
SourceRange getBraceRange() const
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
StringRef getKindName() const
void startDefinition()
Starts the definition of this tag declaration.
TagKind getTagKind() const
void setBraceRange(SourceRange R)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool isNull() const
Determine whether this template argument has no value.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ Pack
The template argument is actually a parameter pack.
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
void disableLateAttributeInstantiation()
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
void setEvaluateConstraints(bool B)
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
LocalInstantiationScope * getStartingScope() const
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
bool isNull() const
Determine whether this template name is NULL.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation getTemplateLoc() const
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
SourceLocation getLocation() const
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set.
Represents a type template specialization; the template must be a class template, a type alias templa...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
bool isParameterPack() const
Returns whether this is a parameter pack.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
Wrapper for template type parameters.
bool isParameterPack() const
unsigned getIndex() const
unsigned getDepth() const
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
const DeclarationNameInfo & getConceptNameInfo() const
ConceptReference * getConceptReference() const
void setLocStart(SourceLocation L)
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc)
Pushes 'T' with all locations pointing to 'Loc'.
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
SourceLocation getNameLoc() const
void setNameLoc(SourceLocation Loc)
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
The base class of the type hierarchy.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
bool isClassScopeExplicitSpecialization() const
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Represents a GCC generic vector type.
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
bool isExprSubstitutionFailure() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
bool hasInvalidConstraint() const
Expr * getConstraintExpr() const
StringRef getInvalidConstraintEntity()
A static requirement that can be used in a requires-expression to check properties of types and expre...
A requires-expression requirement which queries the existence of a type name or type template special...
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Provides information about an attempted template argument deduction, whose success or failure was des...
TemplateArgumentList * takeCanonical()
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
void takeSFINAEDiagnostic(PartialDiagnosticAt &PD)
Take ownership of the SFINAE diagnostic.
Defines the clang::TargetInfo interface.
Requirement::SubstitutionDiagnostic * createSubstDiagAt(Sema &S, SourceLocation Location, EntityPrinter Printer)
create a Requirement::SubstitutionDiagnostic with only a SubstitutedEntity and DiagLoc using Sema's a...
llvm::function_ref< void(llvm::raw_ostream &)> EntityPrinter
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
The JSON file list parser is used to communicate input to InstallAPI.
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
NamedDecl * getAsNamedDecl(TemplateParameter P)
bool isStackNearlyExhausted()
Determine whether the stack is nearly exhausted.
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
TagTypeKind
The kind of a tag type.
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema's representation of template deduction information to the form used in overload-can...
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
TemplateDeductionResult
Describes the result of template argument deduction.
@ Success
Template argument deduction was successful.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ None
No keyword precedes the qualified type name.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.
ExceptionSpecInfo ExceptionSpec
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation,...
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
SynthesisKind
The kind of template instantiation we are performing.
@ MarkingClassDllexported
We are marking a class as __dllexport.
@ RequirementParameterInstantiation
@ DefaultTemplateArgumentInstantiation
We are instantiating a default argument for a template parameter.
@ ExplicitTemplateArgumentSubstitution
We are substituting explicit template arguments provided for a function template.
@ DefaultTemplateArgumentChecking
We are checking the validity of a default template argument that has been used when naming a template...
@ InitializingStructuredBinding
We are initializing a structured binding.
@ ExceptionSpecInstantiation
We are instantiating the exception specification for a function template which was deferred until it ...
@ NestedRequirementConstraintsCheck
We are checking the satisfaction of a nested requirement of a requires expression.
@ BuildingBuiltinDumpStructCall
We are building an implied call from __builtin_dump_struct.
@ ParameterMappingSubstitution
@ DefiningSynthesizedFunction
We are defining a synthesized function (such as a defaulted special member).
@ Memoization
Added for Template instantiation observation.
@ ConstraintNormalization
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
@ TypeAliasTemplateInstantiation
We are instantiating a type alias template declaration.
@ BuildingDeductionGuides
We are building deduction guides for a class.
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
@ PriorTemplateArgumentSubstitution
We are substituting prior template arguments into a new template parameter.
@ ExceptionSpecEvaluation
We are computing the exception specification for a defaulted special member function.
@ TemplateInstantiation
We are instantiating a template declaration.
@ DeclaringSpecialMember
We are declaring an implicit special member function.
@ DeclaringImplicitEqualityComparison
We are declaring an implicit 'operator==' for a defaulted 'operator<=>'.
@ DefaultFunctionArgumentInstantiation
We are instantiating a default argument for a function.
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Decl * Entity
The entity that is being synthesized.
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
A stack object to be created when performing template instantiation.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template,...
void Clear()
Note that we have finished instantiating this template.
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)