38#include "llvm/ADT/StringExtras.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/SaveAndRestore.h"
41#include "llvm/Support/TimeProfiler.h"
54 const Decl *NextDecl =
nullptr;
56 bool ClearRelativeToPrimary =
true;
57 static Response Done() {
62 static Response ChangeDecl(
const Decl *ND) {
67 static Response ChangeDecl(
const DeclContext *Ctx) {
73 static Response UseNextDecl(
const Decl *CurDecl) {
77 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
78 Response R = Response::UseNextDecl(CurDecl);
79 R.ClearRelativeToPrimary =
false;
88getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
90 return LambdaCallOperator;
92 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
94 FTD && FTD->getInstantiatedFromMemberTemplate()) {
96 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
103 ->getInstantiatedFromMemberFunction())
104 LambdaCallOperator = Prev;
108 return LambdaCallOperator;
111struct EnclosingTypeAliasTemplateDetails {
121EnclosingTypeAliasTemplateDetails
122getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
125 TypeAliasTemplateInstantiation)
127 EnclosingTypeAliasTemplateDetails Result;
129 *
Next = TATD->getInstantiatedFromMemberTemplate();
133 CSC.template_arguments(),
136 Result.PrimaryTypeAliasDecl =
Next;
137 Next =
Next->getInstantiatedFromMemberTemplate();
150bool isLambdaEnclosedByTypeAliasDecl(
154 Visitor(
const FunctionDecl *CallOperator) : CallOperator(CallOperator) {}
155 bool VisitLambdaExpr(
LambdaExpr *LE)
override {
158 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
167 return !Visitor(getPrimaryTemplateOfGenericLambda(LambdaCallOperator))
168 .TraverseType(Underlying);
175 bool SkipForSpecialization) {
179 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
184 return Response::Done();
189 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
192 dyn_cast<VarTemplatePartialSpecializationDecl *>(Specialized)) {
193 if (!SkipForSpecialization)
194 Result.addOuterTemplateArguments(
197 if (Partial->isMemberSpecialization())
198 return Response::Done();
201 if (!SkipForSpecialization)
202 Result.addOuterTemplateArguments(
206 return Response::Done();
208 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
220 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
221 Result.addOuterTemplateArguments(std::nullopt);
222 return Response::Done();
225Response HandlePartialClassTemplateSpec(
228 if (!SkipForSpecialization)
230 return Response::Done();
237 bool SkipForSpecialization) {
242 return Response::Done();
244 if (!SkipForSpecialization)
245 Result.addOuterTemplateArguments(
254 return Response::Done();
260 if (
auto *InstFromPartialTempl =
263 return Response::ChangeDecl(
264 InstFromPartialTempl->getLexicalDeclContext());
266 return Response::UseNextDecl(ClassTemplSpec);
272 bool ForConstraintInstantiation,
273 bool ForDefaultArgumentSubstitution) {
275 if (!RelativeToPrimary &&
276 Function->getTemplateSpecializationKindForInstantiation() ==
278 return Response::Done();
280 if (!RelativeToPrimary &&
285 return Response::UseNextDecl(Function);
287 Function->getTemplateSpecializationArgs()) {
289 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
290 TemplateArgs->asArray(),
293 if (RelativeToPrimary &&
294 (Function->getTemplateSpecializationKind() ==
296 (Function->getFriendObjectKind() &&
297 !Function->getPrimaryTemplate()->getFriendObjectKind())))
298 return Response::UseNextDecl(Function);
302 assert(Function->getPrimaryTemplate() &&
"No function template?");
303 if (!ForDefaultArgumentSubstitution &&
304 Function->getPrimaryTemplate()->isMemberSpecialization())
305 return Response::Done();
308 if (!ForConstraintInstantiation &&
310 return Response::Done();
312 }
else if (
auto *
Template = Function->getDescribedFunctionTemplate()) {
314 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
315 "Outer template not instantiated?");
316 if (ForConstraintInstantiation) {
324 Result.addOuterTemplateArguments(
Template, Inst.template_arguments(),
335 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
336 Function->getNonTransparentDeclContext()->isFileContext() &&
338 return Response::ChangeDecl(Function->getLexicalDeclContext());
341 if (ForConstraintInstantiation && Function->getFriendObjectKind())
342 return Response::ChangeDecl(Function->getLexicalDeclContext());
343 return Response::UseNextDecl(Function);
346Response HandleFunctionTemplateDecl(
Sema &SemaRef,
350 Result.addOuterTemplateArguments(
363 Ty = std::exchange(NextTy,
nullptr)) {
366 NextTy = P.getAsType();
367 const auto *TSTy = dyn_cast<TemplateSpecializationType>(Ty);
389 if (TSTy->isCurrentInstantiation()) {
390 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
392 Arguments = CTD->getInjectedTemplateArgs(SemaRef.
Context);
394 dyn_cast<ClassTemplateSpecializationDecl>(RD))
395 Arguments =
Specialization->getTemplateInstantiationArgs().asArray();
397 Result.addOuterTemplateArguments(
398 TSTy->getTemplateName().getAsTemplateDecl(), Arguments,
409 bool ForConstraintInstantiation) {
412 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
413 "Outer template not instantiated?");
414 if (ClassTemplate->isMemberSpecialization())
415 return Response::Done();
416 if (ForConstraintInstantiation)
417 Result.addOuterTemplateArguments(
419 ClassTemplate->getInjectedTemplateArgs(SemaRef.
Context),
426 return Response::Done();
431 if (ForConstraintInstantiation && IsFriend &&
440 return Response::ChangeDecl(LCD);
444 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef);
445 ForConstraintInstantiation &&
TypeAlias) {
448 Result.addOuterTemplateArguments(
TypeAlias.Template,
464 return Response::ChangeDecl(
TypeAlias.Template->getDeclContext());
469 return Response::UseNextDecl(Rec);
472Response HandleImplicitConceptSpecializationDecl(
475 Result.addOuterTemplateArguments(
479 return Response::UseNextDecl(CSD);
482Response HandleGenericDeclContext(
const Decl *CurDecl) {
483 return Response::UseNextDecl(CurDecl);
491 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
492 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
493 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
498 const Decl *CurDecl = ND;
501 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
511 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
512 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
514 : Response::UseNextDecl(CurDecl).NextDecl;
520 if (
const auto *VarTemplSpec =
521 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
522 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
523 }
else if (
const auto *PartialClassTemplSpec =
524 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
525 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
526 SkipForSpecialization);
527 }
else if (
const auto *ClassTemplSpec =
528 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
529 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
530 SkipForSpecialization);
531 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
532 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
533 ForConstraintInstantiation,
534 ForDefaultArgumentSubstitution);
535 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
537 ForConstraintInstantiation);
538 }
else if (
const auto *CSD =
539 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
540 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
541 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
542 R = HandleFunctionTemplateDecl(*
this, FTD,
Result);
543 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
544 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
546 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
547 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
548 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
551 R = HandleGenericDeclContext(CurDecl);
556 if (R.ClearRelativeToPrimary)
557 RelativeToPrimary =
false;
559 CurDecl = R.NextDecl;
602 llvm_unreachable(
"Invalid SynthesisKind!");
614 if (
SemaRef.Diags.hasFatalErrorOccurred() &&
615 SemaRef.hasUncompilableErrorOccurred()) {
629 Inst.InConstraintSubstitution =
631 Inst.InParameterMappingSubstitution =
633 if (!
SemaRef.CodeSynthesisContexts.empty()) {
634 Inst.InConstraintSubstitution |=
635 SemaRef.CodeSynthesisContexts.back().InConstraintSubstitution;
636 Inst.InParameterMappingSubstitution |=
637 SemaRef.CodeSynthesisContexts.back().InParameterMappingSubstitution;
642 AlreadyInstantiating =
645 : !
SemaRef.InstantiatingSpecializations
646 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
657 PointOfInstantiation, InstantiationRange, Entity) {}
664 PointOfInstantiation, InstantiationRange, Entity) {}
684 TemplateArgs, &DeductionInfo) {
699 TemplateArgs, &DeductionInfo) {}
709 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
710 TemplateArgs, &DeductionInfo) {}
720 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
721 TemplateArgs, &DeductionInfo) {}
729 PointOfInstantiation, InstantiationRange, Param,
nullptr,
739 PointOfInstantiation, InstantiationRange, Param,
Template,
749 PointOfInstantiation, InstantiationRange, Param,
Template,
758 PointOfInstantiation, InstantiationRange, Entity,
767 PointOfInstantiation, InstantiationRange, Param,
Template,
776 PointOfInstantiation, InstantiationRange,
nullptr,
777 nullptr, {}, &DeductionInfo) {}
785 PointOfInstantiation, InstantiationRange,
nullptr,
793 PointOfInstantiation, InstantiationRange,
nullptr,
794 nullptr, {}, &DeductionInfo) {}
812 {}, &DeductionInfo) {}
820 PointOfInstantiation, InstantiationRange,
Template) {}
828 PointOfInstantiation, InstantiationRange,
Template) {}
835 PointOfInstantiation, InstantiationRange, Entity) {}
841 ArgLoc, InstantiationRange, PArg) {}
850 assert(
SemaRef.NonInstantiationEntries <=
851 SemaRef.CodeSynthesisContexts.size());
852 if ((
SemaRef.CodeSynthesisContexts.size() -
853 SemaRef.NonInstantiationEntries) >
854 SemaRef.getLangOpts().InstantiationDepth) {
856 diag::err_template_recursion_depth_exceeded)
859 diag::note_template_recursion_depth)
860 <<
SemaRef.getLangOpts().InstantiationDepth;
875 if (!Active.isInstantiationRecord()) {
885 "forgot to remove a lookup module for a template instantiation");
904 if (!AlreadyInstantiating) {
905 auto &Active = SemaRef.CodeSynthesisContexts.back();
907 SemaRef.InstantiatingSpecializations.erase(
908 {Active.Entity->getCanonicalDecl(), Active.Kind});
912 SemaRef.CodeSynthesisContexts.back());
914 SemaRef.popCodeSynthesisContext();
922 llvm::raw_string_ostream
OS(Result);
923 llvm::ListSeparator Comma;
924 for (
const Expr *Arg : Args) {
926 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
935 unsigned Limit =
Diags.getTemplateBacktraceLimit();
937 SkipStart = Limit / 2 + Limit % 2;
942 unsigned InstantiationIdx = 0;
947 ++Active, ++InstantiationIdx) {
949 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
950 if (InstantiationIdx == SkipStart) {
952 DiagFunc(Active->PointOfInstantiation,
953 PDiag(diag::note_instantiation_contexts_suppressed)
959 switch (Active->Kind) {
961 Decl *D = Active->Entity;
963 unsigned DiagID = diag::note_template_member_class_here;
965 DiagID = diag::note_template_class_instantiation_here;
966 DiagFunc(Active->PointOfInstantiation,
967 PDiag(DiagID) <<
Record << Active->InstantiationRange);
971 DiagID = diag::note_function_template_spec_here;
973 DiagID = diag::note_template_member_function_here;
974 DiagFunc(Active->PointOfInstantiation,
976 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
977 DiagFunc(Active->PointOfInstantiation,
978 PDiag(VD->isStaticDataMember()
979 ? diag::note_template_static_data_member_def_here
980 : diag::note_template_variable_def_here)
981 << VD << Active->InstantiationRange);
982 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
983 DiagFunc(Active->PointOfInstantiation,
984 PDiag(diag::note_template_enum_def_here)
985 << ED << Active->InstantiationRange);
986 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
987 DiagFunc(Active->PointOfInstantiation,
988 PDiag(diag::note_template_nsdmi_here)
989 << FD << Active->InstantiationRange);
991 DiagFunc(Active->PointOfInstantiation,
992 PDiag(diag::note_template_class_instantiation_here)
993 << CTD << Active->InstantiationRange);
1001 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1003 printTemplateArgumentList(
OS, Active->template_arguments(),
1005 DiagFunc(Active->PointOfInstantiation,
1006 PDiag(diag::note_default_arg_instantiation_here)
1007 <<
OS.str() << Active->InstantiationRange);
1013 DiagFunc(Active->PointOfInstantiation,
1014 PDiag(diag::note_explicit_template_arg_substitution_here)
1018 Active->NumTemplateArgs)
1019 << Active->InstantiationRange);
1025 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1027 Active->PointOfInstantiation,
1028 PDiag(diag::note_function_template_deduction_instantiation_here)
1031 FnTmpl->getTemplateParameters(), Active->TemplateArgs,
1032 Active->NumTemplateArgs)
1033 << Active->InstantiationRange);
1037 bool IsTemplate =
false;
1039 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1041 Params = D->getTemplateParameters();
1042 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1044 Params = D->getTemplateParameters();
1045 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1047 Params = D->getTemplateParameters();
1049 llvm_unreachable(
"unexpected template kind");
1052 DiagFunc(Active->PointOfInstantiation,
1053 PDiag(diag::note_deduced_template_arg_substitution_here)
1056 Active->TemplateArgs,
1057 Active->NumTemplateArgs)
1058 << Active->InstantiationRange);
1068 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1070 printTemplateArgumentList(
OS, Active->template_arguments(),
1072 DiagFunc(Active->PointOfInstantiation,
1073 PDiag(diag::note_default_function_arg_instantiation_here)
1074 <<
OS.str() << Active->InstantiationRange);
1082 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1086 TemplateParams =
Template->getTemplateParameters();
1090 ->getTemplateParameters();
1091 DiagFunc(Active->PointOfInstantiation,
1092 PDiag(diag::note_prior_template_arg_substitution)
1095 Active->TemplateArgs,
1096 Active->NumTemplateArgs)
1097 << Active->InstantiationRange);
1104 TemplateParams =
Template->getTemplateParameters();
1108 ->getTemplateParameters();
1110 DiagFunc(Active->PointOfInstantiation,
1111 PDiag(diag::note_template_default_arg_checking)
1113 Active->TemplateArgs,
1114 Active->NumTemplateArgs)
1115 << Active->InstantiationRange);
1120 DiagFunc(Active->PointOfInstantiation,
1121 PDiag(diag::note_evaluating_exception_spec_here)
1126 DiagFunc(Active->PointOfInstantiation,
1127 PDiag(diag::note_template_exception_spec_instantiation_here)
1129 << Active->InstantiationRange);
1133 DiagFunc(Active->PointOfInstantiation,
1134 PDiag(diag::note_template_requirement_instantiation_here)
1135 << Active->InstantiationRange);
1138 DiagFunc(Active->PointOfInstantiation,
1139 PDiag(diag::note_template_requirement_params_instantiation_here)
1140 << Active->InstantiationRange);
1144 DiagFunc(Active->PointOfInstantiation,
1145 PDiag(diag::note_nested_requirement_here)
1146 << Active->InstantiationRange);
1150 DiagFunc(Active->PointOfInstantiation,
1151 PDiag(diag::note_in_declaration_of_implicit_special_member)
1153 << Active->SpecialMember);
1158 Active->Entity->getLocation(),
1159 PDiag(diag::note_in_declaration_of_implicit_equality_comparison));
1165 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1173 DiagFunc(Active->PointOfInstantiation,
1174 PDiag(diag::note_member_synthesized_at)
1176 <<
Context.getCanonicalTagType(MD->getParent()));
1178 QualType RecordType = FD->getParamDecl(0)
1180 .getNonReferenceType()
1181 .getUnqualifiedType();
1182 DiagFunc(Active->PointOfInstantiation,
1183 PDiag(diag::note_comparison_synthesized_at)
1190 DiagFunc(Active->Entity->getLocation(),
1191 PDiag(diag::note_rewriting_operator_as_spaceship));
1195 DiagFunc(Active->PointOfInstantiation,
1196 PDiag(diag::note_in_binding_decl_init)
1201 DiagFunc(Active->PointOfInstantiation,
1202 PDiag(diag::note_due_to_dllexported_class)
1208 DiagFunc(Active->PointOfInstantiation,
1209 PDiag(diag::note_building_builtin_dump_struct_call)
1212 Active->NumCallArgs)));
1219 DiagFunc(Active->PointOfInstantiation,
1220 PDiag(diag::note_lambda_substitution_here));
1223 unsigned DiagID = 0;
1224 if (!Active->Entity) {
1225 DiagFunc(Active->PointOfInstantiation,
1226 PDiag(diag::note_nested_requirement_here)
1227 << Active->InstantiationRange);
1231 DiagID = diag::note_concept_specialization_here;
1233 DiagID = diag::note_checking_constraints_for_template_id_here;
1235 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1237 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1240 DiagID = diag::note_checking_constraints_for_function_here;
1243 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1246 printTemplateArgumentList(
OS, Active->template_arguments(),
1249 DiagFunc(Active->PointOfInstantiation,
1250 PDiag(DiagID) <<
OS.str() << Active->InstantiationRange);
1254 DiagFunc(Active->PointOfInstantiation,
1255 PDiag(diag::note_constraint_substitution_here)
1256 << Active->InstantiationRange);
1259 DiagFunc(Active->PointOfInstantiation,
1260 PDiag(diag::note_constraint_normalization_here)
1262 << Active->InstantiationRange);
1265 DiagFunc(Active->PointOfInstantiation,
1266 PDiag(diag::note_parameter_mapping_substitution_here)
1267 << Active->InstantiationRange);
1270 DiagFunc(Active->PointOfInstantiation,
1271 PDiag(diag::note_building_deduction_guide_here));
1274 DiagFunc(Active->PointOfInstantiation,
1275 PDiag(diag::note_template_type_alias_instantiation_here)
1277 << Active->InstantiationRange);
1280 DiagFunc(Active->PointOfInstantiation,
1281 PDiag(diag::note_template_arg_template_params_mismatch));
1284 DiagFunc(ParamLoc,
PDiag(diag::note_template_prev_declaration)
1286 << Active->InstantiationRange);
1294 return std::optional<TemplateDeductionInfo *>(
nullptr);
1299 Active != ActiveEnd;
1302 switch (Active->Kind) {
1317 return std::nullopt;
1324 return std::nullopt;
1346 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1347 return Active->DeductionInfo;
1358 return std::nullopt;
1372 if (Active->SavedInNonInstantiationSFINAEContext)
1373 return std::optional<TemplateDeductionInfo *>(
nullptr);
1376 return std::nullopt;
1384 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1389 bool EvaluateConstraints =
true;
1392 bool IsIncomplete =
false;
1394 bool BailOutOnIncomplete;
1399 bool BuildPackExpansionTypes =
true;
1404 bool maybeInstantiateFunctionParameterToScope(
ParmVarDecl *OldParm);
1409 TemplateInstantiator(
Sema &SemaRef,
1412 bool BailOutOnIncomplete =
false)
1413 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1414 Entity(Entity), BailOutOnIncomplete(BailOutOnIncomplete) {}
1416 void setEvaluateConstraints(
bool B) {
1417 EvaluateConstraints = B;
1419 bool getEvaluateConstraints() {
1420 return EvaluateConstraints;
1423 inline static struct ForParameterMappingSubstitution_t {
1424 } ForParameterMappingSubstitution;
1426 TemplateInstantiator(ForParameterMappingSubstitution_t, Sema &SemaRef,
1428 const MultiLevelTemplateArgumentList &TemplateArgs,
1429 bool BuildPackExpansionTypes)
1430 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1431 BailOutOnIncomplete(
false),
1432 BuildPackExpansionTypes(BuildPackExpansionTypes) {}
1439 bool AlreadyTransformed(QualType
T);
1442 SourceLocation getBaseLocation() {
return Loc; }
1445 DeclarationName getBaseEntity() {
return Entity; }
1448 bool getIsIncomplete()
const {
return IsIncomplete; }
1452 void setBase(SourceLocation Loc, DeclarationName Entity) {
1454 this->Entity = Entity;
1457 unsigned TransformTemplateDepth(
unsigned Depth) {
1461 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1462 SourceRange PatternRange,
1463 ArrayRef<UnexpandedParameterPack> Unexpanded,
1464 bool FailOnPackProducingTemplates,
1465 bool &ShouldExpand,
bool &RetainExpansion,
1466 UnsignedOrNone &NumExpansions) {
1471 NamedDecl *VD = ParmPack.first.dyn_cast<NamedDecl *>();
1472 if (
auto *PVD = dyn_cast_if_present<ParmVarDecl>(VD);
1473 PVD && maybeInstantiateFunctionParameterToScope(PVD))
1478 return getSema().CheckParameterPacksForExpansion(
1479 EllipsisLoc, PatternRange, Unexpanded, TemplateArgs,
1480 FailOnPackProducingTemplates, ShouldExpand, RetainExpansion,
1484 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1488 TemplateArgument ForgetPartiallySubstitutedPack() {
1492 MultiLevelTemplateArgumentList &TemplateArgs =
1493 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1494 unsigned Depth, Index;
1497 Result = TemplateArgs(Depth, Index);
1498 TemplateArgs.
setArgument(Depth, Index, TemplateArgument());
1500 IsIncomplete =
true;
1501 if (BailOutOnIncomplete)
1502 return TemplateArgument();
1509 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1515 MultiLevelTemplateArgumentList &TemplateArgs =
1516 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1517 unsigned Depth, Index;
1523 MultiLevelTemplateArgumentList ForgetSubstitution() {
1524 MultiLevelTemplateArgumentList
New;
1527 MultiLevelTemplateArgumentList Old =
1528 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1529 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1534 void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
1535 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) = Old;
1539 getTemplateArgumentPackPatternForRewrite(
const TemplateArgument &TA) {
1545 "unexpected pack arguments in template rewrite");
1554 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1556 void transformAttrs(Decl *Old, Decl *
New) {
1560 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1562 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1564 for (
auto *
New : NewDecls)
1570 assert(NewDecls.size() == 1 &&
1571 "should only have multiple expansions for a pack");
1577 auto *NewMD = dyn_cast<CXXMethodDecl>(
New);
1579 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1580 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1581 NewTD->setInstantiatedFromMemberTemplate(
1582 OldMD->getDescribedFunctionTemplate());
1584 NewMD->setInstantiationOfMemberFunction(OldMD,
1592 if (
auto *DC = dyn_cast<DeclContext>(Old);
1593 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1599 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1603 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1605 bool TransformExceptionSpec(SourceLocation Loc,
1606 FunctionProtoType::ExceptionSpecInfo &ESI,
1607 SmallVectorImpl<QualType> &Exceptions,
1612 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1613 TypeSourceInfo *Declarator,
1614 SourceLocation StartLoc,
1615 SourceLocation NameLoc,
1616 IdentifierInfo *Name);
1620 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1621 TypeSourceInfo *TSInfo, QualType
T);
1624 TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc,
1626 SourceLocation NameLoc,
1627 QualType ObjectType = QualType(),
1628 NamedDecl *FirstQualifierInScope =
nullptr,
1629 bool AllowInjectedClassName =
false);
1631 const AnnotateAttr *TransformAnnotateAttr(
const AnnotateAttr *AA);
1632 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1633 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1634 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1636 const NoInlineAttr *A);
1637 const AlwaysInlineAttr *
1638 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1639 const AlwaysInlineAttr *A);
1640 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1641 const OpenACCRoutineDeclAttr *
1642 TransformOpenACCRoutineDeclAttr(
const OpenACCRoutineDeclAttr *A);
1643 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1644 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1645 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1647 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1648 NonTypeTemplateParmDecl *D);
1651 ExprResult RebuildVarDeclRefExpr(ValueDecl *PD, SourceLocation Loc);
1654 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, ValueDecl *PD);
1659 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1661 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1662 FunctionProtoTypeLoc TL) {
1664 return inherited::TransformFunctionProtoType(TLB, TL);
1667 QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL) {
1668 auto Type = inherited::TransformTagType(TLB, TL);
1674 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TL.
getTypePtr());
1677 Type = inherited::TransformType(
1678 ICNT->getOriginalDecl()->getCanonicalTemplateSpecializationType(
1686 bool TransformTemplateArgument(
const TemplateArgumentLoc &Input,
1687 TemplateArgumentLoc &Output,
1688 bool Uneval =
false) {
1689 const TemplateArgument &Arg = Input.
getArgument();
1690 std::vector<TemplateArgument> TArgs;
1700 pack, QualType(), SourceLocation{});
1701 TemplateArgumentLoc Output;
1702 if (TransformTemplateArgument(Input, Output, Uneval))
1707 TemplateArgument(llvm::ArrayRef(TArgs).copy(SemaRef.
Context)),
1708 QualType(), SourceLocation{});
1713 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1717 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
1718 UnsignedOrNone NumExpansions) {
1719 return inherited::RebuildPackExpansion(Pattern, EllipsisLoc,
1723 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
1724 SourceLocation EllipsisLoc,
1725 UnsignedOrNone NumExpansions) {
1728 if (BuildPackExpansionTypes)
1729 return inherited::RebuildPackExpansion(Pattern, EllipsisLoc,
1736 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
1737 TemplateSpecializationTypeLoc TL) {
1739 if (!getSema().ArgPackSubstIndex || !
T->
isSugared() ||
1749 QualType R = TransformType(
T->
desugar());
1754 UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(
1755 ArrayRef<TemplateArgument> PackArgs) {
1766 return std::nullopt;
1768 return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1771 template<
typename Fn>
1772 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1773 FunctionProtoTypeLoc TL,
1774 CXXRecordDecl *ThisContext,
1775 Qualifiers ThisTypeQuals,
1776 Fn TransformExceptionSpec);
1778 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1779 int indexAdjustment,
1780 UnsignedOrNone NumExpansions,
1781 bool ExpectParameterPack);
1783 using inherited::TransformTemplateTypeParmType;
1786 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1787 TemplateTypeParmTypeLoc TL,
1788 bool SuppressObjCLifetime);
1790 QualType BuildSubstTemplateTypeParmType(
1791 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
1792 Decl *AssociatedDecl,
unsigned Index, UnsignedOrNone PackIndex,
1793 TemplateArgument Arg, SourceLocation NameLoc);
1798 using inherited::TransformSubstTemplateTypeParmPackType;
1800 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1801 SubstTemplateTypeParmPackTypeLoc TL,
1802 bool SuppressObjCLifetime);
1804 TransformSubstBuiltinTemplatePackType(TypeLocBuilder &TLB,
1805 SubstBuiltinTemplatePackTypeLoc TL);
1808 ComputeLambdaDependency(LambdaScopeInfo *LSI) {
1810 TemplateInstArgsHelpers::getEnclosingTypeAliasTemplateDecl(
1812 TypeAlias && TemplateInstArgsHelpers::isLambdaEnclosedByTypeAliasDecl(
1814 unsigned TypeAliasDeclDepth =
TypeAlias.Template->getTemplateDepth();
1816 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1817 for (
const TemplateArgument &TA :
TypeAlias.AssociatedTemplateArguments)
1819 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1821 return inherited::ComputeLambdaDependency(LSI);
1829 LocalInstantiationScope Scope(SemaRef,
true,
1831 Sema::ConstraintEvalRAII<TemplateInstantiator> RAII(*
this);
1833 return inherited::TransformLambdaExpr(E);
1836 ExprResult TransformBlockExpr(BlockExpr *E) {
1837 LocalInstantiationScope Scope(SemaRef,
true,
1839 return inherited::TransformBlockExpr(E);
1842 ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1843 LambdaScopeInfo *LSI) {
1846 assert(PVD &&
"null in a parameter list");
1847 if (!PVD->hasDefaultArg())
1849 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1851 SourceLocation EqualLoc = UninstExpr->
getBeginLoc();
1860 PVD->setDefaultArg(ErrorResult.
get());
1863 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1876 llvm::SaveAndRestore _(EvaluateConstraints,
true);
1877 return inherited::TransformLambdaBody(E, Body);
1881 LocalInstantiationScope Scope(SemaRef,
true);
1882 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1885 assert(TransReq.
get() != E &&
1886 "Do not change value of isSatisfied for the existing expression. "
1887 "Create a new expression instead.");
1889 Sema::SFINAETrap Trap(SemaRef);
1894 if (Trap.hasErrorOccurred())
1900 bool TransformRequiresExprRequirements(
1901 ArrayRef<concepts::Requirement *> Reqs,
1902 SmallVectorImpl<concepts::Requirement *> &Transformed) {
1903 bool SatisfactionDetermined =
false;
1904 for (concepts::Requirement *Req : Reqs) {
1905 concepts::Requirement *TransReq =
nullptr;
1906 if (!SatisfactionDetermined) {
1907 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1908 TransReq = TransformTypeRequirement(TypeReq);
1909 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1910 TransReq = TransformExprRequirement(ExprReq);
1912 TransReq = TransformNestedRequirement(
1922 SatisfactionDetermined =
true;
1925 Transformed.push_back(TransReq);
1930 TemplateParameterList *TransformTemplateParameterList(
1931 TemplateParameterList *OrigTPL) {
1932 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1935 TemplateDeclInstantiator DeclInstantiator(getSema(),
1936 Owner, TemplateArgs);
1937 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1938 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1941 concepts::TypeRequirement *
1942 TransformTypeRequirement(concepts::TypeRequirement *Req);
1943 concepts::ExprRequirement *
1944 TransformExprRequirement(concepts::ExprRequirement *Req);
1945 concepts::NestedRequirement *
1946 TransformNestedRequirement(concepts::NestedRequirement *Req);
1948 SourceLocation KWLoc, SourceLocation RBraceLoc,
const RequiresExpr *RE,
1949 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params,
1950 SmallVectorImpl<QualType> &PTypes,
1951 SmallVectorImpl<ParmVarDecl *> &TransParams,
1952 Sema::ExtParameterInfoBuilder &PInfos);
1956bool TemplateInstantiator::AlreadyTransformed(QualType
T) {
1964 getSema().MarkDeclarationsReferencedInType(Loc,
T);
1968Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1972 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1979 TTP->getPosition())) {
1980 IsIncomplete =
true;
1981 return BailOutOnIncomplete ?
nullptr : D;
1984 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1986 if (TTP->isParameterPack()) {
1988 "Missing argument pack");
1989 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
1994 "Wrong kind of template template argument");
1995 return Template.getAsTemplateDecl();
2002 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(D);
2003 PVD &&
SemaRef.CurrentInstantiationScope &&
2004 (
SemaRef.inConstraintSubstitution() ||
2005 SemaRef.inParameterMappingSubstitution()) &&
2006 maybeInstantiateFunctionParameterToScope(PVD))
2012bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
2013 ParmVarDecl *OldParm) {
2014 if (
SemaRef.CurrentInstantiationScope->getInstantiationOfIfExists(OldParm))
2018 return !TransformFunctionTypeParam(OldParm, 0,
2022 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2026 PackExpansionTypeLoc ExpansionTL = TL.
castAs<PackExpansionTypeLoc>();
2028 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
2029 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
2031 bool ShouldExpand =
false;
2032 bool RetainExpansion =
false;
2033 UnsignedOrNone OrigNumExpansions =
2034 ExpansionTL.
getTypePtr()->getNumExpansions();
2035 UnsignedOrNone NumExpansions = OrigNumExpansions;
2037 Pattern.getSourceRange(), Unexpanded,
2039 ShouldExpand, RetainExpansion, NumExpansions))
2042 assert(ShouldExpand && !RetainExpansion &&
2043 "Shouldn't preserve pack expansion when evaluating constraints");
2044 ExpandingFunctionParameterPack(OldParm);
2045 for (
unsigned I = 0; I != *NumExpansions; ++I) {
2046 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
2047 if (!TransformFunctionTypeParam(OldParm, 0,
2055Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
2056 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
2060 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2064bool TemplateInstantiator::TransformExceptionSpec(
2065 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
2066 SmallVectorImpl<QualType> &Exceptions,
bool &Changed) {
2071 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
2075TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
2076 SourceLocation Loc) {
2079 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
2080 const TemplateTypeParmType *TTP
2085 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
2087 if (TTP->isParameterPack()) {
2089 "Missing argument pack");
2094 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2099 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2101 if (
const TagType *Tag =
T->
getAs<TagType>())
2102 return Tag->getOriginalDecl();
2105 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
2110 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2114TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
2115 TypeSourceInfo *Declarator,
2116 SourceLocation StartLoc,
2117 SourceLocation NameLoc,
2118 IdentifierInfo *Name) {
2119 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
2120 StartLoc, NameLoc, Name);
2122 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2126VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
2127 TypeSourceInfo *TSInfo,
2129 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
2131 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2135TemplateName TemplateInstantiator::TransformTemplateName(
2136 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
2137 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
2138 NamedDecl *FirstQualifierInScope,
bool AllowInjectedClassName) {
2140 assert(!QualifierLoc &&
"Unexpected qualifier");
2143 TTP && TTP->getDepth() < TemplateArgs.
getNumLevels()) {
2149 TTP->getPosition())) {
2150 IsIncomplete =
true;
2154 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
2159 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2161 "unexpected nontype template argument kind in template rewrite");
2165 auto [AssociatedDecl, Final] =
2167 UnsignedOrNone PackIndex = std::nullopt;
2168 if (TTP->isParameterPack()) {
2170 "Missing argument pack");
2176 return getSema().Context.getSubstTemplateTemplateParmPack(
2177 Arg, AssociatedDecl, TTP->getIndex(), Final);
2180 PackIndex =
SemaRef.getPackIndex(Arg);
2181 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2185 assert(!
Template.isNull() &&
"Null template template argument");
2186 return getSema().Context.getSubstTemplateTemplateParm(
2187 Template, AssociatedDecl, TTP->getIndex(), PackIndex, Final);
2191 if (SubstTemplateTemplateParmPackStorage *SubstPack
2196 TemplateArgument Pack = SubstPack->getArgumentPack();
2198 SemaRef.getPackSubstitutedTemplateArgument(Pack).getAsTemplate();
2199 return getSema().Context.getSubstTemplateTemplateParm(
2200 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2201 SemaRef.getPackIndex(Pack), SubstPack->getFinal());
2204 return inherited::TransformTemplateName(
2205 QualifierLoc, TemplateKWLoc, Name, NameLoc, ObjectType,
2206 FirstQualifierInScope, AllowInjectedClassName);
2210TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
2218TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
2219 NonTypeTemplateParmDecl *NTTP) {
2226 IsIncomplete =
true;
2227 return BailOutOnIncomplete ?
ExprError() : E;
2235 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2237 "unexpected nontype template argument kind in template rewrite");
2243 auto [AssociatedDecl, Final] =
2245 UnsignedOrNone PackIndex = std::nullopt;
2248 "Missing argument pack");
2254 QualType TargetType =
SemaRef.SubstType(NTTP->
getType(), TemplateArgs,
2263 return new (
SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
2267 PackIndex =
SemaRef.getPackIndex(Arg);
2268 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2270 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
2271 AssociatedDecl, NTTP, E->
getLocation(), Arg, PackIndex, Final);
2275TemplateInstantiator::TransformAnnotateAttr(
const AnnotateAttr *AA) {
2276 SmallVector<Expr *> Args;
2277 for (Expr *Arg : AA->args()) {
2278 ExprResult Res = getDerived().TransformExpr(Arg);
2280 Args.push_back(Res.
get());
2282 return AnnotateAttr::CreateImplicit(getSema().
Context, AA->getAnnotation(),
2283 Args.data(), Args.size(), AA->getRange());
2286const CXXAssumeAttr *
2287TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2288 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2292 if (!(Res.
get()->
getDependence() & ExprDependence::TypeValueInstantiation)) {
2293 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2299 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2304TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2305 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2307 if (TransformedExpr == LH->getValue())
2312 LH->getSemanticSpelling() ==
2313 LoopHintAttr::Pragma_unroll))
2316 LoopHintAttr::OptionType Option = LH->getOption();
2317 LoopHintAttr::LoopHintState State = LH->getState();
2319 llvm::APSInt ValueAPS =
2322 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2323 Option = LoopHintAttr::Unroll;
2324 State = LoopHintAttr::Disable;
2329 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2330 TransformedExpr, *LH);
2332const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2333 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2339const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2340 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2347const CodeAlignAttr *
2348TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2349 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2350 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2352const OpenACCRoutineDeclAttr *
2353TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
2354 const OpenACCRoutineDeclAttr *A) {
2355 llvm_unreachable(
"RoutineDecl should only be a declaration attribute, as it "
2356 "applies to a Function Decl (and a few places for VarDecl)");
2359ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,
2360 SourceLocation Loc) {
2361 DeclarationNameInfo NameInfo(PD->
getDeclName(), Loc);
2362 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
2366TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
2370 ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), D));
2373 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2376 QualType
T = TransformType(E->
getType());
2382 SmallVector<ValueDecl *, 8> Vars;
2386 ValueDecl *D = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), *I));
2395 getSema().MarkFunctionParmPackReferenced(PackExpr);
2400TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
2403 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found
2404 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2405 assert(
Found &&
"no instantiation for parameter pack");
2407 Decl *TransformedDecl;
2408 if (DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(*
Found)) {
2412 QualType
T = TransformType(E->
getType());
2417 getSema().MarkFunctionParmPackReferenced(PackExpr);
2421 TransformedDecl = (*Pack)[*getSema().ArgPackSubstIndex];
2432TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
2437 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2439 return TransformTemplateParmRefExpr(E, NTTP);
2446 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2448 return TransformFunctionParmPackRefExpr(E, PD);
2450 return inherited::TransformDeclRefExpr(E);
2453ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2454 CXXDefaultArgExpr *E) {
2456 getDescribedFunctionTemplate() &&
2457 "Default arg expressions are never formed in dependent cases.");
2458 return SemaRef.BuildCXXDefaultArgExpr(
2463template<
typename Fn>
2464QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2465 FunctionProtoTypeLoc TL,
2466 CXXRecordDecl *ThisContext,
2467 Qualifiers ThisTypeQuals,
2468 Fn TransformExceptionSpec) {
2476 LocalInstantiationScope *Current = getSema().CurrentInstantiationScope;
2477 std::optional<LocalInstantiationScope> Scope;
2481 return inherited::TransformFunctionProtoType(
2482 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2485ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2486 ParmVarDecl *OldParm,
int indexAdjustment, UnsignedOrNone NumExpansions,
2487 bool ExpectParameterPack) {
2488 auto NewParm =
SemaRef.SubstParmVarDecl(
2489 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2490 ExpectParameterPack, EvaluateConstraints);
2491 if (NewParm &&
SemaRef.getLangOpts().OpenCL)
2492 SemaRef.deduceOpenCLAddressSpace(NewParm);
2496QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2497 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
2498 Decl *AssociatedDecl,
unsigned Index, UnsignedOrNone PackIndex,
2499 TemplateArgument Arg, SourceLocation NameLoc) {
2504 if (SuppressObjCLifetime) {
2506 RQs = Replacement.getQualifiers();
2509 SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2513 QualType
Result = getSema().Context.getSubstTemplateTypeParmType(
2514 Replacement, AssociatedDecl, Index, PackIndex, Final);
2515 SubstTemplateTypeParmTypeLoc NewTL =
2516 TLB.
push<SubstTemplateTypeParmTypeLoc>(
Result);
2522TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2523 TemplateTypeParmTypeLoc TL,
2524 bool SuppressObjCLifetime) {
2535 IsIncomplete =
true;
2536 if (BailOutOnIncomplete)
2539 TemplateTypeParmTypeLoc NewTL
2540 = TLB.
push<TemplateTypeParmTypeLoc>(TL.
getType());
2545 TemplateArgument Arg = TemplateArgs(
T->getDepth(),
T->getIndex());
2550 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2552 "unexpected nontype template argument kind in template rewrite");
2558 auto [AssociatedDecl, Final] =
2560 UnsignedOrNone PackIndex = std::nullopt;
2561 if (
T->isParameterPack()) {
2563 "Missing argument pack");
2569 QualType
Result = getSema().Context.getSubstTemplateTypeParmPackType(
2570 AssociatedDecl,
T->getIndex(), Final, Arg);
2571 SubstTemplateTypeParmPackTypeLoc NewTL
2572 = TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2578 PackIndex =
SemaRef.getPackIndex(Arg);
2579 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2583 "Template argument kind mismatch");
2585 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2586 AssociatedDecl,
T->getIndex(),
2594 TemplateTypeParmDecl *NewTTPDecl =
nullptr;
2595 if (TemplateTypeParmDecl *OldTTPDecl =
T->getDecl())
2596 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2598 QualType
Result = getSema().Context.getTemplateTypeParmType(
2600 T->isParameterPack(), NewTTPDecl);
2601 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
2606QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2607 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2608 bool SuppressObjCLifetime) {
2609 const SubstTemplateTypeParmPackType *
T = TL.
getTypePtr();
2611 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2616 if (NewReplaced !=
T->getAssociatedDecl())
2617 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2618 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2619 SubstTemplateTypeParmPackTypeLoc NewTL =
2620 TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2625 TemplateArgument Pack =
T->getArgumentPack();
2626 TemplateArgument Arg =
SemaRef.getPackSubstitutedTemplateArgument(Pack);
2627 return BuildSubstTemplateTypeParmType(
2628 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2632QualType TemplateInstantiator::TransformSubstBuiltinTemplatePackType(
2633 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
2635 return TreeTransform::TransformSubstBuiltinTemplatePackType(TLB, TL);
2636 TemplateArgument
Result =
SemaRef.getPackSubstitutedTemplateArgument(
2640 return Result.getAsType();
2643static concepts::Requirement::SubstitutionDiagnostic *
2653 ErrorLoc = PDA.first;
2658 llvm::raw_svector_ostream
OS(Entity);
2662 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2665concepts::Requirement::SubstitutionDiagnostic *
2668 llvm::raw_svector_ostream
OS(Entity);
2672 C.backupStr(Entity),
2673 Location, StringRef()};
2676ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2690 if (getDerived().TransformFunctionTypeParams(
2691 KWLoc, Params,
nullptr,
nullptr, PTypes,
2692 &TransParams, PInfos, &ErrorIdx) ||
2693 Trap.hasErrorOccurred()) {
2699 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2700 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2702 TransReqs, RBraceLoc);
2708concepts::TypeRequirement *
2709TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2713 if (AlwaysRebuild())
2714 return RebuildTypeRequirement(
2719 Sema::SFINAETrap Trap(
SemaRef);
2721 Sema::InstantiatingTemplate TypeInst(
SemaRef,
2724 if (TypeInst.isInvalid())
2726 TypeSourceInfo *TransType = TransformType(Req->
getType());
2727 if (!TransType || Trap.hasErrorOccurred())
2729 [&] (llvm::raw_ostream&
OS) {
2732 return RebuildTypeRequirement(TransType);
2735concepts::ExprRequirement *
2736TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2740 Sema::SFINAETrap Trap(
SemaRef);
2742 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2751 if (ExprInst.isInvalid())
2754 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2756 TransExprRes =
SemaRef.CheckPlaceholderExpr(TransExprRes.
get());
2757 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2762 TransExpr = TransExprRes.
get();
2765 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2767 if (RetReq.isEmpty())
2768 TransRetReq.emplace();
2769 else if (RetReq.isSubstitutionFailure())
2770 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2771 else if (RetReq.isTypeConstraint()) {
2772 TemplateParameterList *OrigTPL =
2773 RetReq.getTypeConstraintTemplateParameterList();
2777 if (TPLInst.isInvalid())
2779 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2780 if (!TPL || Trap.hasErrorOccurred())
2782 [&] (llvm::raw_ostream&
OS) {
2783 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2784 ->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2788 TransRetReq.emplace(TPL);
2791 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2792 if (Expr *E = TransExpr.dyn_cast<Expr *>())
2794 std::move(*TransRetReq));
2795 return RebuildExprRequirement(
2800concepts::NestedRequirement *
2801TemplateInstantiator::TransformNestedRequirement(
2802 concepts::NestedRequirement *Req) {
2807 ConstraintSatisfaction Satisfaction;
2809 auto NestedReqWithDiag = [&
C,
this](Expr *E,
2810 ConstraintSatisfaction Satisfaction) {
2812 SmallString<128> Entity;
2813 llvm::raw_svector_ostream
OS(Entity);
2814 E->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2815 return new (
C) concepts::NestedRequirement(
2816 SemaRef.Context,
C.backupStr(Entity), std::move(Satisfaction));
2820 if (AlwaysRebuild())
2826 if (!getEvaluateConstraints()) {
2828 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2832 concepts::NestedRequirement(TransConstraint.
get());
2833 ConstraintSatisfaction Satisfaction;
2834 return new (
SemaRef.Context) concepts::NestedRequirement(
2835 SemaRef.Context, TransConstraint.
get(), Satisfaction);
2839 Expr *NewConstraint;
2840 TemplateDeductionInfo Info(Constraint->
getBeginLoc());
2845 Sema::InstantiatingTemplate ConstrInst(
2847 Sema::InstantiatingTemplate::ConstraintsCheck(),
2850 if (ConstrInst.isInvalid())
2853 Sema::SFINAETrap Trap(
SemaRef);
2856 Req, AssociatedConstraint(Constraint,
SemaRef.ArgPackSubstIndex),
2858 nullptr, &NewConstraint);
2860 assert(!
Success || !Trap.hasErrorOccurred() &&
2861 "Substitution failures must be handled "
2862 "by CheckConstraintSatisfaction.");
2866 return NestedReqWithDiag(Constraint, Satisfaction);
2870 if (!NewConstraint) {
2872 return NestedReqWithDiag(Constraint, Satisfaction);
2874 NewConstraint = Constraint;
2876 return new (
C) concepts::NestedRequirement(
C, NewConstraint, Satisfaction);
2883 bool AllowDeducedTST) {
2885 "Cannot perform an instantiation without some context on the "
2886 "instantiation stack");
2888 if (!
T->getType()->isInstantiationDependentType() &&
2889 !
T->getType()->isVariablyModifiedType())
2892 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2893 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2894 : Instantiator.TransformType(
T);
2902 "Cannot perform an instantiation without some context on the "
2903 "instantiation stack");
2917 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2931 bool *IsIncompleteSubstitution) {
2933 "Cannot perform an instantiation without some context on the "
2934 "instantiation stack");
2938 if (!
T->isInstantiationDependentType() && !
T->isVariablyModifiedType())
2941 TemplateInstantiator Instantiator(
2942 *
this, TemplateArgs, Loc, Entity,
2943 IsIncompleteSubstitution !=
nullptr);
2944 QualType QT = Instantiator.TransformType(
T);
2945 if (IsIncompleteSubstitution && Instantiator.getIsIncomplete())
2946 *IsIncompleteSubstitution =
true;
2951 if (
T->getType()->isInstantiationDependentType() ||
2952 T->getType()->isVariablyModifiedType())
2955 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2978 bool EvaluateConstraints) {
2980 "Cannot perform an instantiation without some context on the "
2981 "instantiation stack");
2986 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2987 Instantiator.setEvaluateConstraints(EvaluateConstraints);
3003 Result = Instantiator.TransformFunctionProtoType(
3004 TLB, Proto, ThisContext, ThisTypeQuals,
3006 bool &Changed) {
return false; });
3008 Result = Instantiator.TransformType(TLB, TL);
3022 bool Changed =
false;
3023 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
3024 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
3035 ESI, ExceptionStorage, Args))
3044 struct GetContainedInventedTypeParmVisitor :
3045 public TypeVisitor<GetContainedInventedTypeParmVisitor,
3046 TemplateTypeParmDecl *> {
3047 using TypeVisitor<GetContainedInventedTypeParmVisitor,
3053 return Visit(
T.getTypePtr());
3057 const TemplateTypeParmType *
T) {
3058 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
3060 return T->getDecl();
3066 TemplateTypeParmDecl *VisitPointerType(
const PointerType *
T) {
3070 TemplateTypeParmDecl *VisitBlockPointerType(
const BlockPointerType *
T) {
3074 TemplateTypeParmDecl *VisitReferenceType(
const ReferenceType *
T) {
3075 return Visit(
T->getPointeeTypeAsWritten());
3078 TemplateTypeParmDecl *VisitMemberPointerType(
const MemberPointerType *
T) {
3082 TemplateTypeParmDecl *VisitArrayType(
const ArrayType *
T) {
3083 return Visit(
T->getElementType());
3086 TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
3087 const DependentSizedExtVectorType *
T) {
3088 return Visit(
T->getElementType());
3091 TemplateTypeParmDecl *VisitVectorType(
const VectorType *
T) {
3092 return Visit(
T->getElementType());
3095 TemplateTypeParmDecl *VisitFunctionProtoType(
const FunctionProtoType *
T) {
3096 return VisitFunctionType(
T);
3099 TemplateTypeParmDecl *VisitFunctionType(
const FunctionType *
T) {
3103 TemplateTypeParmDecl *VisitParenType(
const ParenType *
T) {
3104 return Visit(
T->getInnerType());
3107 TemplateTypeParmDecl *VisitAttributedType(
const AttributedType *
T) {
3108 return Visit(
T->getModifiedType());
3111 TemplateTypeParmDecl *VisitMacroQualifiedType(
const MacroQualifiedType *
T) {
3112 return Visit(
T->getUnderlyingType());
3115 TemplateTypeParmDecl *VisitAdjustedType(
const AdjustedType *
T) {
3116 return Visit(
T->getOriginalType());
3119 TemplateTypeParmDecl *VisitPackExpansionType(
const PackExpansionType *
T) {
3120 return Visit(
T->getPattern());
3129 bool EvaluateConstraints) {
3136 Index =
SemaRef.ArgPackSubstIndex;
3165 bool ExpectParameterPack,
bool EvaluateConstraint) {
3185 }
else if (ExpectParameterPack) {
3191 diag::err_function_parameter_pack_without_parameter_packs)
3215 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
3217 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3222 if (Inst && !Inst->getTypeConstraint()) {
3291 "Cannot perform an instantiation without some context on the "
3292 "instantiation stack");
3294 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3296 return Instantiator.TransformFunctionTypeParams(
3297 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3306 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3315 Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
3327 std::optional<LocalInstantiationScope> LIS;
3338 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3355 Param->getLocation(),
3360 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3390 auto ComputeInfo = [&S, &TemplateArgs, BaseSourceRange, BaseEllipsisLoc](
3397 if (IsLateExpansionAttempt) {
3402 return P.first.dyn_cast<
const SubstBuiltinTemplatePackType *>();
3404 if (!SawPackTypes) {
3416 BaseEllipsisLoc, BaseSourceRange, Unexpanded, TemplateArgs,
3421 if (ComputeInfo(
Base.getTypeSourceInfo(),
false, Info))
3425 Out =
Base.getTypeSourceInfo();
3435 if (!Out->getType()->containsUnexpandedParameterPack())
3440 if (ComputeInfo(Out,
true, Info))
3453 for (
const auto &
Base : Pattern->
bases()) {
3454 if (!
Base.getType()->isDependentType()) {
3456 if (RD->isInvalidDecl())
3465 if (
Base.isPackExpansion()) {
3477 ArgsForSubst = &EmptyList;
3492 Instantiation,
Base.getSourceRange(),
Base.isVirtual(),
3493 Base.getAccessSpecifierAsWritten(), Expanded,
3495 InstantiatedBases.push_back(InstantiatedBase);
3504 EllipsisLoc =
Base.getEllipsisLoc();
3512 Base.getSourceRange().getBegin(),
3523 Base.getSourceRange(),
3525 Base.getAccessSpecifierAsWritten(),
3528 InstantiatedBases.push_back(InstantiatedBase);
3560 Pattern, PatternDef, TSK, Complain))
3563 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3564 llvm::TimeTraceMetadata M;
3565 llvm::raw_string_ostream
OS(M.Detail);
3568 if (llvm::isTimeTraceVerbose()) {
3571 M.Line =
SourceMgr.getExpansionLineNumber(Loc);
3576 Pattern = PatternDef;
3581 MSInfo->setTemplateSpecializationKind(TSK);
3582 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3584 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3585 Spec->setTemplateSpecializationKind(TSK);
3586 Spec->setPointOfInstantiation(PointOfInstantiation);
3594 "instantiating class definition");
3612 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3638 bool MightHaveConstexprVirtualFunctions =
false;
3649 if (
Member->getDeclContext() != Pattern)
3660 if (
Member->isInvalidDecl()) {
3667 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3668 Fields.push_back(Field);
3669 }
else if (
EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3675 Enum->isCompleteDefinition()) {
3677 assert(MSInfo &&
"no spec info for member enum specialization");
3682 if (SA->isFailed()) {
3688 }
else if (
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3691 MightHaveConstexprVirtualFunctions =
true;
3712 if (ParsingClassDepth == 0)
3717 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3718 E = LateAttrs.end(); I != E; ++I) {
3724 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3726 ND->isCXXInstanceMember());
3731 I->NewDecl->addAttr(NewAttr);
3760 P->first, P->second)) {
3773 P->first, P->second)) {
3790 else if (MightHaveConstexprVirtualFunctions)
3795 Consumer.HandleTagDeclDefinition(Instantiation);
3807 Pattern, PatternDef, TSK,
true))
3809 Pattern = PatternDef;
3814 MSInfo->setTemplateSpecializationKind(TSK);
3815 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3824 "instantiating enum definition");
3859 "pattern and instantiation disagree about init style");
3867 Diag(PointOfInstantiation,
3868 diag::err_default_member_initializer_not_yet_parsed)
3869 << OutermostClass << Pattern;
3870 Diag(Pattern->getEndLoc(),
3871 diag::note_default_member_initializer_not_yet_parsed);
3881 Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3886 "instantiating default member init");
3894 PointOfInstantiation, Instantiation,
CurContext};
3910 L->DefaultMemberInitializerInstantiated(Instantiation);
3919 struct PartialSpecMatchResult {
3945 !CTPSD->getMostRecentDecl()->isMemberSpecialization())
3986 typedef PartialSpecMatchResult MatchResult;
3989 Template->getPartialSpecializations(PartialSpecs);
4002 if (
Template->getMostRecentDecl()->isMemberSpecialization() &&
4003 !Partial->getMostRecentDecl()->isMemberSpecialization())
4021 if (Matched.empty() && PrimaryStrictPackMatch)
4022 Matched = std::move(ExtraMatched);
4028 if (Matched.size() >= 1) {
4030 if (Matched.size() == 1) {
4043 PEnd = Matched.end();
4046 P->Partial, Best->Partial, PointOfInstantiation) ==
4055 PEnd = Matched.end();
4058 P->Partial, Best->Partial,
4059 PointOfInstantiation) != Best->Partial) {
4068 S.
Diag(PointOfInstantiation,
4069 diag::err_partial_spec_ordering_ambiguous)
4070 << ClassTemplateSpec;
4074 PEnd = Matched.end();
4076 S.
Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
4078 P->Partial->getTemplateParameters(), *P->Args);
4093 if (
auto *PartialSpec =
4096 while (PartialSpec->getInstantiatedFromMember()) {
4099 if (PartialSpec->isMemberSpecialization())
4102 PartialSpec = PartialSpec->getInstantiatedFromMember();
4104 Pattern = PartialSpec;
4107 while (
Template->getInstantiatedFromMemberTemplate()) {
4110 if (
Template->isMemberSpecialization())
4115 Pattern =
Template->getTemplatedDecl();
4125 bool PrimaryStrictPackMatch) {
4132 bool HadAvaibilityWarning =
4138 ClassTemplateSpec, TSK,
4139 PrimaryStrictPackMatch);
4145 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4152 if (!Err && !HadAvaibilityWarning) {
4172 "Unexpected template specialization kind!");
4173 for (
auto *D : Instantiation->
decls()) {
4174 bool SuppressNew =
false;
4175 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4177 Function->getInstantiatedFromMemberFunction()) {
4179 if (
Function->getTrailingRequiresClause()) {
4187 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4191 Function->getTemplateSpecializationKind();
4196 PointOfInstantiation, TSK,
Function, PrevTSK,
4197 Function->getPointOfInstantiation(), SuppressNew) ||
4210 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4220 std::make_pair(
Function, PointOfInstantiation));
4223 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4228 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4232 assert(MSInfo &&
"No member specialization information?");
4261 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4262 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4270 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4275 assert(MSInfo &&
"No member specialization information?");
4281 if (
Context.getTargetInfo().getTriple().isOSWindows() &&
4301 assert(Pattern &&
"Missing instantiated-from-template information");
4303 if (!
Record->getDefinition()) {
4324 Record->getTemplateSpecializationKind() ==
4326 Record->setTemplateSpecializationKind(TSK);
4331 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4335 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4337 assert(MSInfo &&
"No member specialization information?");
4344 PointOfInstantiation, TSK,
Enum,
4350 if (
Enum->getDefinition())
4353 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4354 assert(Pattern &&
"Missing instantiated-from-template information");
4365 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4376 ClassPattern->
lookup(Field->getDeclName());
4409 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4412 return Instantiator.TransformStmt(S);
4420 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
4421 return Instantiator.TransformTemplateArgument(Input, Output);
4428 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4430 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4437 TemplateInstantiator Instantiator(
4438 TemplateInstantiator::ForParameterMappingSubstitution, *
this, BaseLoc,
4439 TemplateArgs, BuildPackExpansionTypes);
4440 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4448 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4451 return Instantiator.TransformExpr(E);
4460 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4462 return Instantiator.TransformAddressOfOperand(E);
4478 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4480 Instantiator.setEvaluateConstraints(
false);
4481 return Instantiator.TransformExpr(E);
4486 bool CXXDirectInit) {
4487 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4489 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4498 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4501 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4511 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4513 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4519 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4521 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4529 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameLoc,
4531 return Instantiator.TransformTemplateName(QualifierLoc, TemplateKWLoc, Name,
4540 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4541 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4542 unsigned i = PV->getFunctionScopeIndex();
4545 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4546 return FD->getCanonicalDecl()->getParamDecl(i);
4552llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4556 Current = Current->Outer) {
4559 const Decl *CheckD = D;
4561 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4562 if (
Found != Current->LocalDecls.end())
4563 return &
Found->second;
4567 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4574 if (!Current->CombineWithOuterScope)
4581llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4594 if (RD->isLocalClass())
4611 assert(
isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4617 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4618 if (Stored.isNull()) {
4622 while (Current->CombineWithOuterScope && Current->Outer) {
4623 Current = Current->Outer;
4624 assert(!Current->LocalDecls.contains(D) &&
4625 "Instantiated local in inner and outer scopes");
4629 }
else if (
DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(Stored)) {
4632 assert(
cast<Decl *>(Stored) == Inst &&
"Already instantiated this local");
4640 Pack->push_back(Inst);
4647 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4648 assert(!Current->LocalDecls.contains(D) &&
4649 "Creating local pack after instantiation of local");
4653 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4656 ArgumentPacks.push_back(Pack);
4661 if (llvm::is_contained(*Pack, D))
4668 unsigned NumExplicitArgs) {
4669 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4670 "Already have a partially-substituted pack");
4671 assert((!PartiallySubstitutedPack
4672 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4673 "Wrong number of arguments in partially-substituted pack");
4674 PartiallySubstitutedPack = Pack;
4675 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4676 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4681 unsigned *NumExplicitArgs)
const {
4683 *ExplicitArgs =
nullptr;
4684 if (NumExplicitArgs)
4685 *NumExplicitArgs = 0;
4688 Current = Current->Outer) {
4689 if (Current->PartiallySubstitutedPack) {
4691 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4692 if (NumExplicitArgs)
4693 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4695 return Current->PartiallySubstitutedPack;
4698 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.
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 static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXRecordDecl * getDefinition() const
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
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
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 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.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial 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.
void ActOnFinishCXXNonNestedClass()
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
void ActOnFinishDelayedMemberInitializers(Decl *Record)
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.
SmallVector< LateInstantiatedAttribute, 1 > LateInstantiatedAttrVec
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 ...
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained).
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)
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
bool RebuildingImmediateInvocation
Whether the AST is currently being rebuilt to correct immediate invocations.
void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
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...
SourceManager & SourceMgr
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
Represents a C++11 static_assert declaration.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Represents the declaration of a struct/union/class/enum.
void setTagKind(TagKind TK)
SourceRange getBraceRange() const
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
void startDefinition()
Starts the definition of this tag declaration.
TagKind getTagKind() const
void setBraceRange(SourceRange R)
SourceLocation getNameLoc() const
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
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.
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.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
void disableLateAttributeInstantiation()
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
void setEvaluateConstraints(bool B)
LocalInstantiationScope * getStartingScope() const
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
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
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)
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 ('>').
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
ArrayRef< TemplateArgumentLoc > arguments() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.
ExceptionSpecInfo ExceptionSpec
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
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.
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
bool ExpandUnderForgetSubstitions
UnsignedOrNone NumExpansions