38#include "llvm/ADT/SmallVectorExtras.h"
39#include "llvm/ADT/StringExtras.h"
40#include "llvm/Support/ErrorHandling.h"
41#include "llvm/Support/SaveAndRestore.h"
42#include "llvm/Support/TimeProfiler.h"
55 const Decl *NextDecl =
nullptr;
57 bool ClearRelativeToPrimary =
true;
58 static Response Done() {
63 static Response ChangeDecl(
const Decl *ND) {
68 static Response ChangeDecl(
const DeclContext *Ctx) {
74 static Response UseNextDecl(
const Decl *CurDecl) {
78 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
79 Response R = Response::UseNextDecl(CurDecl);
80 R.ClearRelativeToPrimary =
false;
89getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
91 return LambdaCallOperator;
93 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
95 FTD && FTD->getInstantiatedFromMemberTemplate()) {
97 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
104 ->getInstantiatedFromMemberFunction())
105 LambdaCallOperator = Prev;
109 return LambdaCallOperator;
112struct EnclosingTypeAliasTemplateDetails {
122EnclosingTypeAliasTemplateDetails
123getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
126 TypeAliasTemplateInstantiation)
128 EnclosingTypeAliasTemplateDetails Result;
130 *
Next = TATD->getInstantiatedFromMemberTemplate();
134 CSC.template_arguments(),
137 Result.PrimaryTypeAliasDecl =
Next;
138 Next =
Next->getInstantiatedFromMemberTemplate();
151bool isLambdaEnclosedByTypeAliasDecl(
155 Visitor(
const FunctionDecl *CallOperator) : CallOperator(CallOperator) {}
156 bool VisitLambdaExpr(
LambdaExpr *LE)
override {
159 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
168 return !Visitor(getPrimaryTemplateOfGenericLambda(LambdaCallOperator))
169 .TraverseType(Underlying);
176 bool SkipForSpecialization) {
180 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
185 return Response::Done();
190 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
193 dyn_cast<VarTemplatePartialSpecializationDecl *>(Specialized)) {
194 if (!SkipForSpecialization)
195 Result.addOuterTemplateArguments(
198 if (Partial->isMemberSpecialization())
199 return Response::Done();
202 if (!SkipForSpecialization)
203 Result.addOuterTemplateArguments(
207 return Response::Done();
209 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
221 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
222 Result.addOuterTemplateArguments(std::nullopt);
223 return Response::Done();
226Response HandlePartialClassTemplateSpec(
229 if (!SkipForSpecialization)
231 return Response::Done();
238 bool SkipForSpecialization) {
243 return Response::Done();
245 if (!SkipForSpecialization)
246 Result.addOuterTemplateArguments(
255 return Response::Done();
261 if (
auto *InstFromPartialTempl =
264 return Response::ChangeDecl(
265 InstFromPartialTempl->getLexicalDeclContext());
267 return Response::UseNextDecl(ClassTemplSpec);
273 bool ForConstraintInstantiation,
274 bool ForDefaultArgumentSubstitution) {
276 if (!RelativeToPrimary &&
277 Function->getTemplateSpecializationKindForInstantiation() ==
279 return Response::Done();
281 if (!RelativeToPrimary &&
286 return Response::UseNextDecl(Function);
288 Function->getTemplateSpecializationArgs()) {
290 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
291 TemplateArgs->asArray(),
294 if (RelativeToPrimary &&
295 (Function->getTemplateSpecializationKind() ==
297 (Function->getFriendObjectKind() &&
298 !Function->getPrimaryTemplate()->getFriendObjectKind())))
299 return Response::UseNextDecl(Function);
303 assert(Function->getPrimaryTemplate() &&
"No function template?");
304 if (!ForDefaultArgumentSubstitution &&
305 Function->getPrimaryTemplate()->isMemberSpecialization())
306 return Response::Done();
309 if (!ForConstraintInstantiation &&
311 return Response::Done();
313 }
else if (
auto *
Template = Function->getDescribedFunctionTemplate()) {
315 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
316 "Outer template not instantiated?");
317 if (ForConstraintInstantiation) {
325 Result.addOuterTemplateArguments(
Template, Inst.template_arguments(),
336 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
337 Function->getNonTransparentDeclContext()->isFileContext() &&
339 return Response::ChangeDecl(Function->getLexicalDeclContext());
342 if (ForConstraintInstantiation && Function->getFriendObjectKind())
343 return Response::ChangeDecl(Function->getLexicalDeclContext());
344 return Response::UseNextDecl(Function);
347Response HandleFunctionTemplateDecl(
Sema &SemaRef,
351 Result.addOuterTemplateArguments(
364 Ty = std::exchange(NextTy,
nullptr)) {
367 NextTy = P.getAsType();
368 const auto *TSTy = dyn_cast<TemplateSpecializationType>(Ty);
390 if (TSTy->isCurrentInstantiation()) {
391 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
393 Arguments = CTD->getInjectedTemplateArgs(SemaRef.
Context);
395 dyn_cast<ClassTemplateSpecializationDecl>(RD))
396 Arguments =
Specialization->getTemplateInstantiationArgs().asArray();
398 Result.addOuterTemplateArguments(
399 TSTy->getTemplateName().getAsTemplateDecl(), Arguments,
410 bool ForConstraintInstantiation) {
413 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
414 "Outer template not instantiated?");
415 if (ClassTemplate->isMemberSpecialization())
416 return Response::Done();
417 if (ForConstraintInstantiation)
418 Result.addOuterTemplateArguments(
420 ClassTemplate->getInjectedTemplateArgs(SemaRef.
Context),
427 return Response::Done();
432 if (ForConstraintInstantiation && IsFriend &&
441 return Response::ChangeDecl(LCD);
445 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef);
446 ForConstraintInstantiation &&
TypeAlias) {
449 Result.addOuterTemplateArguments(
TypeAlias.Template,
465 return Response::ChangeDecl(
TypeAlias.Template->getDeclContext());
470 return Response::UseNextDecl(Rec);
473Response HandleImplicitConceptSpecializationDecl(
476 Result.addOuterTemplateArguments(
480 return Response::UseNextDecl(CSD);
483Response HandleGenericDeclContext(
const Decl *CurDecl) {
484 return Response::UseNextDecl(CurDecl);
492 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
493 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
494 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
499 const Decl *CurDecl = ND;
502 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
512 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
513 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
515 : Response::UseNextDecl(CurDecl).NextDecl;
521 if (
const auto *VarTemplSpec =
522 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
523 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
524 }
else if (
const auto *PartialClassTemplSpec =
525 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
526 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
527 SkipForSpecialization);
528 }
else if (
const auto *ClassTemplSpec =
529 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
530 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
531 SkipForSpecialization);
532 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
533 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
534 ForConstraintInstantiation,
535 ForDefaultArgumentSubstitution);
536 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
538 ForConstraintInstantiation);
539 }
else if (
const auto *CSD =
540 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
541 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
542 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
543 R = HandleFunctionTemplateDecl(*
this, FTD,
Result);
544 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
545 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
547 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
548 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
549 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
552 R = HandleGenericDeclContext(CurDecl);
557 if (R.ClearRelativeToPrimary)
558 RelativeToPrimary =
false;
560 CurDecl = R.NextDecl;
603 llvm_unreachable(
"Invalid SynthesisKind!");
615 if (
SemaRef.Diags.hasFatalErrorOccurred() &&
616 SemaRef.hasUncompilableErrorOccurred()) {
630 Inst.InConstraintSubstitution =
632 Inst.InParameterMappingSubstitution =
634 if (!
SemaRef.CodeSynthesisContexts.empty()) {
635 Inst.InConstraintSubstitution |=
636 SemaRef.CodeSynthesisContexts.back().InConstraintSubstitution;
637 Inst.InParameterMappingSubstitution |=
638 SemaRef.CodeSynthesisContexts.back().InParameterMappingSubstitution;
651 PointOfInstantiation, InstantiationRange, Entity) {}
658 PointOfInstantiation, InstantiationRange, Entity) {}
678 TemplateArgs, &DeductionInfo) {
693 TemplateArgs, &DeductionInfo) {}
703 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
704 TemplateArgs, &DeductionInfo) {}
714 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
715 TemplateArgs, &DeductionInfo) {}
723 PointOfInstantiation, InstantiationRange, Param,
nullptr,
733 PointOfInstantiation, InstantiationRange, Param,
Template,
743 PointOfInstantiation, InstantiationRange, Param,
Template,
752 PointOfInstantiation, InstantiationRange, Entity,
761 PointOfInstantiation, InstantiationRange, Param,
Template,
770 PointOfInstantiation, InstantiationRange,
nullptr,
771 nullptr, {}, &DeductionInfo) {}
779 PointOfInstantiation, InstantiationRange,
nullptr,
787 PointOfInstantiation, InstantiationRange,
nullptr,
788 nullptr, {}, &DeductionInfo) {}
806 {}, &DeductionInfo) {}
814 PointOfInstantiation, InstantiationRange,
Template) {}
822 PointOfInstantiation, InstantiationRange,
Template) {}
829 PointOfInstantiation, InstantiationRange, Entity) {}
835 ArgLoc, InstantiationRange, PArg) {}
844 assert(
SemaRef.NonInstantiationEntries <=
845 SemaRef.CodeSynthesisContexts.size());
846 if ((
SemaRef.CodeSynthesisContexts.size() -
847 SemaRef.NonInstantiationEntries) >
848 SemaRef.getLangOpts().InstantiationDepth) {
850 diag::err_template_recursion_depth_exceeded)
853 diag::note_template_recursion_depth)
854 <<
SemaRef.getLangOpts().InstantiationDepth;
869 if (!Active.isInstantiationRecord()) {
879 "forgot to remove a lookup module for a template instantiation");
899 SemaRef.CodeSynthesisContexts.back());
901 SemaRef.popCodeSynthesisContext();
909 llvm::raw_string_ostream
OS(Result);
910 llvm::ListSeparator Comma;
911 for (
const Expr *Arg : Args) {
913 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
922 unsigned Limit =
Diags.getTemplateBacktraceLimit();
924 SkipStart = Limit / 2 + Limit % 2;
929 unsigned InstantiationIdx = 0;
934 ++Active, ++InstantiationIdx) {
936 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
937 if (InstantiationIdx == SkipStart) {
939 DiagFunc(Active->PointOfInstantiation,
940 PDiag(diag::note_instantiation_contexts_suppressed)
946 switch (Active->Kind) {
948 Decl *D = Active->Entity;
950 unsigned DiagID = diag::note_template_member_class_here;
952 DiagID = diag::note_template_class_instantiation_here;
953 DiagFunc(Active->PointOfInstantiation,
954 PDiag(DiagID) <<
Record << Active->InstantiationRange);
958 DiagID = diag::note_function_template_spec_here;
960 DiagID = diag::note_template_member_function_here;
961 DiagFunc(Active->PointOfInstantiation,
963 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
964 DiagFunc(Active->PointOfInstantiation,
965 PDiag(VD->isStaticDataMember()
966 ? diag::note_template_static_data_member_def_here
967 : diag::note_template_variable_def_here)
968 << VD << Active->InstantiationRange);
969 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
970 DiagFunc(Active->PointOfInstantiation,
971 PDiag(diag::note_template_enum_def_here)
972 << ED << Active->InstantiationRange);
973 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
974 DiagFunc(Active->PointOfInstantiation,
975 PDiag(diag::note_template_nsdmi_here)
976 << FD << Active->InstantiationRange);
978 DiagFunc(Active->PointOfInstantiation,
979 PDiag(diag::note_template_class_instantiation_here)
980 << CTD << Active->InstantiationRange);
988 llvm::raw_svector_ostream
OS(TemplateArgsStr);
990 printTemplateArgumentList(
OS, Active->template_arguments(),
992 DiagFunc(Active->PointOfInstantiation,
993 PDiag(diag::note_default_arg_instantiation_here)
994 <<
OS.str() << Active->InstantiationRange);
1000 DiagFunc(Active->PointOfInstantiation,
1001 PDiag(diag::note_explicit_template_arg_substitution_here)
1005 Active->NumTemplateArgs)
1006 << Active->InstantiationRange);
1012 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1014 Active->PointOfInstantiation,
1015 PDiag(diag::note_function_template_deduction_instantiation_here)
1018 FnTmpl->getTemplateParameters(), Active->TemplateArgs,
1019 Active->NumTemplateArgs)
1020 << Active->InstantiationRange);
1024 bool IsTemplate =
false;
1026 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1028 Params = D->getTemplateParameters();
1029 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1031 Params = D->getTemplateParameters();
1032 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1034 Params = D->getTemplateParameters();
1036 llvm_unreachable(
"unexpected template kind");
1039 DiagFunc(Active->PointOfInstantiation,
1040 PDiag(diag::note_deduced_template_arg_substitution_here)
1043 Active->TemplateArgs,
1044 Active->NumTemplateArgs)
1045 << Active->InstantiationRange);
1055 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1057 printTemplateArgumentList(
OS, Active->template_arguments(),
1059 DiagFunc(Active->PointOfInstantiation,
1060 PDiag(diag::note_default_function_arg_instantiation_here)
1061 <<
OS.str() << Active->InstantiationRange);
1069 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1073 TemplateParams =
Template->getTemplateParameters();
1077 ->getTemplateParameters();
1078 DiagFunc(Active->PointOfInstantiation,
1079 PDiag(diag::note_prior_template_arg_substitution)
1082 Active->TemplateArgs,
1083 Active->NumTemplateArgs)
1084 << Active->InstantiationRange);
1091 TemplateParams =
Template->getTemplateParameters();
1095 ->getTemplateParameters();
1097 DiagFunc(Active->PointOfInstantiation,
1098 PDiag(diag::note_template_default_arg_checking)
1100 Active->TemplateArgs,
1101 Active->NumTemplateArgs)
1102 << Active->InstantiationRange);
1107 DiagFunc(Active->PointOfInstantiation,
1108 PDiag(diag::note_evaluating_exception_spec_here)
1113 DiagFunc(Active->PointOfInstantiation,
1114 PDiag(diag::note_template_exception_spec_instantiation_here)
1116 << Active->InstantiationRange);
1120 DiagFunc(Active->PointOfInstantiation,
1121 PDiag(diag::note_template_requirement_instantiation_here)
1122 << Active->InstantiationRange);
1125 DiagFunc(Active->PointOfInstantiation,
1126 PDiag(diag::note_template_requirement_params_instantiation_here)
1127 << Active->InstantiationRange);
1131 DiagFunc(Active->PointOfInstantiation,
1132 PDiag(diag::note_nested_requirement_here)
1133 << Active->InstantiationRange);
1137 DiagFunc(Active->PointOfInstantiation,
1138 PDiag(diag::note_in_declaration_of_implicit_special_member)
1140 << Active->SpecialMember);
1145 Active->Entity->getLocation(),
1146 PDiag(diag::note_in_declaration_of_implicit_equality_comparison));
1152 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1160 DiagFunc(Active->PointOfInstantiation,
1161 PDiag(diag::note_member_synthesized_at)
1163 <<
Context.getCanonicalTagType(MD->getParent()));
1165 QualType RecordType = FD->getParamDecl(0)
1167 .getNonReferenceType()
1168 .getUnqualifiedType();
1169 DiagFunc(Active->PointOfInstantiation,
1170 PDiag(diag::note_comparison_synthesized_at)
1177 DiagFunc(Active->Entity->getLocation(),
1178 PDiag(diag::note_rewriting_operator_as_spaceship));
1182 DiagFunc(Active->PointOfInstantiation,
1183 PDiag(diag::note_in_binding_decl_init)
1188 DiagFunc(Active->PointOfInstantiation,
1189 PDiag(diag::note_due_to_dllexported_class)
1195 DiagFunc(Active->PointOfInstantiation,
1196 PDiag(diag::note_building_builtin_dump_struct_call)
1199 Active->NumCallArgs)));
1206 DiagFunc(Active->PointOfInstantiation,
1207 PDiag(diag::note_lambda_substitution_here));
1210 unsigned DiagID = 0;
1211 if (!Active->Entity) {
1212 DiagFunc(Active->PointOfInstantiation,
1213 PDiag(diag::note_nested_requirement_here)
1214 << Active->InstantiationRange);
1218 DiagID = diag::note_concept_specialization_here;
1220 DiagID = diag::note_checking_constraints_for_template_id_here;
1222 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1224 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1227 DiagID = diag::note_checking_constraints_for_function_here;
1230 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1233 printTemplateArgumentList(
OS, Active->template_arguments(),
1236 DiagFunc(Active->PointOfInstantiation,
1237 PDiag(DiagID) <<
OS.str() << Active->InstantiationRange);
1241 DiagFunc(Active->PointOfInstantiation,
1242 PDiag(diag::note_constraint_substitution_here)
1243 << Active->InstantiationRange);
1246 DiagFunc(Active->PointOfInstantiation,
1247 PDiag(diag::note_constraint_normalization_here)
1249 << Active->InstantiationRange);
1252 DiagFunc(Active->PointOfInstantiation,
1253 PDiag(diag::note_parameter_mapping_substitution_here)
1254 << Active->InstantiationRange);
1257 DiagFunc(Active->PointOfInstantiation,
1258 PDiag(diag::note_building_deduction_guide_here));
1265 if (Active->NumTemplateArgs == 0)
1267 DiagFunc(Active->PointOfInstantiation,
1268 PDiag(diag::note_template_type_alias_instantiation_here)
1270 << Active->InstantiationRange);
1273 DiagFunc(Active->PointOfInstantiation,
1274 PDiag(diag::note_template_arg_template_params_mismatch));
1277 DiagFunc(ParamLoc,
PDiag(diag::note_template_prev_declaration)
1279 << Active->InstantiationRange);
1287 return std::optional<TemplateDeductionInfo *>(
nullptr);
1292 Active != ActiveEnd;
1295 switch (Active->Kind) {
1310 return std::nullopt;
1317 return std::nullopt;
1339 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1340 return Active->DeductionInfo;
1351 return std::nullopt;
1365 if (Active->SavedInNonInstantiationSFINAEContext)
1366 return std::optional<TemplateDeductionInfo *>(
nullptr);
1369 return std::nullopt;
1377 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1382 bool EvaluateConstraints =
true;
1385 bool IsIncomplete =
false;
1387 bool BailOutOnIncomplete;
1392 bool BuildPackExpansionTypes =
true;
1397 bool maybeInstantiateFunctionParameterToScope(
ParmVarDecl *OldParm);
1402 TemplateInstantiator(
Sema &SemaRef,
1405 bool BailOutOnIncomplete =
false)
1406 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1407 Entity(Entity), BailOutOnIncomplete(BailOutOnIncomplete) {}
1409 void setEvaluateConstraints(
bool B) {
1410 EvaluateConstraints = B;
1412 bool getEvaluateConstraints() {
1413 return EvaluateConstraints;
1416 inline static struct ForParameterMappingSubstitution_t {
1417 } ForParameterMappingSubstitution;
1419 TemplateInstantiator(ForParameterMappingSubstitution_t, Sema &SemaRef,
1421 const MultiLevelTemplateArgumentList &TemplateArgs,
1422 bool BuildPackExpansionTypes)
1423 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1424 BailOutOnIncomplete(
false),
1425 BuildPackExpansionTypes(BuildPackExpansionTypes) {}
1432 bool AlreadyTransformed(QualType
T);
1435 SourceLocation getBaseLocation() {
return Loc; }
1438 DeclarationName getBaseEntity() {
return Entity; }
1441 bool getIsIncomplete()
const {
return IsIncomplete; }
1445 void setBase(SourceLocation Loc, DeclarationName Entity) {
1447 this->Entity = Entity;
1450 unsigned TransformTemplateDepth(
unsigned Depth) {
1454 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1455 SourceRange PatternRange,
1456 ArrayRef<UnexpandedParameterPack> Unexpanded,
1457 bool FailOnPackProducingTemplates,
1458 bool &ShouldExpand,
bool &RetainExpansion,
1459 UnsignedOrNone &NumExpansions) {
1464 NamedDecl *VD = ParmPack.first.dyn_cast<NamedDecl *>();
1465 if (
auto *PVD = dyn_cast_if_present<ParmVarDecl>(VD);
1466 PVD && maybeInstantiateFunctionParameterToScope(PVD))
1471 return getSema().CheckParameterPacksForExpansion(
1472 EllipsisLoc, PatternRange, Unexpanded, TemplateArgs,
1473 FailOnPackProducingTemplates, ShouldExpand, RetainExpansion,
1477 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1481 TemplateArgument ForgetPartiallySubstitutedPack() {
1485 MultiLevelTemplateArgumentList &TemplateArgs =
1486 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1487 unsigned Depth, Index;
1490 Result = TemplateArgs(Depth, Index);
1491 TemplateArgs.
setArgument(Depth, Index, TemplateArgument());
1493 IsIncomplete =
true;
1494 if (BailOutOnIncomplete)
1495 return TemplateArgument();
1502 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1508 MultiLevelTemplateArgumentList &TemplateArgs =
1509 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1510 unsigned Depth, Index;
1516 MultiLevelTemplateArgumentList ForgetSubstitution() {
1517 MultiLevelTemplateArgumentList
New;
1520 MultiLevelTemplateArgumentList Old =
1521 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1522 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1527 void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
1528 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) = Old;
1532 getTemplateArgumentPackPatternForRewrite(
const TemplateArgument &TA) {
1538 "unexpected pack arguments in template rewrite");
1547 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1549 void transformAttrs(Decl *Old, Decl *
New) {
1553 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1555 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1557 for (
auto *
New : NewDecls)
1563 assert(NewDecls.size() == 1 &&
1564 "should only have multiple expansions for a pack");
1570 auto *NewMD = dyn_cast<CXXMethodDecl>(
New);
1572 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1573 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1574 NewTD->setInstantiatedFromMemberTemplate(
1575 OldMD->getDescribedFunctionTemplate());
1577 NewMD->setInstantiationOfMemberFunction(OldMD,
1585 if (
auto *DC = dyn_cast<DeclContext>(Old);
1586 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1592 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1596 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1598 bool TransformExceptionSpec(SourceLocation Loc,
1599 FunctionProtoType::ExceptionSpecInfo &ESI,
1600 SmallVectorImpl<QualType> &Exceptions,
1605 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1606 TypeSourceInfo *Declarator,
1607 SourceLocation StartLoc,
1608 SourceLocation NameLoc,
1609 IdentifierInfo *Name);
1613 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1614 TypeSourceInfo *TSInfo, QualType
T);
1617 TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc,
1619 SourceLocation NameLoc,
1620 QualType ObjectType = QualType(),
1621 NamedDecl *FirstQualifierInScope =
nullptr,
1622 bool AllowInjectedClassName =
false);
1624 const AnnotateAttr *TransformAnnotateAttr(
const AnnotateAttr *AA);
1625 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1626 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1627 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1629 const NoInlineAttr *A);
1630 const AlwaysInlineAttr *
1631 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1632 const AlwaysInlineAttr *A);
1633 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1634 const OpenACCRoutineDeclAttr *
1635 TransformOpenACCRoutineDeclAttr(
const OpenACCRoutineDeclAttr *A);
1636 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1637 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1638 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1640 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1641 NonTypeTemplateParmDecl *D);
1644 ExprResult RebuildVarDeclRefExpr(ValueDecl *PD, SourceLocation Loc);
1647 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, ValueDecl *PD);
1652 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1654 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1655 FunctionProtoTypeLoc TL) {
1657 return inherited::TransformFunctionProtoType(TLB, TL);
1660 QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL) {
1661 auto Type = inherited::TransformTagType(TLB, TL);
1667 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TL.
getTypePtr());
1670 Type = inherited::TransformType(
1671 ICNT->getDecl()->getCanonicalTemplateSpecializationType(
1679 bool TransformTemplateArgument(
const TemplateArgumentLoc &Input,
1680 TemplateArgumentLoc &Output,
1681 bool Uneval =
false) {
1682 const TemplateArgument &Arg = Input.
getArgument();
1683 std::vector<TemplateArgument> TArgs;
1693 pack, QualType(), SourceLocation{});
1694 TemplateArgumentLoc Output;
1695 if (TransformTemplateArgument(Input, Output, Uneval))
1700 TemplateArgument(llvm::ArrayRef(TArgs).copy(SemaRef.
Context)),
1701 QualType(), SourceLocation{});
1706 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1710 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
1711 UnsignedOrNone NumExpansions) {
1712 return inherited::RebuildPackExpansion(Pattern, EllipsisLoc,
1716 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
1717 SourceLocation EllipsisLoc,
1718 UnsignedOrNone NumExpansions) {
1721 if (BuildPackExpansionTypes)
1722 return inherited::RebuildPackExpansion(Pattern, EllipsisLoc,
1729 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
1730 TemplateSpecializationTypeLoc TL) {
1732 if (!getSema().ArgPackSubstIndex || !
T->
isSugared() ||
1742 QualType R = TransformType(
T->
desugar());
1747 UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(
1748 ArrayRef<TemplateArgument> PackArgs) {
1759 return std::nullopt;
1761 return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1764 template<
typename Fn>
1765 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1766 FunctionProtoTypeLoc TL,
1767 CXXRecordDecl *ThisContext,
1768 Qualifiers ThisTypeQuals,
1769 Fn TransformExceptionSpec);
1771 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1772 int indexAdjustment,
1773 UnsignedOrNone NumExpansions,
1774 bool ExpectParameterPack);
1776 using inherited::TransformTemplateTypeParmType;
1779 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1780 TemplateTypeParmTypeLoc TL,
1781 bool SuppressObjCLifetime);
1783 QualType BuildSubstTemplateTypeParmType(
1784 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
1785 Decl *AssociatedDecl,
unsigned Index, UnsignedOrNone PackIndex,
1786 TemplateArgument Arg, SourceLocation NameLoc);
1791 using inherited::TransformSubstTemplateTypeParmPackType;
1793 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1794 SubstTemplateTypeParmPackTypeLoc TL,
1795 bool SuppressObjCLifetime);
1797 TransformSubstBuiltinTemplatePackType(TypeLocBuilder &TLB,
1798 SubstBuiltinTemplatePackTypeLoc TL);
1801 ComputeLambdaDependency(LambdaScopeInfo *LSI) {
1803 TemplateInstArgsHelpers::getEnclosingTypeAliasTemplateDecl(
1805 TypeAlias && TemplateInstArgsHelpers::isLambdaEnclosedByTypeAliasDecl(
1807 unsigned TypeAliasDeclDepth =
TypeAlias.Template->getTemplateDepth();
1809 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1810 for (
const TemplateArgument &TA :
TypeAlias.AssociatedTemplateArguments)
1812 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1814 return inherited::ComputeLambdaDependency(LSI);
1822 LocalInstantiationScope Scope(SemaRef,
true,
1824 Sema::ConstraintEvalRAII<TemplateInstantiator> RAII(*
this);
1826 return inherited::TransformLambdaExpr(E);
1829 ExprResult TransformBlockExpr(BlockExpr *E) {
1830 LocalInstantiationScope Scope(SemaRef,
true,
1832 return inherited::TransformBlockExpr(E);
1835 ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1836 LambdaScopeInfo *LSI) {
1839 assert(PVD &&
"null in a parameter list");
1840 if (!PVD->hasDefaultArg())
1842 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1844 SourceLocation EqualLoc = UninstExpr->
getBeginLoc();
1853 PVD->setDefaultArg(ErrorResult.
get());
1856 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1869 llvm::SaveAndRestore _(EvaluateConstraints,
true);
1870 return inherited::TransformLambdaBody(E, Body);
1874 LocalInstantiationScope Scope(SemaRef,
true);
1875 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1878 assert(TransReq.
get() != E &&
1879 "Do not change value of isSatisfied for the existing expression. "
1880 "Create a new expression instead.");
1882 Sema::SFINAETrap Trap(SemaRef);
1887 if (Trap.hasErrorOccurred())
1893 bool TransformRequiresExprRequirements(
1894 ArrayRef<concepts::Requirement *> Reqs,
1895 SmallVectorImpl<concepts::Requirement *> &Transformed) {
1896 bool SatisfactionDetermined =
false;
1897 for (concepts::Requirement *Req : Reqs) {
1898 concepts::Requirement *TransReq =
nullptr;
1899 if (!SatisfactionDetermined) {
1900 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1901 TransReq = TransformTypeRequirement(TypeReq);
1902 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1903 TransReq = TransformExprRequirement(ExprReq);
1905 TransReq = TransformNestedRequirement(
1915 SatisfactionDetermined =
true;
1918 Transformed.push_back(TransReq);
1923 TemplateParameterList *TransformTemplateParameterList(
1924 TemplateParameterList *OrigTPL) {
1925 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1928 TemplateDeclInstantiator DeclInstantiator(getSema(),
1929 Owner, TemplateArgs);
1930 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1931 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1934 concepts::TypeRequirement *
1935 TransformTypeRequirement(concepts::TypeRequirement *Req);
1936 concepts::ExprRequirement *
1937 TransformExprRequirement(concepts::ExprRequirement *Req);
1938 concepts::NestedRequirement *
1939 TransformNestedRequirement(concepts::NestedRequirement *Req);
1941 SourceLocation KWLoc, SourceLocation RBraceLoc,
const RequiresExpr *RE,
1942 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params,
1943 SmallVectorImpl<QualType> &PTypes,
1944 SmallVectorImpl<ParmVarDecl *> &TransParams,
1945 Sema::ExtParameterInfoBuilder &PInfos);
1949bool TemplateInstantiator::AlreadyTransformed(QualType
T) {
1957 getSema().MarkDeclarationsReferencedInType(Loc,
T);
1961Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1965 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1972 TTP->getPosition())) {
1973 IsIncomplete =
true;
1974 return BailOutOnIncomplete ?
nullptr : D;
1977 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1979 if (TTP->isParameterPack()) {
1981 "Missing argument pack");
1982 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
1987 "Wrong kind of template template argument");
1988 return Template.getAsTemplateDecl();
1995 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(D);
1996 PVD &&
SemaRef.CurrentInstantiationScope &&
1997 (
SemaRef.inConstraintSubstitution() ||
1998 SemaRef.inParameterMappingSubstitution()) &&
1999 maybeInstantiateFunctionParameterToScope(PVD))
2005bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
2006 ParmVarDecl *OldParm) {
2007 if (
SemaRef.CurrentInstantiationScope->getInstantiationOfIfExists(OldParm))
2011 return !TransformFunctionTypeParam(OldParm, 0,
2015 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2019 PackExpansionTypeLoc ExpansionTL = TL.
castAs<PackExpansionTypeLoc>();
2021 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
2022 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
2024 bool ShouldExpand =
false;
2025 bool RetainExpansion =
false;
2026 UnsignedOrNone OrigNumExpansions =
2027 ExpansionTL.
getTypePtr()->getNumExpansions();
2028 UnsignedOrNone NumExpansions = OrigNumExpansions;
2030 Pattern.getSourceRange(), Unexpanded,
2032 ShouldExpand, RetainExpansion, NumExpansions))
2035 assert(ShouldExpand && !RetainExpansion &&
2036 "Shouldn't preserve pack expansion when evaluating constraints");
2037 ExpandingFunctionParameterPack(OldParm);
2038 for (
unsigned I = 0; I != *NumExpansions; ++I) {
2039 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
2040 if (!TransformFunctionTypeParam(OldParm, 0,
2048Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
2049 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
2053 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2057bool TemplateInstantiator::TransformExceptionSpec(
2058 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
2059 SmallVectorImpl<QualType> &Exceptions,
bool &Changed) {
2064 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
2068TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
2069 SourceLocation Loc) {
2072 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
2073 const TemplateTypeParmType *TTP
2078 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
2080 if (TTP->isParameterPack()) {
2082 "Missing argument pack");
2087 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2092 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2094 if (
const TagType *Tag =
T->
getAs<TagType>())
2095 return Tag->getDecl();
2098 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
2103 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2107TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
2108 TypeSourceInfo *Declarator,
2109 SourceLocation StartLoc,
2110 SourceLocation NameLoc,
2111 IdentifierInfo *Name) {
2112 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
2113 StartLoc, NameLoc, Name);
2115 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2119VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
2120 TypeSourceInfo *TSInfo,
2122 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
2124 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2128TemplateName TemplateInstantiator::TransformTemplateName(
2129 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
2130 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
2131 NamedDecl *FirstQualifierInScope,
bool AllowInjectedClassName) {
2133 assert(!QualifierLoc &&
"Unexpected qualifier");
2136 TTP && TTP->getDepth() < TemplateArgs.
getNumLevels()) {
2142 TTP->getPosition())) {
2143 IsIncomplete =
true;
2147 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
2152 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2154 "unexpected nontype template argument kind in template rewrite");
2158 auto [AssociatedDecl, Final] =
2160 UnsignedOrNone PackIndex = std::nullopt;
2161 if (TTP->isParameterPack()) {
2163 "Missing argument pack");
2169 return getSema().Context.getSubstTemplateTemplateParmPack(
2170 Arg, AssociatedDecl, TTP->getIndex(), Final);
2173 PackIndex =
SemaRef.getPackIndex(Arg);
2174 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2178 assert(!
Template.isNull() &&
"Null template template argument");
2179 return getSema().Context.getSubstTemplateTemplateParm(
2180 Template, AssociatedDecl, TTP->getIndex(), PackIndex, Final);
2184 if (SubstTemplateTemplateParmPackStorage *SubstPack
2189 TemplateArgument Pack = SubstPack->getArgumentPack();
2191 SemaRef.getPackSubstitutedTemplateArgument(Pack).getAsTemplate();
2192 return getSema().Context.getSubstTemplateTemplateParm(
2193 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2194 SemaRef.getPackIndex(Pack), SubstPack->getFinal());
2197 return inherited::TransformTemplateName(
2198 QualifierLoc, TemplateKWLoc, Name, NameLoc, ObjectType,
2199 FirstQualifierInScope, AllowInjectedClassName);
2203TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
2211TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
2212 NonTypeTemplateParmDecl *NTTP) {
2219 IsIncomplete =
true;
2220 return BailOutOnIncomplete ?
ExprError() : E;
2228 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2230 "unexpected nontype template argument kind in template rewrite");
2236 auto [AssociatedDecl, Final] =
2238 UnsignedOrNone PackIndex = std::nullopt;
2241 "Missing argument pack");
2247 QualType TargetType =
SemaRef.SubstType(NTTP->
getType(), TemplateArgs,
2256 return new (
SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
2260 PackIndex =
SemaRef.getPackIndex(Arg);
2261 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2263 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
2264 AssociatedDecl, NTTP, E->
getLocation(), Arg, PackIndex, Final);
2268TemplateInstantiator::TransformAnnotateAttr(
const AnnotateAttr *AA) {
2269 SmallVector<Expr *> Args;
2270 for (Expr *Arg : AA->args()) {
2271 ExprResult Res = getDerived().TransformExpr(Arg);
2273 Args.push_back(Res.
get());
2275 return AnnotateAttr::CreateImplicit(getSema().
Context, AA->getAnnotation(),
2276 Args.data(), Args.size(), AA->getRange());
2279const CXXAssumeAttr *
2280TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2281 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2285 if (!(Res.
get()->
getDependence() & ExprDependence::TypeValueInstantiation)) {
2286 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2292 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2297TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2298 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2300 if (TransformedExpr == LH->getValue())
2305 LH->getSemanticSpelling() ==
2306 LoopHintAttr::Pragma_unroll))
2309 LoopHintAttr::OptionType Option = LH->getOption();
2310 LoopHintAttr::LoopHintState State = LH->getState();
2312 llvm::APSInt ValueAPS =
2315 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2316 Option = LoopHintAttr::Unroll;
2317 State = LoopHintAttr::Disable;
2322 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2323 TransformedExpr, *LH);
2325const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2326 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2332const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2333 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2340const CodeAlignAttr *
2341TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2342 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2343 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2345const OpenACCRoutineDeclAttr *
2346TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
2347 const OpenACCRoutineDeclAttr *A) {
2348 llvm_unreachable(
"RoutineDecl should only be a declaration attribute, as it "
2349 "applies to a Function Decl (and a few places for VarDecl)");
2352ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,
2353 SourceLocation Loc) {
2354 DeclarationNameInfo NameInfo(PD->
getDeclName(), Loc);
2355 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
2359TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
2363 ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), D));
2366 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2369 QualType
T = TransformType(E->
getType());
2375 SmallVector<ValueDecl *, 8> Vars;
2379 ValueDecl *D = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), *I));
2388 getSema().MarkFunctionParmPackReferenced(PackExpr);
2393TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
2396 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found
2397 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2398 assert(
Found &&
"no instantiation for parameter pack");
2400 Decl *TransformedDecl;
2401 if (DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(*
Found)) {
2405 QualType
T = TransformType(E->
getType());
2410 getSema().MarkFunctionParmPackReferenced(PackExpr);
2414 TransformedDecl = (*Pack)[*getSema().ArgPackSubstIndex];
2425TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
2430 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2432 return TransformTemplateParmRefExpr(E, NTTP);
2439 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2441 return TransformFunctionParmPackRefExpr(E, PD);
2443 return inherited::TransformDeclRefExpr(E);
2446ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2447 CXXDefaultArgExpr *E) {
2449 getDescribedFunctionTemplate() &&
2450 "Default arg expressions are never formed in dependent cases.");
2451 return SemaRef.BuildCXXDefaultArgExpr(
2456template<
typename Fn>
2457QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2458 FunctionProtoTypeLoc TL,
2459 CXXRecordDecl *ThisContext,
2460 Qualifiers ThisTypeQuals,
2461 Fn TransformExceptionSpec) {
2469 LocalInstantiationScope *Current = getSema().CurrentInstantiationScope;
2470 std::optional<LocalInstantiationScope> Scope;
2474 return inherited::TransformFunctionProtoType(
2475 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2478ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2479 ParmVarDecl *OldParm,
int indexAdjustment, UnsignedOrNone NumExpansions,
2480 bool ExpectParameterPack) {
2481 auto NewParm =
SemaRef.SubstParmVarDecl(
2482 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2483 ExpectParameterPack, EvaluateConstraints);
2484 if (NewParm &&
SemaRef.getLangOpts().OpenCL)
2485 SemaRef.deduceOpenCLAddressSpace(NewParm);
2489QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2490 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
2491 Decl *AssociatedDecl,
unsigned Index, UnsignedOrNone PackIndex,
2492 TemplateArgument Arg, SourceLocation NameLoc) {
2497 if (SuppressObjCLifetime) {
2499 RQs = Replacement.getQualifiers();
2502 SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2506 QualType
Result = getSema().Context.getSubstTemplateTypeParmType(
2507 Replacement, AssociatedDecl, Index, PackIndex, Final);
2508 SubstTemplateTypeParmTypeLoc NewTL =
2509 TLB.
push<SubstTemplateTypeParmTypeLoc>(
Result);
2515TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2516 TemplateTypeParmTypeLoc TL,
2517 bool SuppressObjCLifetime) {
2528 IsIncomplete =
true;
2529 if (BailOutOnIncomplete)
2532 TemplateTypeParmTypeLoc NewTL
2533 = TLB.
push<TemplateTypeParmTypeLoc>(TL.
getType());
2538 TemplateArgument Arg = TemplateArgs(
T->getDepth(),
T->getIndex());
2543 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2545 "unexpected nontype template argument kind in template rewrite");
2551 auto [AssociatedDecl, Final] =
2553 UnsignedOrNone PackIndex = std::nullopt;
2554 if (
T->isParameterPack()) {
2556 "Missing argument pack");
2562 QualType
Result = getSema().Context.getSubstTemplateTypeParmPackType(
2563 AssociatedDecl,
T->getIndex(), Final, Arg);
2564 SubstTemplateTypeParmPackTypeLoc NewTL
2565 = TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2571 PackIndex =
SemaRef.getPackIndex(Arg);
2572 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2576 "Template argument kind mismatch");
2578 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2579 AssociatedDecl,
T->getIndex(),
2587 TemplateTypeParmDecl *NewTTPDecl =
nullptr;
2588 if (TemplateTypeParmDecl *OldTTPDecl =
T->getDecl())
2589 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2591 QualType
Result = getSema().Context.getTemplateTypeParmType(
2593 T->isParameterPack(), NewTTPDecl);
2594 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
2599QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2600 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2601 bool SuppressObjCLifetime) {
2602 const SubstTemplateTypeParmPackType *
T = TL.
getTypePtr();
2604 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2609 if (NewReplaced !=
T->getAssociatedDecl())
2610 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2611 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2612 SubstTemplateTypeParmPackTypeLoc NewTL =
2613 TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2618 TemplateArgument Pack =
T->getArgumentPack();
2619 TemplateArgument Arg =
SemaRef.getPackSubstitutedTemplateArgument(Pack);
2620 return BuildSubstTemplateTypeParmType(
2621 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2625QualType TemplateInstantiator::TransformSubstBuiltinTemplatePackType(
2626 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
2628 return TreeTransform::TransformSubstBuiltinTemplatePackType(TLB, TL);
2629 TemplateArgument
Result =
SemaRef.getPackSubstitutedTemplateArgument(
2633 return Result.getAsType();
2636static concepts::Requirement::SubstitutionDiagnostic *
2646 ErrorLoc = PDA.first;
2651 llvm::raw_svector_ostream
OS(Entity);
2655 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2658concepts::Requirement::SubstitutionDiagnostic *
2661 llvm::raw_svector_ostream
OS(Entity);
2665 C.backupStr(Entity),
2666 Location, StringRef()};
2669ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2683 if (getDerived().TransformFunctionTypeParams(
2684 KWLoc, Params,
nullptr,
nullptr, PTypes,
2685 &TransParams, PInfos, &ErrorIdx) ||
2686 Trap.hasErrorOccurred()) {
2692 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2693 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2695 TransReqs, RBraceLoc);
2701concepts::TypeRequirement *
2702TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2706 if (AlwaysRebuild())
2707 return RebuildTypeRequirement(
2712 Sema::SFINAETrap Trap(
SemaRef);
2714 Sema::InstantiatingTemplate TypeInst(
SemaRef,
2717 if (TypeInst.isInvalid())
2719 TypeSourceInfo *TransType = TransformType(Req->
getType());
2720 if (!TransType || Trap.hasErrorOccurred())
2722 [&] (llvm::raw_ostream&
OS) {
2725 return RebuildTypeRequirement(TransType);
2728concepts::ExprRequirement *
2729TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2733 Sema::SFINAETrap Trap(
SemaRef);
2735 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2744 if (ExprInst.isInvalid())
2747 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2749 TransExprRes =
SemaRef.CheckPlaceholderExpr(TransExprRes.
get());
2750 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2755 TransExpr = TransExprRes.
get();
2758 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2760 if (RetReq.isEmpty())
2761 TransRetReq.emplace();
2762 else if (RetReq.isSubstitutionFailure())
2763 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2764 else if (RetReq.isTypeConstraint()) {
2765 TemplateParameterList *OrigTPL =
2766 RetReq.getTypeConstraintTemplateParameterList();
2770 if (TPLInst.isInvalid())
2772 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2773 if (!TPL || Trap.hasErrorOccurred())
2775 [&] (llvm::raw_ostream&
OS) {
2776 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2777 ->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2781 TransRetReq.emplace(TPL);
2784 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2785 if (Expr *E = TransExpr.dyn_cast<Expr *>())
2787 std::move(*TransRetReq));
2788 return RebuildExprRequirement(
2793concepts::NestedRequirement *
2794TemplateInstantiator::TransformNestedRequirement(
2795 concepts::NestedRequirement *Req) {
2800 ConstraintSatisfaction Satisfaction;
2802 auto NestedReqWithDiag = [&
C,
this](Expr *E,
2803 ConstraintSatisfaction Satisfaction) {
2805 SmallString<128> Entity;
2806 llvm::raw_svector_ostream
OS(Entity);
2807 E->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2808 return new (
C) concepts::NestedRequirement(
2809 SemaRef.Context,
C.backupStr(Entity), std::move(Satisfaction));
2813 if (AlwaysRebuild())
2819 if (!getEvaluateConstraints()) {
2821 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2825 concepts::NestedRequirement(TransConstraint.
get());
2826 ConstraintSatisfaction Satisfaction;
2827 return new (
SemaRef.Context) concepts::NestedRequirement(
2828 SemaRef.Context, TransConstraint.
get(), Satisfaction);
2832 Expr *NewConstraint;
2833 TemplateDeductionInfo Info(Constraint->
getBeginLoc());
2838 Sema::InstantiatingTemplate ConstrInst(
2840 Sema::InstantiatingTemplate::ConstraintsCheck(),
2843 if (ConstrInst.isInvalid())
2846 Sema::SFINAETrap Trap(
SemaRef);
2849 Req, AssociatedConstraint(Constraint,
SemaRef.ArgPackSubstIndex),
2851 nullptr, &NewConstraint);
2853 assert((!
Success || !Trap.hasErrorOccurred()) &&
2854 "Substitution failures must be handled "
2855 "by CheckConstraintSatisfaction.");
2859 return NestedReqWithDiag(Constraint, Satisfaction);
2863 if (!NewConstraint) {
2865 return NestedReqWithDiag(Constraint, Satisfaction);
2867 NewConstraint = Constraint;
2869 return new (
C) concepts::NestedRequirement(
C, NewConstraint, Satisfaction);
2876 bool AllowDeducedTST) {
2878 "Cannot perform an instantiation without some context on the "
2879 "instantiation stack");
2881 if (!
T->getType()->isInstantiationDependentType() &&
2882 !
T->getType()->isVariablyModifiedType())
2885 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2886 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2887 : Instantiator.TransformType(
T);
2895 "Cannot perform an instantiation without some context on the "
2896 "instantiation stack");
2910 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2924 bool *IsIncompleteSubstitution) {
2926 "Cannot perform an instantiation without some context on the "
2927 "instantiation stack");
2931 if (!
T->isInstantiationDependentType() && !
T->isVariablyModifiedType())
2934 TemplateInstantiator Instantiator(
2935 *
this, TemplateArgs, Loc, Entity,
2936 IsIncompleteSubstitution !=
nullptr);
2937 QualType QT = Instantiator.TransformType(
T);
2938 if (IsIncompleteSubstitution && Instantiator.getIsIncomplete())
2939 *IsIncompleteSubstitution =
true;
2944 if (
T->getType()->isInstantiationDependentType() ||
2945 T->getType()->isVariablyModifiedType())
2948 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2971 bool EvaluateConstraints) {
2973 "Cannot perform an instantiation without some context on the "
2974 "instantiation stack");
2979 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2980 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2996 Result = Instantiator.TransformFunctionProtoType(
2997 TLB, Proto, ThisContext, ThisTypeQuals,
2999 bool &Changed) {
return false; });
3001 Result = Instantiator.TransformType(TLB, TL);
3015 bool Changed =
false;
3016 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
3017 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
3028 ESI, ExceptionStorage, Args))
3037 struct GetContainedInventedTypeParmVisitor :
3038 public TypeVisitor<GetContainedInventedTypeParmVisitor,
3039 TemplateTypeParmDecl *> {
3040 using TypeVisitor<GetContainedInventedTypeParmVisitor,
3046 return Visit(
T.getTypePtr());
3050 const TemplateTypeParmType *
T) {
3051 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
3053 return T->getDecl();
3059 TemplateTypeParmDecl *VisitPointerType(
const PointerType *
T) {
3063 TemplateTypeParmDecl *VisitBlockPointerType(
const BlockPointerType *
T) {
3067 TemplateTypeParmDecl *VisitReferenceType(
const ReferenceType *
T) {
3068 return Visit(
T->getPointeeTypeAsWritten());
3071 TemplateTypeParmDecl *VisitMemberPointerType(
const MemberPointerType *
T) {
3075 TemplateTypeParmDecl *VisitArrayType(
const ArrayType *
T) {
3076 return Visit(
T->getElementType());
3079 TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
3080 const DependentSizedExtVectorType *
T) {
3081 return Visit(
T->getElementType());
3084 TemplateTypeParmDecl *VisitVectorType(
const VectorType *
T) {
3085 return Visit(
T->getElementType());
3088 TemplateTypeParmDecl *VisitFunctionProtoType(
const FunctionProtoType *
T) {
3089 return VisitFunctionType(
T);
3092 TemplateTypeParmDecl *VisitFunctionType(
const FunctionType *
T) {
3096 TemplateTypeParmDecl *VisitParenType(
const ParenType *
T) {
3097 return Visit(
T->getInnerType());
3100 TemplateTypeParmDecl *VisitAttributedType(
const AttributedType *
T) {
3101 return Visit(
T->getModifiedType());
3104 TemplateTypeParmDecl *VisitMacroQualifiedType(
const MacroQualifiedType *
T) {
3105 return Visit(
T->getUnderlyingType());
3108 TemplateTypeParmDecl *VisitAdjustedType(
const AdjustedType *
T) {
3109 return Visit(
T->getOriginalType());
3112 TemplateTypeParmDecl *VisitPackExpansionType(
const PackExpansionType *
T) {
3113 return Visit(
T->getPattern());
3122 bool EvaluateConstraints) {
3129 Index =
SemaRef.ArgPackSubstIndex;
3158 bool ExpectParameterPack,
bool EvaluateConstraint) {
3178 }
else if (ExpectParameterPack) {
3184 diag::err_function_parameter_pack_without_parameter_packs)
3208 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
3210 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3215 if (Inst && !Inst->getTypeConstraint()) {
3284 "Cannot perform an instantiation without some context on the "
3285 "instantiation stack");
3287 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3289 return Instantiator.TransformFunctionTypeParams(
3290 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3299 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3303 if (AlreadyInstantiating) {
3304 Param->setInvalidDecl();
3305 return Diag(Param->getBeginLoc(), diag::err_recursive_default_argument)
3323 std::optional<LocalInstantiationScope> LIS;
3334 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3351 Param->getLocation(),
3356 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3386 auto ComputeInfo = [&S, &TemplateArgs, BaseSourceRange, BaseEllipsisLoc](
3393 if (IsLateExpansionAttempt) {
3398 return P.first.dyn_cast<
const SubstBuiltinTemplatePackType *>();
3400 if (!SawPackTypes) {
3412 BaseEllipsisLoc, BaseSourceRange, Unexpanded, TemplateArgs,
3417 if (ComputeInfo(
Base.getTypeSourceInfo(),
false, Info))
3421 Out =
Base.getTypeSourceInfo();
3431 if (!Out->getType()->containsUnexpandedParameterPack())
3436 if (ComputeInfo(Out,
true, Info))
3449 for (
const auto &
Base : Pattern->
bases()) {
3450 if (!
Base.getType()->isDependentType()) {
3452 if (RD->isInvalidDecl())
3461 if (
Base.isPackExpansion()) {
3473 ArgsForSubst = &EmptyList;
3488 Instantiation,
Base.getSourceRange(),
Base.isVirtual(),
3489 Base.getAccessSpecifierAsWritten(), Expanded,
3491 InstantiatedBases.push_back(InstantiatedBase);
3500 EllipsisLoc =
Base.getEllipsisLoc();
3508 Base.getSourceRange().getBegin(),
3519 Base.getSourceRange(),
3521 Base.getAccessSpecifierAsWritten(),
3524 InstantiatedBases.push_back(InstantiatedBase);
3554 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3557 return InstantiateClassImpl(PointOfInstantiation, Instantiation, Pattern,
3558 TemplateArgs, TSK, Complain);
3561bool Sema::InstantiateClassImpl(
3568 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3570 Pattern, PatternDef, TSK, Complain))
3573 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3574 llvm::TimeTraceMetadata M;
3575 llvm::raw_string_ostream OS(M.Detail);
3578 if (llvm::isTimeTraceVerbose()) {
3579 auto Loc = SourceMgr.getExpansionLoc(Instantiation->
getLocation());
3580 M.File = SourceMgr.getFilename(Loc);
3581 M.Line = SourceMgr.getExpansionLineNumber(Loc);
3586 Pattern = PatternDef;
3589 if (MemberSpecializationInfo *MSInfo
3591 MSInfo->setTemplateSpecializationKind(TSK);
3592 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3593 }
else if (ClassTemplateSpecializationDecl *Spec
3594 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3595 Spec->setTemplateSpecializationKind(TSK);
3596 Spec->setPointOfInstantiation(PointOfInstantiation);
3599 InstantiatingTemplate Inst(*
this, PointOfInstantiation, Instantiation);
3600 if (Inst.isInvalid())
3602 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3603 "instantiating class definition");
3607 ContextRAII SavedContext(*
this, Instantiation);
3608 EnterExpressionEvaluationContext EvalContext(
3609 *
this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
3615 LocalInstantiationScope Scope(*
this, MergeWithParentScope);
3621 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3624 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3634 Instantiation->
setTagKind(Pattern->getTagKind());
3637 if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
3640 TemplateDeclInstantiator Instantiator(*
this, Instantiation, TemplateArgs);
3641 Instantiator.setEvaluateConstraints(
false);
3642 SmallVector<Decl*, 4> Fields;
3644 LateInstantiatedAttrVec LateAttrs;
3645 Instantiator.enableLateAttributeInstantiation(&LateAttrs);
3647 bool MightHaveConstexprVirtualFunctions =
false;
3648 for (
auto *
Member : Pattern->decls()) {
3658 if (
Member->getDeclContext() != Pattern)
3669 if (
Member->isInvalidDecl()) {
3674 Decl *NewMember = Instantiator.Visit(
Member);
3676 if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3677 Fields.push_back(Field);
3678 }
else if (EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3684 Enum->isCompleteDefinition()) {
3685 MemberSpecializationInfo *MSInfo =
Enum->getMemberSpecializationInfo();
3686 assert(MSInfo &&
"no spec info for member enum specialization");
3690 }
else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
3691 if (SA->isFailed()) {
3697 }
else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3700 MightHaveConstexprVirtualFunctions =
true;
3714 ActOnFields(
nullptr, Instantiation->
getLocation(), Instantiation, Fields,
3715 SourceLocation(), SourceLocation(), ParsedAttributesView());
3716 CheckCompletedCXXClass(
nullptr, Instantiation);
3721 if (ParsingClassDepth == 0)
3722 ActOnFinishCXXNonNestedClass();
3726 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3727 E = LateAttrs.end(); I != E; ++I) {
3728 assert(CurrentInstantiationScope == Instantiator.getStartingScope());
3729 CurrentInstantiationScope = I->Scope;
3733 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3734 CXXThisScopeRAII ThisScope(*
this, ThisContext, Qualifiers(),
3735 ND->isCXXInstanceMember());
3740 I->NewDecl->addAttr(NewAttr);
3742 Instantiator.getStartingScope());
3744 Instantiator.disableLateAttributeInstantiation();
3747 ActOnFinishDelayedMemberInitializers(Instantiation);
3752 Instantiation->
setLocation(Pattern->getLocation());
3753 Instantiation->
setLocStart(Pattern->getInnerLocStart());
3759 if (Pattern->isDependentContext())
3760 PerformDependentDiagnostics(Pattern, TemplateArgs);
3765 P = Instantiator.delayed_partial_spec_begin(),
3766 PEnd = Instantiator.delayed_partial_spec_end();
3768 if (!Instantiator.InstantiateClassTemplatePartialSpecialization(
3769 P->first, P->second)) {
3778 P = Instantiator.delayed_var_partial_spec_begin(),
3779 PEnd = Instantiator.delayed_var_partial_spec_end();
3781 if (!Instantiator.InstantiateVarTemplatePartialSpecialization(
3782 P->first, P->second)) {
3798 MarkVTableUsed(PointOfInstantiation, Instantiation,
true);
3799 else if (MightHaveConstexprVirtualFunctions)
3800 MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
3804 Consumer.HandleTagDeclDefinition(Instantiation);
3816 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3822 Pattern, PatternDef, TSK,
true))
3824 Pattern = PatternDef;
3837 "instantiating enum definition");
3872 "pattern and instantiation disagree about init style");
3876 if (AlreadyInstantiating)
3878 return Diag(PointOfInstantiation,
3879 diag::err_default_member_initializer_cycle)
3888 Diag(PointOfInstantiation,
3889 diag::err_default_member_initializer_not_yet_parsed)
3890 << OutermostClass << Pattern;
3891 Diag(Pattern->getEndLoc(),
3892 diag::note_default_member_initializer_not_yet_parsed);
3901 "instantiating default member init");
3909 PointOfInstantiation, Instantiation,
CurContext};
3925 L->DefaultMemberInitializerInstantiated(Instantiation);
3934 struct PartialSpecMatchResult {
3960 !CTPSD->getMostRecentDecl()->isMemberSpecialization())
3999 typedef PartialSpecMatchResult MatchResult;
4002 Template->getPartialSpecializations(PartialSpecs);
4015 if (
Template->getMostRecentDecl()->isMemberSpecialization() &&
4016 !Partial->getMostRecentDecl()->isMemberSpecialization())
4034 if (Matched.empty() && PrimaryStrictPackMatch)
4035 Matched = std::move(ExtraMatched);
4041 if (Matched.size() >= 1) {
4043 if (Matched.size() == 1) {
4056 PEnd = Matched.end();
4059 P->Partial, Best->Partial, PointOfInstantiation) ==
4068 PEnd = Matched.end();
4071 P->Partial, Best->Partial,
4072 PointOfInstantiation) != Best->Partial) {
4081 S.
Diag(PointOfInstantiation,
4082 diag::err_partial_spec_ordering_ambiguous)
4083 << ClassTemplateSpec;
4087 PEnd = Matched.end();
4089 S.
Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
4091 P->Partial->getTemplateParameters(), *P->Args);
4106 if (
auto *PartialSpec =
4109 while (PartialSpec->getInstantiatedFromMember()) {
4112 if (PartialSpec->isMemberSpecialization())
4115 PartialSpec = PartialSpec->getInstantiatedFromMember();
4117 Pattern = PartialSpec;
4120 while (
Template->getInstantiatedFromMemberTemplate()) {
4123 if (
Template->isMemberSpecialization())
4128 Pattern =
Template->getTemplatedDecl();
4138 bool PrimaryStrictPackMatch) {
4147 if (AlreadyInstantiating)
4150 bool HadAvaibilityWarning =
4156 ClassTemplateSpec, TSK,
4157 PrimaryStrictPackMatch);
4162 bool Err = InstantiateClassImpl(
4163 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4170 if (!Err && !HadAvaibilityWarning) {
4190 "Unexpected template specialization kind!");
4191 for (
auto *D : Instantiation->
decls()) {
4192 bool SuppressNew =
false;
4193 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4195 Function->getInstantiatedFromMemberFunction()) {
4197 if (
Function->getTrailingRequiresClause()) {
4205 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4209 Function->getTemplateSpecializationKind();
4214 PointOfInstantiation, TSK,
Function, PrevTSK,
4215 Function->getPointOfInstantiation(), SuppressNew) ||
4228 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4238 std::make_pair(
Function, PointOfInstantiation));
4241 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4246 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4250 assert(MSInfo &&
"No member specialization information?");
4279 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4280 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4288 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4293 assert(MSInfo &&
"No member specialization information?");
4299 if (
Context.getTargetInfo().getTriple().isOSWindows() &&
4319 assert(Pattern &&
"Missing instantiated-from-template information");
4321 if (!
Record->getDefinition()) {
4342 Record->getTemplateSpecializationKind() ==
4344 Record->setTemplateSpecializationKind(TSK);
4349 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4353 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4355 assert(MSInfo &&
"No member specialization information?");
4362 PointOfInstantiation, TSK,
Enum,
4368 if (
Enum->getDefinition())
4371 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4372 assert(Pattern &&
"Missing instantiated-from-template information");
4383 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4394 ClassPattern->
lookup(Field->getDeclName());
4427 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4430 return Instantiator.TransformStmt(S);
4438 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
4439 return Instantiator.TransformTemplateArgument(Input, Output);
4446 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4448 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4455 TemplateInstantiator Instantiator(
4456 TemplateInstantiator::ForParameterMappingSubstitution, *
this, BaseLoc,
4457 TemplateArgs, BuildPackExpansionTypes);
4458 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4466 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4469 return Instantiator.TransformExpr(E);
4478 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4480 return Instantiator.TransformAddressOfOperand(E);
4496 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4498 Instantiator.setEvaluateConstraints(
false);
4499 return Instantiator.TransformExpr(E);
4505 TemplateInstantiator Instantiator(*
this, MLTAL,
SourceLocation(),
4513 *
this, ArgsAsWritten->
arguments().front().getSourceRange().getBegin(),
4516 ArgsAsWritten->
arguments().front().getSourceRange());
4521 if (Instantiator.TransformConceptTemplateArguments(
4546 struct ConstraintExprTransformer :
TreeTransform<ConstraintExprTransformer> {
4558 case Stmt::BinaryOperatorClass:
4559 case Stmt::ConceptSpecializationExprClass:
4560 case Stmt::ParenExprClass:
4561 case Stmt::UnresolvedLookupExprClass:
4562 return Base::TransformExpr(E);
4573 if (!(E->
getOpcode() == BinaryOperatorKind::BO_LAnd ||
4574 E->
getOpcode() == BinaryOperatorKind::BO_LOr))
4591 bool Uneval =
false) {
4593 return Base::TransformTemplateArgument(Input, Output, Uneval);
4600 bool IsAddressOfOperand =
false) {
4601 if (E->isConceptReference()) {
4609 ConstraintExprTransformer Transformer(*
this, MLTALForConstraint);
4611 Transformer.TransformExpr(
const_cast<Expr *
>(ConstraintExpr));
4617 bool CXXDirectInit) {
4618 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4620 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4629 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4632 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4642 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4644 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4650 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4652 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4660 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameLoc,
4662 return Instantiator.TransformTemplateName(QualifierLoc, TemplateKWLoc, Name,
4671 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4672 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4673 unsigned i = PV->getFunctionScopeIndex();
4676 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4677 return FD->getCanonicalDecl()->getParamDecl(i);
4683llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4687 Current = Current->Outer) {
4690 const Decl *CheckD = D;
4692 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4693 if (
Found != Current->LocalDecls.end())
4694 return &
Found->second;
4698 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4705 if (!Current->CombineWithOuterScope)
4712llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4725 if (RD->isLocalClass())
4742 assert(
isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4748 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4749 if (Stored.isNull()) {
4753 while (Current->CombineWithOuterScope && Current->Outer) {
4754 Current = Current->Outer;
4755 assert(!Current->LocalDecls.contains(D) &&
4756 "Instantiated local in inner and outer scopes");
4760 }
else if (
DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(Stored)) {
4763 assert(
cast<Decl *>(Stored) == Inst &&
"Already instantiated this local");
4771 Pack->push_back(Inst);
4778 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4779 assert(!Current->LocalDecls.contains(D) &&
4780 "Creating local pack after instantiation of local");
4784 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4787 ArgumentPacks.push_back(Pack);
4792 if (llvm::is_contained(*Pack, D))
4799 unsigned NumExplicitArgs) {
4800 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4801 "Already have a partially-substituted pack");
4802 assert((!PartiallySubstitutedPack
4803 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4804 "Wrong number of arguments in partially-substituted pack");
4805 PartiallySubstitutedPack = Pack;
4806 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4807 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4812 unsigned *NumExplicitArgs)
const {
4814 *ExplicitArgs =
nullptr;
4815 if (NumExplicitArgs)
4816 *NumExplicitArgs = 0;
4819 Current = Current->Outer) {
4820 if (Current->PartiallySubstitutedPack) {
4822 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4823 if (NumExplicitArgs)
4824 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4826 return Current->PartiallySubstitutedPack;
4829 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.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines Expressions and AST nodes for C++2a concepts.
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Record Record
static TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, ArrayRef< TemplateArgument > Ps, ArrayRef< TemplateArgument > As, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool NumberOfArgumentsMustMatch, bool PartialOrdering, PackFold PackFold, bool *HasDeducedAnyParam)
static bool PreparePackForExpansion(Sema &S, const CXXBaseSpecifier &Base, const MultiLevelTemplateArgumentList &TemplateArgs, TypeSourceInfo *&Out, UnexpandedInfo &Info)
static const Decl * getCanonicalParmVarDecl(const Decl *D)
static ActionResult< CXXRecordDecl * > getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool PrimaryStrictPackMatch)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, Sema::EntityPrinter Printer)
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const clang::PrintingPolicy & getPrintingPolicy() const
The result of parsing/analyzing an expression, statement etc.
Attr - This represents one attribute.
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getOperatorLoc() const
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a base class of a C++ class.
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
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.
Declaration of a class template.
ClassTemplateDecl * getMostRecentDecl()
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
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
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
const TypeClass * getTypePtr() 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)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
DeclContextLookupResult lookup_result
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.
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
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).
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.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
TypeSourceInfo * getTypeSourceInfo() const
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,...
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
EnumDecl * getDefinition() const
This represents one expression.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
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.
ExprDependence getDependence() const
Represents difference between two FPOptions values.
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.
Represents a function declaration or definition.
ArrayRef< ParmVarDecl * > parameters() const
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, ArrayRef< ValueDecl * > Params)
ValueDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
ValueDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
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...
QualType getReturnType() const
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 an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
A stack-allocated class that identifies which local variable declaration instantiations are present i...
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false, bool InstantiatingLambdaOrBlock=false)
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.
SmallVector< ValueDecl *, 4 > DeclArgumentPack
A set of declarations.
llvm::PointerUnion< Decl *, DeclArgumentPack * > * getInstantiationOfIfExists(const Decl *D)
Similar to findInstantiationOf(), but it wouldn't assert if the instantiation was not found within th...
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)
bool isLambdaOrBlock() const
Determine whether this scope is for instantiating a lambda or block.
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.
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>::".
const Type * getAsType() const
@ Type
A type, stored as a Type*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
SourceLocation getEllipsisLoc() const
TypeLoc getPatternLoc() const
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
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)
PredefinedIdentKind getIdentKind() const
SourceLocation getLocation() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
A (possibly-)qualified type.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
The collection of all-type qualifiers we support.
void removeObjCLifetime()
Represents a struct/union/class.
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
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.
ExprResult SubstConceptTemplateArguments(const ConceptSpecializationExpr *CSE, const Expr *ConstraintExpr, const MultiLevelTemplateArgumentList &MLTAL)
Substitute concept template arguments in the constraint expression of a concept-id.
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
llvm::function_ref< void(SourceLocation, PartialDiagnostic)> InstantiationContextDiagFuncRef
TemplateName SubstTemplateName(SourceLocation TemplateKWLoc, NestedNameSpecifierLoc &QualifierLoc, TemplateName Name, SourceLocation NameLoc, const MultiLevelTemplateArgumentList &TemplateArgs)
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
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 ...
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
llvm::function_ref< void(llvm::raw_ostream &)> EntityPrinter
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
concepts::Requirement::SubstitutionDiagnostic * createSubstDiagAt(SourceLocation Location, EntityPrinter Printer)
create a Requirement::SubstitutionDiagnostic with only a SubstitutedEntity and DiagLoc using ASTConte...
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 InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain, bool PrimaryStrictPackMatch)
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
ExprResult SubstConstraintExprWithoutSatisfaction(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
void PrintInstantiationStack()
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 pushCodeSynthesisContext(CodeSynthesisContext Ctx)
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
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.
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 ...
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.
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
void popCodeSynthesisContext()
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
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...
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...
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, ExprResult Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member,...
bool inConstraintSubstitution() const
Determine whether we are currently performing constraint substitution.
bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass, bool ObjCPropertyAccess, bool AvoidPartialAvailabilityChecks, ObjCInterfaceDecl *ClassReceiver)
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, TemplateDecl *NamedConcept, NamedDecl *FoundDecl, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
std::pair< AvailabilityResult, const NamedDecl * > ShouldDiagnoseAvailabilityOfDecl(const NamedDecl *D, std::string *Message, ObjCInterfaceDecl *ClassReceiver)
The diagnostic we should emit for D, and the declaration that originated it, or AR_Available.
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
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 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)
@ 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 inParameterMappingSubstitution() const
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
bool RebuildingImmediateInvocation
Whether the AST is currently being rebuilt to correct immediate invocations.
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, NamedDecl *Instantiation, bool InstantiatedFromMember, const NamedDecl *Pattern, const NamedDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true, bool *Unreachable=nullptr)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
DiagnosticsEngine & Diags
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier * > Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
friend class InitializationSequence
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.
bool SubstTemplateArgumentsInParameterMapping(ArrayRef< TemplateArgumentLoc > Args, SourceLocation BaseLoc, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Out, bool BuildPackExpansionTypes)
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)
ExprResult SubstCXXIdExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
Substitute an expression as if it is a address-of-operand, which makes it act like a CXXIdExpression ...
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
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)
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
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.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
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
StmtClass getStmtClass() 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 the declaration of a struct/union/class/enum.
void setTagKind(TagKind TK)
void startDefinition()
Starts the definition of this tag declaration.
void setBraceRange(SourceRange R)
SourceLocation getNameLoc() const
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
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.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool isConceptOrConceptTemplateParameter() const
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.
@ 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.
@ 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.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
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.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
@ Template
A single template declaration.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, 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.
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.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool isParameterPack() const
Returns whether this is a parameter pack.
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
UnsignedOrNone getArgPackSubstIndex() const
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
TemplateDecl * getNamedConcept() 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 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)
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 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
QualType getUnderlyingType() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
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.
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.
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...
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.
bool hasStrictPackMatch() const
Defines the clang::TargetInfo interface.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
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)
bool isa(CodeGen::Address addr)
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ OK_Ordinary
An ordinary object is located at an address in memory.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool isPackProducingBuiltinTemplateName(TemplateName N)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
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...
@ Type
The name was classified as a type.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
@ 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.
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
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.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
U cast(CodeGen::Address addr)
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
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 ('>').
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
SourceLocation getLAngleLoc() const
ArrayRef< TemplateArgumentLoc > arguments() const
unsigned getNumTemplateArgs() const
SourceLocation getRAngleLoc() 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...
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.
@ PartialOrderingTTP
We are performing partial ordering for template template parameters.
@ 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.
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
bool ExpandUnderForgetSubstitions
UnsignedOrNone NumExpansions