36#include "llvm/ADT/SmallVectorExtras.h"
37#include "llvm/ADT/StringExtras.h"
38#include "llvm/Support/ErrorHandling.h"
39#include "llvm/Support/SaveAndRestore.h"
40#include "llvm/Support/TimeProfiler.h"
53 const Decl *NextDecl =
nullptr;
55 bool ClearRelativeToPrimary =
true;
56 static Response Done() {
61 static Response ChangeDecl(
const Decl *ND) {
66 static Response ChangeDecl(
const DeclContext *Ctx) {
72 static Response UseNextDecl(
const Decl *CurDecl) {
76 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
77 Response R = Response::UseNextDecl(CurDecl);
78 R.ClearRelativeToPrimary =
false;
87getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
89 return LambdaCallOperator;
91 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
93 FTD && FTD->getInstantiatedFromMemberTemplate()) {
95 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
102 ->getInstantiatedFromMemberFunction())
103 LambdaCallOperator = Prev;
107 return LambdaCallOperator;
110struct EnclosingTypeAliasTemplateDetails {
120EnclosingTypeAliasTemplateDetails
121getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
124 TypeAliasTemplateInstantiation)
126 EnclosingTypeAliasTemplateDetails Result;
128 *
Next = TATD->getInstantiatedFromMemberTemplate();
132 CSC.template_arguments(),
135 Result.PrimaryTypeAliasDecl =
Next;
136 Next =
Next->getInstantiatedFromMemberTemplate();
149bool isLambdaEnclosedByTypeAliasDecl(
153 Visitor(
const FunctionDecl *CallOperator) : CallOperator(CallOperator) {}
154 bool VisitLambdaExpr(
LambdaExpr *LE)
override {
157 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
166 return !Visitor(getPrimaryTemplateOfGenericLambda(LambdaCallOperator))
167 .TraverseType(Underlying);
174 bool SkipForSpecialization) {
178 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
183 return Response::Done();
188 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
191 dyn_cast<VarTemplatePartialSpecializationDecl *>(Specialized)) {
192 if (!SkipForSpecialization)
193 Result.addOuterTemplateArguments(
196 if (Partial->isMemberSpecialization())
197 return Response::Done();
200 if (!SkipForSpecialization)
201 Result.addOuterTemplateArguments(
205 return Response::Done();
207 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
219 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
220 Result.addOuterTemplateArguments(std::nullopt);
221 return Response::Done();
224Response HandlePartialClassTemplateSpec(
227 if (!SkipForSpecialization)
229 return Response::Done();
236 bool SkipForSpecialization) {
241 return Response::Done();
243 if (!SkipForSpecialization)
244 Result.addOuterTemplateArguments(
253 return Response::Done();
259 if (
auto *InstFromPartialTempl =
262 return Response::ChangeDecl(
263 InstFromPartialTempl->getLexicalDeclContext());
265 return Response::UseNextDecl(ClassTemplSpec);
271 bool ForConstraintInstantiation,
272 bool ForDefaultArgumentSubstitution) {
274 if (!RelativeToPrimary &&
275 Function->getTemplateSpecializationKindForInstantiation() ==
277 return Response::Done();
279 if (!RelativeToPrimary &&
284 return Response::UseNextDecl(Function);
286 Function->getTemplateSpecializationArgs()) {
288 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
289 TemplateArgs->asArray(),
292 if (RelativeToPrimary &&
293 (Function->getTemplateSpecializationKind() ==
295 (Function->getFriendObjectKind() &&
296 !Function->getPrimaryTemplate()->getFriendObjectKind())))
297 return Response::UseNextDecl(Function);
301 assert(Function->getPrimaryTemplate() &&
"No function template?");
302 if (!ForDefaultArgumentSubstitution &&
303 Function->getPrimaryTemplate()->isMemberSpecialization())
304 return Response::Done();
307 if (!ForConstraintInstantiation &&
309 return Response::Done();
311 }
else if (
auto *
Template = Function->getDescribedFunctionTemplate()) {
313 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
314 "Outer template not instantiated?");
315 if (ForConstraintInstantiation) {
323 Result.addOuterTemplateArguments(
Template, Inst.template_arguments(),
334 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
335 Function->getNonTransparentDeclContext()->isFileContext() &&
337 return Response::ChangeDecl(Function->getLexicalDeclContext());
340 if (ForConstraintInstantiation && Function->getFriendObjectKind())
341 return Response::ChangeDecl(Function->getLexicalDeclContext());
342 return Response::UseNextDecl(Function);
345Response HandleFunctionTemplateDecl(
Sema &SemaRef,
349 Result.addOuterTemplateArguments(
362 Ty = std::exchange(NextTy,
nullptr)) {
365 NextTy = P.getAsType();
366 const auto *TSTy = dyn_cast<TemplateSpecializationType>(Ty);
388 if (TSTy->isCurrentInstantiation()) {
389 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
391 Arguments = CTD->getInjectedTemplateArgs(SemaRef.
Context);
393 dyn_cast<ClassTemplateSpecializationDecl>(RD))
394 Arguments =
Specialization->getTemplateInstantiationArgs().asArray();
396 Result.addOuterTemplateArguments(
397 TSTy->getTemplateName().getAsTemplateDecl(), Arguments,
408 bool ForConstraintInstantiation) {
411 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
412 "Outer template not instantiated?");
413 if (ClassTemplate->isMemberSpecialization())
414 return Response::Done();
415 if (ForConstraintInstantiation)
416 Result.addOuterTemplateArguments(
418 ClassTemplate->getInjectedTemplateArgs(SemaRef.
Context),
425 return Response::Done();
430 if (ForConstraintInstantiation && IsFriend &&
439 return Response::ChangeDecl(LCD);
443 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef);
444 ForConstraintInstantiation &&
TypeAlias) {
447 Result.addOuterTemplateArguments(
TypeAlias.Template,
463 return Response::ChangeDecl(
TypeAlias.Template->getDeclContext());
468 return Response::UseNextDecl(Rec);
471Response HandleImplicitConceptSpecializationDecl(
474 Result.addOuterTemplateArguments(
478 return Response::UseNextDecl(CSD);
481Response HandleGenericDeclContext(
const Decl *CurDecl) {
482 return Response::UseNextDecl(CurDecl);
490 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
491 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
492 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
497 const Decl *CurDecl = ND;
500 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
510 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
511 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
513 : Response::UseNextDecl(CurDecl).NextDecl;
519 if (
const auto *VarTemplSpec =
520 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
521 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
522 }
else if (
const auto *PartialClassTemplSpec =
523 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
524 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
525 SkipForSpecialization);
526 }
else if (
const auto *ClassTemplSpec =
527 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
528 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
529 SkipForSpecialization);
530 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
531 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
532 ForConstraintInstantiation,
533 ForDefaultArgumentSubstitution);
534 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
536 ForConstraintInstantiation);
537 }
else if (
const auto *CSD =
538 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
539 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
540 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
541 R = HandleFunctionTemplateDecl(*
this, FTD,
Result);
542 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
543 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
545 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
546 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
547 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
550 R = HandleGenericDeclContext(CurDecl);
555 if (R.ClearRelativeToPrimary)
556 RelativeToPrimary =
false;
558 CurDecl = R.NextDecl;
603 llvm_unreachable(
"Invalid SynthesisKind!");
614 if (
SemaRef.Diags.hasFatalErrorOccurred() &&
615 SemaRef.hasUncompilableErrorOccurred()) {
628 Inst.InConstraintSubstitution =
630 Inst.InParameterMappingSubstitution =
632 if (!
SemaRef.CodeSynthesisContexts.empty()) {
633 Inst.InConstraintSubstitution |=
634 SemaRef.CodeSynthesisContexts.back().InConstraintSubstitution;
635 Inst.InParameterMappingSubstitution |=
636 SemaRef.CodeSynthesisContexts.back().InParameterMappingSubstitution;
647 PointOfInstantiation, InstantiationRange, Entity) {}
654 PointOfInstantiation, InstantiationRange, Entity) {}
693 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
702 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
711 PointOfInstantiation, InstantiationRange, Param,
nullptr,
721 PointOfInstantiation, InstantiationRange, Param,
Template,
731 PointOfInstantiation, InstantiationRange, Param,
Template,
740 PointOfInstantiation, InstantiationRange, Entity,
749 PointOfInstantiation, InstantiationRange, Param,
Template,
757 PointOfInstantiation, InstantiationRange,
nullptr,
766 PointOfInstantiation, InstantiationRange,
nullptr,
775 PointOfInstantiation, InstantiationRange,
nullptr,
783 PointOfInstantiation, InstantiationRange,
nullptr,
808 PointOfInstantiation, InstantiationRange,
Template) {}
815 PointOfInstantiation, InstantiationRange, Entity) {}
821 ArgLoc, InstantiationRange, PArg) {}
827 assert(
SemaRef.NonInstantiationEntries <=
828 SemaRef.CodeSynthesisContexts.size());
829 if ((
SemaRef.CodeSynthesisContexts.size() -
830 SemaRef.NonInstantiationEntries) >
831 SemaRef.getLangOpts().InstantiationDepth) {
833 diag::err_template_recursion_depth_exceeded)
836 diag::note_template_recursion_depth)
837 <<
SemaRef.getLangOpts().InstantiationDepth;
852 if (!Active.isInstantiationRecord()) {
860 "forgot to remove a lookup module for a template instantiation");
879 SemaRef.popCodeSynthesisContext();
887 llvm::raw_string_ostream
OS(
Result);
888 llvm::ListSeparator Comma;
889 for (
const Expr *Arg : Args) {
891 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
901 llvm::raw_string_ostream
OS(
Result);
902 llvm::ListSeparator Comma;
904 for (
const Expr *Arg : Args) {
906 const char *ValueCategory =
908 : (EVK ==
VK_XValue ?
"xvalue" :
"prvalue"));
909 OS << Comma << ValueCategory <<
" of type '";
920 unsigned Limit =
Diags.getTemplateBacktraceLimit();
922 SkipStart = Limit / 2 + Limit % 2;
927 unsigned InstantiationIdx = 0;
932 ++Active, ++InstantiationIdx) {
934 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
935 if (InstantiationIdx == SkipStart) {
937 DiagFunc(Active->PointOfInstantiation,
938 PDiag(diag::note_instantiation_contexts_suppressed)
944 switch (Active->Kind) {
946 Decl *D = Active->Entity;
948 unsigned DiagID = diag::note_template_member_class_here;
950 DiagID = diag::note_template_class_instantiation_here;
951 DiagFunc(Active->PointOfInstantiation,
952 PDiag(DiagID) <<
Record << Active->InstantiationRange);
956 DiagID = diag::note_function_template_spec_here;
958 DiagID = diag::note_template_member_function_here;
959 DiagFunc(Active->PointOfInstantiation,
961 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
962 DiagFunc(Active->PointOfInstantiation,
963 PDiag(VD->isStaticDataMember()
964 ? diag::note_template_static_data_member_def_here
965 : diag::note_template_variable_def_here)
966 << VD << Active->InstantiationRange);
967 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
968 DiagFunc(Active->PointOfInstantiation,
969 PDiag(diag::note_template_enum_def_here)
970 << ED << Active->InstantiationRange);
971 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
972 DiagFunc(Active->PointOfInstantiation,
973 PDiag(diag::note_template_nsdmi_here)
974 << FD << Active->InstantiationRange);
976 DiagFunc(Active->PointOfInstantiation,
977 PDiag(diag::note_template_class_instantiation_here)
978 << CTD << Active->InstantiationRange);
986 llvm::raw_svector_ostream
OS(TemplateArgsStr);
988 printTemplateArgumentList(
OS, Active->template_arguments(),
990 DiagFunc(Active->PointOfInstantiation,
991 PDiag(diag::note_default_arg_instantiation_here)
992 <<
OS.str() << Active->InstantiationRange);
998 DiagFunc(Active->PointOfInstantiation,
999 PDiag(diag::note_explicit_template_arg_substitution_here)
1003 Active->NumTemplateArgs)
1004 << Active->InstantiationRange);
1010 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1012 Active->PointOfInstantiation,
1013 PDiag(diag::note_function_template_deduction_instantiation_here)
1016 FnTmpl->getTemplateParameters(), Active->TemplateArgs,
1017 Active->NumTemplateArgs)
1018 << Active->InstantiationRange);
1022 bool IsTemplate =
false;
1024 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1026 Params = D->getTemplateParameters();
1027 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1029 Params = D->getTemplateParameters();
1030 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1032 Params = D->getTemplateParameters();
1034 llvm_unreachable(
"unexpected template kind");
1037 DiagFunc(Active->PointOfInstantiation,
1038 PDiag(diag::note_deduced_template_arg_substitution_here)
1041 Active->TemplateArgs,
1042 Active->NumTemplateArgs)
1043 << Active->InstantiationRange);
1053 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1055 printTemplateArgumentList(
OS, Active->template_arguments(),
1057 DiagFunc(Active->PointOfInstantiation,
1058 PDiag(diag::note_default_function_arg_instantiation_here)
1059 <<
OS.str() << Active->InstantiationRange);
1067 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1071 TemplateParams =
Template->getTemplateParameters();
1075 ->getTemplateParameters();
1076 DiagFunc(Active->PointOfInstantiation,
1077 PDiag(diag::note_prior_template_arg_substitution)
1080 Active->TemplateArgs,
1081 Active->NumTemplateArgs)
1082 << Active->InstantiationRange);
1089 TemplateParams =
Template->getTemplateParameters();
1093 ->getTemplateParameters();
1095 DiagFunc(Active->PointOfInstantiation,
1096 PDiag(diag::note_template_default_arg_checking)
1098 Active->TemplateArgs,
1099 Active->NumTemplateArgs)
1100 << Active->InstantiationRange);
1105 DiagFunc(Active->PointOfInstantiation,
1106 PDiag(diag::note_evaluating_exception_spec_here)
1111 DiagFunc(Active->PointOfInstantiation,
1112 PDiag(diag::note_template_exception_spec_instantiation_here)
1114 << Active->InstantiationRange);
1118 DiagFunc(Active->PointOfInstantiation,
1119 PDiag(diag::note_template_requirement_instantiation_here)
1120 << Active->InstantiationRange);
1123 DiagFunc(Active->PointOfInstantiation,
1124 PDiag(diag::note_template_requirement_params_instantiation_here)
1125 << Active->InstantiationRange);
1129 DiagFunc(Active->PointOfInstantiation,
1130 PDiag(diag::note_nested_requirement_here)
1131 << Active->InstantiationRange);
1135 DiagFunc(Active->PointOfInstantiation,
1136 PDiag(diag::note_in_declaration_of_implicit_special_member)
1138 << Active->SpecialMember);
1143 Active->Entity->getLocation(),
1144 PDiag(diag::note_in_declaration_of_implicit_equality_comparison));
1150 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1155 FD ? FD->getDefaultedFunctionKind()
1159 DiagFunc(Active->PointOfInstantiation,
1160 PDiag(diag::note_member_synthesized_at)
1162 <<
Context.getCanonicalTagType(MD->getParent()));
1164 QualType RecordType = FD->getParamDecl(0)
1166 .getNonReferenceType()
1167 .getUnqualifiedType();
1168 DiagFunc(Active->PointOfInstantiation,
1169 PDiag(diag::note_comparison_synthesized_at)
1176 DiagFunc(Active->Entity->getLocation(),
1177 PDiag(diag::note_rewriting_operator_as_spaceship));
1181 DiagFunc(Active->PointOfInstantiation,
1182 PDiag(diag::note_in_binding_decl_init)
1187 DiagFunc(Active->PointOfInstantiation,
1188 PDiag(diag::note_due_to_dllexported_class)
1194 DiagFunc(Active->PointOfInstantiation,
1195 PDiag(diag::note_building_builtin_dump_struct_call)
1198 Active->NumCallArgs)));
1205 DiagFunc(Active->PointOfInstantiation,
1206 PDiag(diag::note_lambda_substitution_here));
1209 unsigned DiagID = 0;
1210 if (!Active->Entity) {
1211 DiagFunc(Active->PointOfInstantiation,
1212 PDiag(diag::note_nested_requirement_here)
1213 << Active->InstantiationRange);
1217 DiagID = diag::note_concept_specialization_here;
1219 DiagID = diag::note_checking_constraints_for_template_id_here;
1221 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1223 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1226 DiagID = diag::note_checking_constraints_for_function_here;
1229 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1232 printTemplateArgumentList(
OS, Active->template_arguments(),
1235 DiagFunc(Active->PointOfInstantiation,
1236 PDiag(DiagID) <<
OS.str() << Active->InstantiationRange);
1240 DiagFunc(Active->PointOfInstantiation,
1241 PDiag(diag::note_constraint_substitution_here)
1242 << Active->InstantiationRange);
1245 DiagFunc(Active->PointOfInstantiation,
1246 PDiag(diag::note_parameter_mapping_substitution_here)
1247 << Active->InstantiationRange);
1250 DiagFunc(Active->PointOfInstantiation,
1251 PDiag(diag::note_building_deduction_guide_here));
1258 if (Active->NumTemplateArgs == 0)
1260 DiagFunc(Active->PointOfInstantiation,
1261 PDiag(diag::note_template_type_alias_instantiation_here)
1263 << Active->InstantiationRange);
1266 DiagFunc(Active->PointOfInstantiation,
1267 PDiag(diag::note_template_arg_template_params_mismatch));
1270 DiagFunc(ParamLoc,
PDiag(diag::note_template_prev_declaration)
1272 << Active->InstantiationRange);
1275 const auto *SKEPAttr =
1276 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1277 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1278 assert(!SKEPAttr->isInvalidAttr() &&
1279 "sycl_kernel_entry_point attribute is invalid");
1280 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1281 DiagFunc(SKEPAttr->getLocation(),
1282 PDiag(diag::note_sycl_kernel_launch_lookup_here)
1283 << SKEPAttr->getKernelName());
1287 const auto *SKEPAttr =
1288 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1289 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1290 assert(!SKEPAttr->isInvalidAttr() &&
1291 "sycl_kernel_entry_point attribute is invalid");
1292 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1293 DiagFunc(SKEPAttr->getLocation(),
1294 PDiag(diag::note_sycl_kernel_launch_overload_resolution_here)
1295 << SKEPAttr->getKernelName()
1298 Active->NumCallArgs)));
1302 Diags.Report(Active->PointOfInstantiation,
1303 diag::note_expansion_stmt_instantiation_here);
1313 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1318 bool EvaluateConstraints =
true;
1319 bool EvaluateLambdaConstraint =
false;
1322 bool IsIncomplete =
false;
1324 bool BailOutOnIncomplete;
1326 std::optional<llvm::FoldingSetNodeID> TemplateArgsHashValue;
1331 bool maybeInstantiateFunctionParameterToScope(
ParmVarDecl *OldParm);
1336 TemplateInstantiator(
Sema &SemaRef,
1339 bool BailOutOnIncomplete =
false)
1340 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1341 Entity(Entity), BailOutOnIncomplete(BailOutOnIncomplete) {
1344 "Cannot perform an instantiation without some context on the "
1345 "instantiation stack");
1348 void setEvaluateConstraints(
bool B) {
1349 EvaluateConstraints = B;
1351 bool getEvaluateConstraints() {
1352 return EvaluateConstraints;
1355 inline static struct ForParameterMappingSubstitution_t {
1356 } ForParameterMappingSubstitution;
1358 inline static struct ForConstraintSubstitution_t {
1359 } ForConstraintSubstitution;
1361 TemplateInstantiator(ForParameterMappingSubstitution_t, Sema &SemaRef,
1363 const MultiLevelTemplateArgumentList &TemplateArgs)
1364 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1365 EvaluateLambdaConstraint(
true), BailOutOnIncomplete(
false) {
1368 auto &
V = TemplateArgsHashValue.emplace();
1370 for (
auto &Arg :
Level.Args)
1374 TemplateInstantiator(ForConstraintSubstitution_t, Sema &SemaRef,
1375 const MultiLevelTemplateArgumentList &TemplateArgs,
1376 SourceLocation Loc, DeclarationName Entity,
1377 bool BailOutOnIncomplete =
false)
1378 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1379 EvaluateLambdaConstraint(
true), BailOutOnIncomplete(
false) {}
1386 bool AlreadyTransformed(QualType
T);
1389 SourceLocation getBaseLocation() {
return Loc; }
1392 DeclarationName getBaseEntity() {
return Entity; }
1395 bool getIsIncomplete()
const {
return IsIncomplete; }
1399 void setBase(SourceLocation Loc, DeclarationName Entity) {
1401 this->Entity = Entity;
1404 unsigned TransformTemplateDepth(
unsigned Depth) {
1405 return TemplateArgs.getNewDepth(Depth);
1408 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1409 SourceRange PatternRange,
1410 ArrayRef<UnexpandedParameterPack> Unexpanded,
1411 bool FailOnPackProducingTemplates,
1412 bool &ShouldExpand,
bool &RetainExpansion,
1418 NamedDecl *VD = ParmPack.first.dyn_cast<NamedDecl *>();
1419 if (
auto *PVD = dyn_cast_if_present<ParmVarDecl>(VD);
1420 PVD && maybeInstantiateFunctionParameterToScope(PVD))
1425 return getSema().CheckParameterPacksForExpansion(
1426 EllipsisLoc, PatternRange, Unexpanded, TemplateArgs,
1427 FailOnPackProducingTemplates, ShouldExpand, RetainExpansion,
1431 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1435 TemplateArgument ForgetPartiallySubstitutedPack() {
1439 MultiLevelTemplateArgumentList &TemplateArgs =
1440 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1441 unsigned Depth, Index;
1444 Result = TemplateArgs(Depth, Index);
1445 TemplateArgs.
setArgument(Depth, Index, TemplateArgument());
1447 IsIncomplete =
true;
1448 if (BailOutOnIncomplete)
1449 return TemplateArgument();
1456 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1462 MultiLevelTemplateArgumentList &TemplateArgs =
1463 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1464 unsigned Depth, Index;
1470 MultiLevelTemplateArgumentList ForgetSubstitution() {
1471 MultiLevelTemplateArgumentList
New;
1474 MultiLevelTemplateArgumentList Old =
1475 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1476 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1481 void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
1482 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1487 getTemplateArgumentPackPatternForRewrite(
const TemplateArgument &TA) {
1493 "unexpected pack arguments in template rewrite");
1502 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1504 void transformAttrs(Decl *Old, Decl *
New) {
1508 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1510 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1512 for (
auto *
New : NewDecls)
1518 assert(NewDecls.size() == 1 &&
1519 "should only have multiple expansions for a pack");
1525 auto *NewMD = dyn_cast<CXXMethodDecl>(
New);
1527 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1528 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1529 NewTD->setInstantiatedFromMemberTemplate(
1530 OldMD->getDescribedFunctionTemplate());
1532 NewMD->setInstantiationOfMemberFunction(OldMD,
1540 if (
auto *DC = dyn_cast<DeclContext>(Old);
1541 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1547 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1551 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1553 bool TransformExceptionSpec(SourceLocation Loc,
1554 FunctionProtoType::ExceptionSpecInfo &ESI,
1555 SmallVectorImpl<QualType> &Exceptions,
1560 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1561 TypeSourceInfo *Declarator,
1562 SourceLocation StartLoc,
1563 SourceLocation NameLoc,
1564 IdentifierInfo *Name);
1568 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1569 TypeSourceInfo *TSInfo, QualType
T);
1572 TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc,
1574 SourceLocation NameLoc,
1575 QualType ObjectType = QualType(),
1576 NamedDecl *FirstQualifierInScope =
nullptr,
1577 bool AllowInjectedClassName =
false);
1579 const AnnotateAttr *TransformAnnotateAttr(
const AnnotateAttr *AA);
1580 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1581 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1582 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1584 const NoInlineAttr *A);
1585 const AlwaysInlineAttr *
1586 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1587 const AlwaysInlineAttr *A);
1588 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1589 const OpenACCRoutineDeclAttr *
1590 TransformOpenACCRoutineDeclAttr(
const OpenACCRoutineDeclAttr *A);
1591 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1592 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1593 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1595 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1596 NonTypeTemplateParmDecl *D);
1599 ExprResult RebuildVarDeclRefExpr(ValueDecl *PD, SourceLocation Loc);
1602 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, ValueDecl *PD);
1607 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1609 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1610 FunctionProtoTypeLoc TL) {
1612 return inherited::TransformFunctionProtoType(TLB, TL);
1615 QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL) {
1616 auto Type = inherited::TransformTagType(TLB, TL);
1622 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TL.
getTypePtr());
1625 Type = inherited::TransformType(
1626 ICNT->getDecl()->getCanonicalTemplateSpecializationType(
1636 bool TransformTemplateArgument(
const TemplateArgumentLoc &Input,
1637 TemplateArgumentLoc &Output,
1638 bool Uneval =
false) {
1639 const TemplateArgument &Arg = Input.
getArgument();
1641 Cache && TemplateArgsHashValue) {
1642 llvm::FoldingSetNodeID
ID = *TemplateArgsHashValue;
1652 if (
auto Iter =
Cache->find(ID); Iter !=
Cache->end()) {
1653 Output = Iter->second;
1656 bool Ret = inherited::TransformTemplateArgument(Input, Output, Uneval);
1663 std::vector<TemplateArgument> TArgs;
1671 pack, QualType(), SourceLocation{});
1672 TemplateArgumentLoc Output;
1673 if (TransformTemplateArgument(Input, Output, Uneval))
1678 TemplateArgument(llvm::ArrayRef(TArgs).copy(SemaRef.
Context)),
1679 QualType(), SourceLocation{});
1685 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1690 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
1691 TemplateSpecializationTypeLoc TL) {
1693 if (!getSema().ArgPackSubstIndex || !
T->
isSugared() ||
1703 QualType
R = TransformType(
T->
desugar());
1709 ArrayRef<TemplateArgument> PackArgs) {
1720 return std::nullopt;
1722 return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1725 template<
typename Fn>
1726 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1727 FunctionProtoTypeLoc TL,
1728 CXXRecordDecl *ThisContext,
1729 Qualifiers ThisTypeQuals,
1730 Fn TransformExceptionSpec);
1732 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1733 int indexAdjustment,
1735 bool ExpectParameterPack);
1737 using inherited::TransformTemplateTypeParmType;
1740 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1741 TemplateTypeParmTypeLoc TL,
1742 bool SuppressObjCLifetime);
1744 QualType BuildSubstTemplateTypeParmType(
1745 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
1747 TemplateArgument Arg, SourceLocation NameLoc);
1752 using inherited::TransformSubstTemplateTypeParmPackType;
1754 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1755 SubstTemplateTypeParmPackTypeLoc TL,
1756 bool SuppressObjCLifetime);
1758 TransformSubstBuiltinTemplatePackType(TypeLocBuilder &TLB,
1759 SubstBuiltinTemplatePackTypeLoc TL);
1762 ComputeLambdaDependency(LambdaScopeInfo *LSI) {
1764 TemplateInstArgsHelpers::getEnclosingTypeAliasTemplateDecl(
1766 TypeAlias && TemplateInstArgsHelpers::isLambdaEnclosedByTypeAliasDecl(
1768 unsigned TypeAliasDeclDepth =
TypeAlias.Template->getTemplateDepth();
1770 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1771 for (
const TemplateArgument &TA :
TypeAlias.AssociatedTemplateArguments)
1773 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1775 if (
auto *CD = dyn_cast_if_present<ImplicitConceptSpecializationDecl>(
1777 if (llvm::any_of(CD->getTemplateArguments(),
1778 [](
const auto &TA) { return TA.isDependent(); }))
1779 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1781 return inherited::ComputeLambdaDependency(LSI);
1784 ExprResult TransformLambdaConstraint(Expr *AC) {
1785 if (AC && EvaluateLambdaConstraint)
1786 return TransformExpr(
const_cast<Expr *
>(AC));
1796 LocalInstantiationScope Scope(SemaRef,
true,
1798 llvm::SaveAndRestore RAII(EvaluateConstraints, EvaluateLambdaConstraint);
1800 return inherited::TransformLambdaExpr(E);
1803 ExprResult TransformBlockExpr(BlockExpr *E) {
1804 LocalInstantiationScope Scope(SemaRef,
true,
1806 return inherited::TransformBlockExpr(E);
1809 ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1810 LambdaScopeInfo *LSI) {
1813 assert(PVD &&
"null in a parameter list");
1814 if (!PVD->hasDefaultArg())
1816 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1818 SourceLocation EqualLoc = UninstExpr->
getBeginLoc();
1827 PVD->setDefaultArg(ErrorResult.
get());
1830 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1843 llvm::SaveAndRestore _(EvaluateConstraints,
true);
1844 return inherited::TransformLambdaBody(E, Body);
1848 LocalInstantiationScope Scope(SemaRef,
true);
1849 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1852 assert(TransReq.
get() != E &&
1853 "Do not change value of isSatisfied for the existing expression. "
1854 "Create a new expression instead.");
1856 Sema::SFINAETrap Trap(SemaRef);
1861 if (Trap.hasErrorOccurred())
1867 bool TransformRequiresExprRequirements(
1868 ArrayRef<concepts::Requirement *> Reqs,
1869 SmallVectorImpl<concepts::Requirement *> &Transformed) {
1870 bool SatisfactionDetermined =
false;
1871 for (concepts::Requirement *Req : Reqs) {
1872 concepts::Requirement *TransReq =
nullptr;
1873 if (!SatisfactionDetermined) {
1874 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1875 TransReq = TransformTypeRequirement(TypeReq);
1876 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1877 TransReq = TransformExprRequirement(ExprReq);
1879 TransReq = TransformNestedRequirement(
1889 SatisfactionDetermined =
true;
1892 Transformed.push_back(TransReq);
1897 TemplateParameterList *TransformTemplateParameterList(
1898 TemplateParameterList *OrigTPL) {
1899 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1902 TemplateDeclInstantiator DeclInstantiator(getSema(),
1905 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1906 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1909 concepts::TypeRequirement *
1910 TransformTypeRequirement(concepts::TypeRequirement *Req);
1911 concepts::ExprRequirement *
1912 TransformExprRequirement(concepts::ExprRequirement *Req);
1913 concepts::NestedRequirement *
1914 TransformNestedRequirement(concepts::NestedRequirement *Req);
1916 SourceLocation KWLoc, SourceLocation RBraceLoc,
const RequiresExpr *RE,
1917 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params,
1918 SmallVectorImpl<QualType> &PTypes,
1919 SmallVectorImpl<ParmVarDecl *> &TransParams,
1920 Sema::ExtParameterInfoBuilder &PInfos);
1922 ExprResult TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1924 if (
Ret.isInvalid())
1926 QualType
T =
Ret.get()->getType();
1930 if (DestDecl && DestDecl->isEffectivelyFinal())
1931 getSema().MarkVTableUsed(
Ret.get()->getExprLoc(), DestDecl);
1937bool TemplateInstantiator::AlreadyTransformed(QualType
T) {
1945 getSema().MarkDeclarationsReferencedInType(Loc,
T);
1949Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1953 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1960 TTP->getPosition())) {
1961 IsIncomplete =
true;
1962 return BailOutOnIncomplete ?
nullptr : D;
1965 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1967 if (TTP->isParameterPack()) {
1969 "Missing argument pack");
1970 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
1975 "Wrong kind of template template argument");
1976 return Template.getAsTemplateDecl();
1983 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(D);
1984 PVD &&
SemaRef.CurrentInstantiationScope &&
1985 (
SemaRef.inConstraintSubstitution() ||
1986 SemaRef.inParameterMappingSubstitution()) &&
1987 maybeInstantiateFunctionParameterToScope(PVD))
1991 assert(
SemaRef.CurrentInstantiationScope);
1993 *
SemaRef.CurrentInstantiationScope->findInstantiationOf(D));
1999bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
2000 ParmVarDecl *OldParm) {
2001 if (
SemaRef.CurrentInstantiationScope->getInstantiationOfIfExists(OldParm))
2005 return !TransformFunctionTypeParam(OldParm, 0,
2009 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2013 PackExpansionTypeLoc ExpansionTL = TL.
castAs<PackExpansionTypeLoc>();
2015 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
2016 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
2018 bool ShouldExpand =
false;
2019 bool RetainExpansion =
false;
2021 ExpansionTL.
getTypePtr()->getNumExpansions();
2024 Pattern.getSourceRange(), Unexpanded,
2026 ShouldExpand, RetainExpansion, NumExpansions))
2029 assert(ShouldExpand && !RetainExpansion &&
2030 "Shouldn't preserve pack expansion when evaluating constraints");
2031 ExpandingFunctionParameterPack(OldParm);
2032 for (
unsigned I = 0; I != *NumExpansions; ++I) {
2033 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
2034 if (!TransformFunctionTypeParam(OldParm, 0,
2042Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
2043 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
2047 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2051bool TemplateInstantiator::TransformExceptionSpec(
2052 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
2053 SmallVectorImpl<QualType> &Exceptions,
bool &Changed) {
2058 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
2062TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
2063 SourceLocation Loc) {
2066 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
2067 const TemplateTypeParmType *TTP
2072 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
2074 if (TTP->isParameterPack()) {
2076 "Missing argument pack");
2081 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2086 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2088 if (
const TagType *Tag =
T->
getAs<TagType>())
2089 return Tag->getDecl();
2092 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
2097 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2101TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
2102 TypeSourceInfo *Declarator,
2103 SourceLocation StartLoc,
2104 SourceLocation NameLoc,
2105 IdentifierInfo *Name) {
2106 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
2107 StartLoc, NameLoc, Name);
2109 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2113VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
2114 TypeSourceInfo *TSInfo,
2116 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
2118 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2122TemplateName TemplateInstantiator::TransformTemplateName(
2123 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
2124 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
2125 NamedDecl *FirstQualifierInScope,
bool AllowInjectedClassName) {
2127 assert(!QualifierLoc &&
"Unexpected qualifier");
2130 TTP && TTP->getDepth() < TemplateArgs.
getNumLevels()) {
2136 TTP->getPosition())) {
2137 IsIncomplete =
true;
2141 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
2146 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2148 "unexpected nontype template argument kind in template rewrite");
2152 auto [AssociatedDecl, Final] =
2155 if (TTP->isParameterPack()) {
2157 "Missing argument pack");
2163 return getSema().Context.getSubstTemplateTemplateParmPack(
2164 Arg, AssociatedDecl, TTP->getIndex(), Final);
2168 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2172 assert(!
Template.isNull() &&
"Null template template argument");
2173 return getSema().Context.getSubstTemplateTemplateParm(
2178 if (SubstTemplateTemplateParmPackStorage *SubstPack
2183 TemplateArgument Pack = SubstPack->getArgumentPack();
2185 SemaRef.getPackSubstitutedTemplateArgument(Pack).getAsTemplate();
2186 return getSema().Context.getSubstTemplateTemplateParm(
2187 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2188 SemaRef.getPackIndex(Pack), SubstPack->getFinal());
2191 return inherited::TransformTemplateName(
2192 QualifierLoc, TemplateKWLoc, Name, NameLoc, ObjectType,
2193 FirstQualifierInScope, AllowInjectedClassName);
2197TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
2205TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
2206 NonTypeTemplateParmDecl *NTTP) {
2216 IsIncomplete =
true;
2217 return BailOutOnIncomplete ?
ExprError() : E;
2225 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2227 "unexpected nontype template argument kind in template rewrite");
2240 assert(!ParamType.
isNull() &&
"Shouldn't substitute to an invalid type");
2242 auto [AssociatedDecl, Final] =
2262 return new (
SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
2267 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2269 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
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 ExprResult TransformedExprResult = getDerived().TransformExpr(LH->getValue());
2306 if (!TransformedExprResult.
isUsable() ||
2307 TransformedExprResult.
get() == LH->getValue())
2309 Expr *TransformedExpr = TransformedExprResult.
get();
2313 LH->getSemanticSpelling() ==
2314 LoopHintAttr::Pragma_unroll))
2317 LoopHintAttr::OptionType Option = LH->getOption();
2318 LoopHintAttr::LoopHintState State = LH->getState();
2325 if (Option == LoopHintAttr::UnrollCount &&
2327 llvm::APSInt ValueAPS =
2331 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2332 Option = LoopHintAttr::Unroll;
2333 State = LoopHintAttr::Disable;
2339 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2340 TransformedExpr, *LH);
2342const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2343 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2349const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2350 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2357const CodeAlignAttr *
2358TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2359 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2360 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2362const OpenACCRoutineDeclAttr *
2363TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
2364 const OpenACCRoutineDeclAttr *A) {
2365 llvm_unreachable(
"RoutineDecl should only be a declaration attribute, as it "
2366 "applies to a Function Decl (and a few places for VarDecl)");
2369ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,
2370 SourceLocation Loc) {
2371 DeclarationNameInfo NameInfo(PD->
getDeclName(), Loc);
2372 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
2376TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
2380 ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), D));
2383 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2386 QualType
T = TransformType(E->
getType());
2392 SmallVector<ValueDecl *, 8> Vars;
2396 ValueDecl *D = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), *I));
2405 getSema().MarkFunctionParmPackReferenced(PackExpr);
2410TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
2413 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found =
2414 getSema().CurrentInstantiationScope->getInstantiationOfIfExists(PD);
2421 Decl *TransformedDecl;
2422 if (DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(*
Found)) {
2426 QualType
T = TransformType(E->
getType());
2431 getSema().MarkFunctionParmPackReferenced(PackExpr);
2435 TransformedDecl = (*Pack)[*getSema().ArgPackSubstIndex];
2446TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
2451 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2453 return TransformTemplateParmRefExpr(E, NTTP);
2460 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2462 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(PD);
2463 PVD &&
SemaRef.CurrentInstantiationScope &&
2464 (
SemaRef.inConstraintSubstitution() ||
2465 SemaRef.inParameterMappingSubstitution()) &&
2466 maybeInstantiateFunctionParameterToScope(PVD))
2469 return TransformFunctionParmPackRefExpr(E, PD);
2472 return inherited::TransformDeclRefExpr(E);
2475ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2476 CXXDefaultArgExpr *E) {
2478 getDescribedFunctionTemplate() &&
2479 "Default arg expressions are never formed in dependent cases.");
2480 return SemaRef.BuildCXXDefaultArgExpr(
2485template<
typename Fn>
2486QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2487 FunctionProtoTypeLoc TL,
2488 CXXRecordDecl *ThisContext,
2489 Qualifiers ThisTypeQuals,
2490 Fn TransformExceptionSpec) {
2498 LocalInstantiationScope *Current = getSema().CurrentInstantiationScope;
2499 std::optional<LocalInstantiationScope> Scope;
2503 return inherited::TransformFunctionProtoType(
2504 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2507ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2508 ParmVarDecl *OldParm,
int indexAdjustment,
UnsignedOrNone NumExpansions,
2509 bool ExpectParameterPack) {
2510 auto NewParm =
SemaRef.SubstParmVarDecl(
2511 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2512 ExpectParameterPack, EvaluateConstraints);
2513 if (NewParm &&
SemaRef.getLangOpts().OpenCL)
2514 SemaRef.deduceOpenCLAddressSpace(NewParm);
2518QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2519 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
2521 TemplateArgument Arg, SourceLocation NameLoc) {
2526 if (SuppressObjCLifetime) {
2528 RQs = Replacement.getQualifiers();
2531 SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2535 QualType
Result = getSema().Context.getSubstTemplateTypeParmType(
2536 Replacement, AssociatedDecl, Index,
PackIndex, Final);
2537 SubstTemplateTypeParmTypeLoc NewTL =
2538 TLB.
push<SubstTemplateTypeParmTypeLoc>(
Result);
2544TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2545 TemplateTypeParmTypeLoc TL,
2546 bool SuppressObjCLifetime) {
2557 IsIncomplete =
true;
2558 if (BailOutOnIncomplete)
2561 TemplateTypeParmTypeLoc NewTL
2562 = TLB.
push<TemplateTypeParmTypeLoc>(TL.
getType());
2567 TemplateArgument Arg = TemplateArgs(
T->getDepth(),
T->getIndex());
2572 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2574 "unexpected nontype template argument kind in template rewrite");
2580 auto [AssociatedDecl, Final] =
2583 if (
T->isParameterPack() ||
2590 (
T->getDecl() &&
T->getDecl()->isTemplateParameterPack())) {
2592 "Missing argument pack");
2598 QualType
Result = getSema().Context.getSubstTemplateTypeParmPackType(
2599 AssociatedDecl,
T->getIndex(), Final, Arg);
2600 SubstTemplateTypeParmPackTypeLoc NewTL
2601 = TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2608 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2612 "Template argument kind mismatch");
2614 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2615 AssociatedDecl,
T->getIndex(),
2623 TemplateTypeParmDecl *NewTTPDecl =
nullptr;
2624 if (TemplateTypeParmDecl *OldTTPDecl =
T->getDecl())
2625 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2627 QualType
Result = getSema().Context.getTemplateTypeParmType(
2631 T->getIndex(),
T->isParameterPack(), NewTTPDecl);
2632 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
2637QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2638 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2639 bool SuppressObjCLifetime) {
2640 const SubstTemplateTypeParmPackType *
T = TL.
getTypePtr();
2642 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2647 if (NewReplaced !=
T->getAssociatedDecl())
2648 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2649 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2650 SubstTemplateTypeParmPackTypeLoc NewTL =
2651 TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2656 TemplateArgument Pack =
T->getArgumentPack();
2657 TemplateArgument Arg =
SemaRef.getPackSubstitutedTemplateArgument(Pack);
2658 return BuildSubstTemplateTypeParmType(
2659 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2663QualType TemplateInstantiator::TransformSubstBuiltinTemplatePackType(
2664 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
2666 return TreeTransform::TransformSubstBuiltinTemplatePackType(TLB, TL);
2667 TemplateArgument
Result =
SemaRef.getPackSubstitutedTemplateArgument(
2671 return Result.getAsType();
2674static concepts::Requirement::SubstitutionDiagnostic *
2684 ErrorLoc = PDA.first;
2689 llvm::raw_svector_ostream
OS(Entity);
2693 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2696concepts::Requirement::SubstitutionDiagnostic *
2699 llvm::raw_svector_ostream
OS(Entity);
2703 C.backupStr(Entity),
2704 Location, StringRef()};
2707ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2720 if (getDerived().TransformFunctionTypeParams(
2721 KWLoc, Params,
nullptr,
nullptr, PTypes,
2722 &TransParams, PInfos, &ErrorIdx) ||
2723 Trap.hasErrorOccurred()) {
2729 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2730 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2732 TransReqs, RBraceLoc);
2738concepts::TypeRequirement *
2739TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2743 if (AlwaysRebuild())
2744 return RebuildTypeRequirement(
2750 Sema::SFINAETrap Trap(
SemaRef, Info);
2751 Sema::InstantiatingTemplate TypeInst(
2754 if (TypeInst.isInvalid())
2756 TypeSourceInfo *TransType = TransformType(Req->
getType());
2757 if (!TransType || Trap.hasErrorOccurred())
2759 [&] (llvm::raw_ostream&
OS) {
2762 return RebuildTypeRequirement(TransType);
2765concepts::ExprRequirement *
2766TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2770 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2777 Sema::SFINAETrap Trap(
SemaRef, Info);
2780 if (ExprInst.isInvalid())
2783 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2785 TransExprRes =
SemaRef.CheckPlaceholderExpr(TransExprRes.
get());
2786 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2791 TransExpr = TransExprRes.
get();
2794 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2796 if (RetReq.isEmpty())
2797 TransRetReq.emplace();
2798 else if (RetReq.isSubstitutionFailure())
2799 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2800 else if (RetReq.isTypeConstraint()) {
2801 TemplateParameterList *OrigTPL =
2802 RetReq.getTypeConstraintTemplateParameterList();
2804 Sema::SFINAETrap Trap(
SemaRef, Info);
2807 if (TPLInst.isInvalid())
2809 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2810 if (!TPL || Trap.hasErrorOccurred())
2812 [&] (llvm::raw_ostream&
OS) {
2813 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2814 ->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2818 TransRetReq.emplace(TPL);
2821 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2822 if (Expr *E = TransExpr.dyn_cast<Expr *>())
2824 std::move(*TransRetReq));
2825 return RebuildExprRequirement(
2830concepts::NestedRequirement *
2831TemplateInstantiator::TransformNestedRequirement(
2832 concepts::NestedRequirement *Req) {
2836 ConstraintSatisfaction Satisfaction;
2838 auto NestedReqWithDiag = [&
C,
this](Expr *E,
2839 ConstraintSatisfaction Satisfaction) {
2841 SmallString<128> Entity;
2842 llvm::raw_svector_ostream
OS(Entity);
2843 E->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2844 return new (
C) concepts::NestedRequirement(
2845 SemaRef.Context,
C.backupStr(Entity), std::move(Satisfaction));
2849 if (AlwaysRebuild())
2857 if (!getEvaluateConstraints()) {
2859 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2863 concepts::NestedRequirement(TransConstraint.
get());
2864 ConstraintSatisfaction Satisfaction;
2865 return new (
SemaRef.Context) concepts::NestedRequirement(
2866 SemaRef.Context, TransConstraint.
get(), Satisfaction);
2870 Expr *NewConstraint;
2874 Sema::InstantiatingTemplate ConstrInst(
2876 Sema::InstantiatingTemplate::ConstraintsCheck(),
2879 if (ConstrInst.isInvalid())
2883 Req, AssociatedConstraint(Constraint), TemplateArgs,
2885 nullptr, &NewConstraint);
2889 return NestedReqWithDiag(Constraint, Satisfaction);
2893 if (!NewConstraint) {
2895 return NestedReqWithDiag(Constraint, Satisfaction);
2897 NewConstraint = Constraint;
2899 return new (
C) concepts::NestedRequirement(
C, NewConstraint, Satisfaction);
2905 bool AllowDeducedTST) {
2906 if (!
T->getType()->isInstantiationDependentType() &&
2907 !
T->getType()->isVariablyModifiedType())
2910 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2911 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2912 : Instantiator.TransformType(
T);
2930 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2944 bool *IsIncompleteSubstitution) {
2947 if (!
T->isInstantiationDependentType() && !
T->isVariablyModifiedType())
2950 TemplateInstantiator Instantiator(
2951 *
this, TemplateArgs, Loc, Entity,
2952 IsIncompleteSubstitution !=
nullptr);
2953 QualType QT = Instantiator.TransformType(
T);
2954 if (IsIncompleteSubstitution && Instantiator.getIsIncomplete())
2955 *IsIncompleteSubstitution =
true;
2960 if (
T->getType()->isInstantiationDependentType() ||
2961 T->getType()->isVariablyModifiedType())
2964 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2984 Qualifiers ThisTypeQuals,
bool EvaluateConstraints) {
2988 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2989 Instantiator.setEvaluateConstraints(EvaluateConstraints);
3005 Result = Instantiator.TransformFunctionProtoType(
3006 TLB, Proto, ThisContext, ThisTypeQuals,
3008 bool &Changed) {
return false; });
3010 Result = Instantiator.TransformType(TLB, TL);
3024 bool Changed =
false;
3025 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
3026 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
3037 ESI, ExceptionStorage, Args))
3046 struct GetContainedInventedTypeParmVisitor :
3047 public TypeVisitor<GetContainedInventedTypeParmVisitor,
3048 TemplateTypeParmDecl *> {
3049 using TypeVisitor<GetContainedInventedTypeParmVisitor,
3055 return Visit(
T.getTypePtr());
3059 const TemplateTypeParmType *
T) {
3060 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
3062 return T->getDecl();
3068 TemplateTypeParmDecl *VisitPointerType(
const PointerType *
T) {
3072 TemplateTypeParmDecl *VisitBlockPointerType(
const BlockPointerType *
T) {
3076 TemplateTypeParmDecl *VisitReferenceType(
const ReferenceType *
T) {
3077 return Visit(
T->getPointeeTypeAsWritten());
3080 TemplateTypeParmDecl *VisitMemberPointerType(
const MemberPointerType *
T) {
3084 TemplateTypeParmDecl *VisitArrayType(
const ArrayType *
T) {
3085 return Visit(
T->getElementType());
3088 TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
3089 const DependentSizedExtVectorType *
T) {
3090 return Visit(
T->getElementType());
3093 TemplateTypeParmDecl *VisitVectorType(
const VectorType *
T) {
3094 return Visit(
T->getElementType());
3097 TemplateTypeParmDecl *VisitFunctionProtoType(
const FunctionProtoType *
T) {
3098 return VisitFunctionType(
T);
3101 TemplateTypeParmDecl *VisitFunctionType(
const FunctionType *
T) {
3105 TemplateTypeParmDecl *VisitParenType(
const ParenType *
T) {
3106 return Visit(
T->getInnerType());
3109 TemplateTypeParmDecl *VisitAttributedType(
const AttributedType *
T) {
3110 return Visit(
T->getModifiedType());
3113 TemplateTypeParmDecl *VisitMacroQualifiedType(
const MacroQualifiedType *
T) {
3114 return Visit(
T->getUnderlyingType());
3117 TemplateTypeParmDecl *VisitAdjustedType(
const AdjustedType *
T) {
3118 return Visit(
T->getOriginalType());
3121 TemplateTypeParmDecl *VisitPackExpansionType(
const PackExpansionType *
T) {
3122 return Visit(
T->getPattern());
3131 bool EvaluateConstraints) {
3135 if (!EvaluateConstraints) {
3137 bool ContainsUnexpandedPack =
3141 return TA.getArgument().containsUnexpandedParameterPack();
3143 if (!Index && ContainsUnexpandedPack)
3144 Index =
SemaRef.ArgPackSubstIndex;
3173 bool ExpectParameterPack,
bool EvaluateConstraint) {
3193 }
else if (ExpectParameterPack) {
3199 diag::err_function_parameter_pack_without_parameter_packs)
3223 GetContainedInventedTypeParmVisitor().Visit(OldTSI->
getType())) {
3225 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3230 if (Inst && !Inst->getTypeConstraint()) {
3298 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3300 return Instantiator.TransformFunctionTypeParams(
3301 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3310 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3314 if (AlreadyInstantiating) {
3315 Param->setInvalidDecl();
3316 return Diag(Param->getBeginLoc(), diag::err_recursive_default_argument)
3334 std::optional<LocalInstantiationScope> LIS;
3345 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3362 Param->getLocation(),
3367 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3397 auto ComputeInfo = [&S, &TemplateArgs, BaseSourceRange, BaseEllipsisLoc](
3404 if (IsLateExpansionAttempt) {
3409 return P.first.dyn_cast<
const SubstBuiltinTemplatePackType *>();
3411 if (!SawPackTypes) {
3423 BaseEllipsisLoc, BaseSourceRange, Unexpanded, TemplateArgs,
3428 if (ComputeInfo(
Base.getTypeSourceInfo(),
false, Info))
3432 Out =
Base.getTypeSourceInfo();
3442 if (!Out->getType()->containsUnexpandedParameterPack())
3447 if (ComputeInfo(Out,
true, Info))
3460 for (
const auto &
Base : Pattern->
bases()) {
3461 if (!
Base.getType()->isInstantiationDependentType()) {
3463 if (RD->isInvalidDecl())
3472 if (
Base.isPackExpansion()) {
3484 ArgsForSubst = &EmptyList;
3499 Instantiation,
Base.getSourceRange(),
Base.isVirtual(),
3500 Base.getAccessSpecifierAsWritten(), Expanded,
3502 InstantiatedBases.push_back(InstantiatedBase);
3511 EllipsisLoc =
Base.getEllipsisLoc();
3519 Base.getSourceRange().getBegin(),
3530 Base.getSourceRange(),
3532 Base.getAccessSpecifierAsWritten(),
3535 InstantiatedBases.push_back(InstantiatedBase);
3565 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3568 return InstantiateClassImpl(PointOfInstantiation, Instantiation, Pattern,
3569 TemplateArgs, TSK, Complain);
3572bool Sema::InstantiateClassImpl(
3579 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3581 Pattern, PatternDef, TSK, Complain))
3584 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3585 llvm::TimeTraceMetadata M;
3586 llvm::raw_string_ostream OS(M.Detail);
3589 if (llvm::isTimeTraceVerbose()) {
3590 auto Loc = SourceMgr.getExpansionLoc(Instantiation->
getLocation());
3591 M.File = SourceMgr.getFilename(Loc);
3592 M.Line = SourceMgr.getExpansionLineNumber(Loc);
3597 Pattern = PatternDef;
3600 if (MemberSpecializationInfo *MSInfo
3602 MSInfo->setTemplateSpecializationKind(TSK);
3603 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3604 }
else if (ClassTemplateSpecializationDecl *Spec
3605 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3606 Spec->setTemplateSpecializationKind(TSK);
3607 Spec->setPointOfInstantiation(PointOfInstantiation);
3610 NonSFINAEContext _(*
this);
3611 InstantiatingTemplate Inst(*
this, PointOfInstantiation, Instantiation);
3612 if (Inst.isInvalid())
3614 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3615 "instantiating class definition");
3619 ContextRAII SavedContext(*
this, Instantiation);
3620 EnterExpressionEvaluationContext EvalContext(
3621 *
this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
3627 LocalInstantiationScope Scope(*
this, MergeWithParentScope);
3633 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3636 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3646 Instantiation->
setTagKind(Pattern->getTagKind());
3649 if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
3652 TemplateDeclInstantiator Instantiator(*
this, Instantiation, TemplateArgs);
3653 Instantiator.setEvaluateConstraints(
false);
3654 SmallVector<Decl*, 4> Fields;
3656 LateInstantiatedAttrVec LateAttrs;
3657 Instantiator.enableLateAttributeInstantiation(&LateAttrs);
3659 bool MightHaveConstexprVirtualFunctions =
false;
3660 for (
auto *
Member : Pattern->decls()) {
3670 if (
Member->getDeclContext() != Pattern)
3681 if (
Member->isInvalidDecl()) {
3691 Decl *NewMember = Instantiator.Visit(
Member);
3693 if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3694 Fields.push_back(Field);
3695 }
else if (EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3701 Enum->isCompleteDefinition()) {
3702 MemberSpecializationInfo *MSInfo =
Enum->getMemberSpecializationInfo();
3703 assert(MSInfo &&
"no spec info for member enum specialization");
3707 }
else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
3708 if (SA->isFailed()) {
3714 }
else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3717 MightHaveConstexprVirtualFunctions =
true;
3720 if (
Member->isInvalidDecl())
3734 ActOnFields(
nullptr, Instantiation->
getLocation(), Instantiation, Fields,
3735 SourceLocation(), SourceLocation(), ParsedAttributesView());
3736 CheckCompletedCXXClass(
nullptr, Instantiation);
3741 if (ParsingClassDepth == 0)
3742 ActOnFinishCXXNonNestedClass();
3746 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3747 E = LateAttrs.end(); I != E; ++I) {
3748 assert(CurrentInstantiationScope == Instantiator.getStartingScope());
3749 CurrentInstantiationScope = I->Scope;
3753 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3754 CXXThisScopeRAII ThisScope(*
this, ThisContext, Qualifiers(),
3755 ND->isCXXInstanceMember());
3759 if (NewAttr && checkInstantiatedThreadSafetyAttrs(I->NewDecl, NewAttr))
3760 I->NewDecl->addAttr(NewAttr);
3762 Instantiator.getStartingScope());
3764 Instantiator.disableLateAttributeInstantiation();
3767 ActOnFinishDelayedMemberInitializers(Instantiation);
3772 Instantiation->
setLocation(Pattern->getLocation());
3773 Instantiation->
setLocStart(Pattern->getInnerLocStart());
3779 if (Pattern->isDependentContext())
3780 PerformDependentDiagnostics(Pattern, TemplateArgs);
3785 P = Instantiator.delayed_partial_spec_begin(),
3786 PEnd = Instantiator.delayed_partial_spec_end();
3788 if (!Instantiator.InstantiateClassTemplatePartialSpecialization(
3789 P->first, P->second)) {
3798 P = Instantiator.delayed_var_partial_spec_begin(),
3799 PEnd = Instantiator.delayed_var_partial_spec_end();
3801 if (!Instantiator.InstantiateVarTemplatePartialSpecialization(
3802 P->first, P->second)) {
3820 MarkVTableUsed(PointOfInstantiation, Instantiation,
true);
3821 else if (MightHaveConstexprVirtualFunctions)
3822 MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
3826 Consumer.HandleTagDeclDefinition(Instantiation);
3838 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3844 Pattern, PatternDef, TSK,
true))
3846 Pattern = PatternDef;
3860 "instantiating enum definition");
3895 "pattern and instantiation disagree about init style");
3899 if (AlreadyInstantiating)
3901 return Diag(PointOfInstantiation,
3902 diag::err_default_member_initializer_cycle)
3911 Diag(PointOfInstantiation,
3912 diag::err_default_member_initializer_not_yet_parsed)
3913 << OutermostClass << Pattern;
3914 Diag(Pattern->getEndLoc(),
3915 diag::note_default_member_initializer_not_yet_parsed);
3924 "instantiating default member init");
3933 PointOfInstantiation, Instantiation,
CurContext};
3949 L->DefaultMemberInitializerInstantiated(Instantiation);
3958 struct PartialSpecMatchResult {
4003 std::optional<Sema::NonSFINAEContext> NSC(S);
4023 typedef PartialSpecMatchResult MatchResult;
4026 Template->getPartialSpecializations(PartialSpecs);
4039 if (
Template->isMemberSpecialization() &&
4040 !Partial->isMemberSpecialization())
4058 if (Matched.empty() && PrimaryStrictPackMatch)
4059 Matched = std::move(ExtraMatched);
4065 if (Matched.size() >= 1) {
4067 if (Matched.size() == 1) {
4080 PEnd = Matched.end();
4083 P->Partial, Best->Partial, PointOfInstantiation) ==
4092 PEnd = Matched.end();
4095 P->Partial, Best->Partial,
4096 PointOfInstantiation) != Best->Partial) {
4106 S.
Diag(PointOfInstantiation,
4107 diag::err_partial_spec_ordering_ambiguous)
4108 << ClassTemplateSpec;
4112 PEnd = Matched.end();
4114 S.
Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
4116 P->Partial->getTemplateParameters(), *P->Args);
4131 if (
auto *PartialSpec =
4134 while (PartialSpec->getInstantiatedFromMember()) {
4137 if (PartialSpec->isMemberSpecialization())
4140 PartialSpec = PartialSpec->getInstantiatedFromMember();
4142 Pattern = PartialSpec;
4145 while (
Template->getInstantiatedFromMemberTemplate()) {
4148 if (
Template->isMemberSpecialization())
4153 Pattern =
Template->getTemplatedDecl();
4163 bool PrimaryStrictPackMatch) {
4172 if (AlreadyInstantiating)
4175 bool HadAvaibilityWarning =
4181 ClassTemplateSpec, TSK,
4182 PrimaryStrictPackMatch);
4187 bool Err = InstantiateClassImpl(
4188 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4195 if (!Err && !HadAvaibilityWarning) {
4215 "Unexpected template specialization kind!");
4216 for (
auto *D : Instantiation->
decls()) {
4217 bool SuppressNew =
false;
4218 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4220 Function->getInstantiatedFromMemberFunction()) {
4222 if (
Function->getTrailingRequiresClause()) {
4230 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4234 Function->getTemplateSpecializationKind();
4239 PointOfInstantiation, TSK,
Function, PrevTSK,
4240 Function->getPointOfInstantiation(), SuppressNew) ||
4253 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4263 std::make_pair(
Function, PointOfInstantiation));
4266 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4271 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4275 assert(MSInfo &&
"No member specialization information?");
4304 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4305 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4313 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4318 assert(MSInfo &&
"No member specialization information?");
4324 if (
Context.getTargetInfo().getTriple().isOSWindows() &&
4344 assert(Pattern &&
"Missing instantiated-from-template information");
4346 if (!
Record->getDefinition()) {
4367 Record->getTemplateSpecializationKind() ==
4369 Record->setTemplateSpecializationKind(TSK);
4374 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4378 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4380 assert(MSInfo &&
"No member specialization information?");
4387 PointOfInstantiation, TSK,
Enum,
4393 if (
Enum->getDefinition())
4396 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4397 assert(Pattern &&
"Missing instantiated-from-template information");
4408 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4419 ClassPattern->
lookup(Field->getDeclName());
4452 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4455 return Instantiator.TransformStmt(S);
4463 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
4464 return Instantiator.TransformTemplateArgument(Input, Output);
4471 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4473 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4480 TemplateInstantiator Instantiator(
4481 TemplateInstantiator::ForParameterMappingSubstitution, *
this, BaseLoc,
4483 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4491 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4494 return Instantiator.TransformExpr(E);
4503 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4505 return Instantiator.TransformAddressOfOperand(E);
4514 TemplateInstantiator Instantiator(
4515 TemplateInstantiator::ForConstraintSubstitution, *
this, TemplateArgs,
4517 return Instantiator.TransformExpr(E);
4525 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4527 Instantiator.setEvaluateConstraints(
false);
4528 return Instantiator.TransformExpr(E);
4536 TemplateInstantiator Instantiator(*
this, MLTAL,
SourceLocation(),
4543 if (Instantiator.TransformConceptTemplateArguments(
4568 struct ConstraintExprTransformer :
TreeTransform<ConstraintExprTransformer> {
4580 case Stmt::BinaryOperatorClass:
4581 case Stmt::ConceptSpecializationExprClass:
4582 case Stmt::ParenExprClass:
4583 case Stmt::UnresolvedLookupExprClass:
4584 return Base::TransformExpr(E);
4595 if (!(E->
getOpcode() == BinaryOperatorKind::BO_LAnd ||
4596 E->
getOpcode() == BinaryOperatorKind::BO_LOr))
4613 bool Uneval =
false) {
4615 return Base::TransformTemplateArgument(Input, Output, Uneval);
4622 bool IsAddressOfOperand =
false) {
4623 if (!E->isConceptReference())
4626 assert(E->getNumDecls() == 1 &&
4627 "ConceptReference must have single declaration");
4631 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
4632 unsigned Depth = TTP->getDepth();
4633 unsigned Pos = TTP->getPosition();
4641 if (ResolvedConcept ==
nullptr)
4647 if (TransformTemplateArguments(E->getTemplateArgs(),
4648 E->getNumTemplateArgs(), TransArgs))
4655 ResolvedConcept, ResolvedConcept,
4660 ConstraintExprTransformer Transformer(*
this, MLTALForConstraint);
4662 Transformer.TransformExpr(
const_cast<Expr *
>(ConstraintExpr));
4668 bool CXXDirectInit) {
4669 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4671 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4680 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4683 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4693 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4695 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4701 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4703 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4711 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameLoc,
4713 return Instantiator.TransformTemplateName(QualifierLoc, TemplateKWLoc, Name,
4722 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4723 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4724 unsigned i = PV->getFunctionScopeIndex();
4727 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4728 return FD->getCanonicalDecl()->getParamDecl(i);
4734llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4738 Current = Current->Outer) {
4741 const Decl *CheckD = D;
4743 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4744 if (
Found != Current->LocalDecls.end())
4745 return &
Found->second;
4749 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4756 if (!Current->CombineWithOuterScope)
4763llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4776 if (RD->isLocalClass())
4793 assert(
isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4799 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4800 if (Stored.isNull()) {
4804 while (Current->CombineWithOuterScope && Current->Outer) {
4805 Current = Current->Outer;
4806 assert(!Current->LocalDecls.contains(D) &&
4807 "Instantiated local in inner and outer scopes");
4811 }
else if (
DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(Stored)) {
4814 assert(
cast<Decl *>(Stored) == Inst &&
"Already instantiated this local");
4822 Pack->push_back(Inst);
4829 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4830 assert(!Current->LocalDecls.contains(D) &&
4831 "Creating local pack after instantiation of local");
4835 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4838 ArgumentPacks.push_back(Pack);
4843 if (llvm::is_contained(*Pack, D))
4850 unsigned NumExplicitArgs) {
4851 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4852 "Already have a partially-substituted pack");
4853 assert((!PartiallySubstitutedPack
4854 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4855 "Wrong number of arguments in partially-substituted pack");
4856 PartiallySubstitutedPack = Pack;
4857 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4858 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4863 unsigned *NumExplicitArgs)
const {
4865 *ExplicitArgs =
nullptr;
4866 if (NumExplicitArgs)
4867 *NumExplicitArgs = 0;
4870 Current = Current->Outer) {
4871 if (Current->PartiallySubstitutedPack) {
4873 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4874 if (NumExplicitArgs)
4875 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4877 return Current->PartiallySubstitutedPack;
4880 if (!Current->CombineWithOuterScope)
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.
Result
Implement __builtin_bit_cast and related operations.
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 std::string convertCallArgsValueCategoryAndTypeToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
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.
TypePropertyCache< Private > Cache
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const clang::PrintingPolicy & getPrintingPolicy() const
The result of parsing/analyzing an expression, statement etc.
Attr - This represents one attribute.
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getOperatorLoc() const
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a base class of a C++ class.
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
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...
void setIsHLSLBuiltinRecord(bool Value)
Sets the flag that the class is a built-in HLSL record.
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.
Represents a C++ nested-name-specifier or a global scope specifier.
Declaration of a class template.
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...
Declaration of a C++20 concept.
NamedDecl * getFoundDecl() const
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
const TypeClass * getTypePtr() const
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
bool HasSubstitutionFailure()
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
DeclContextLookupResult lookup_result
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
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 isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
ExprDependence getDependence() const
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
For a defaulted function, the kind of defaulted function that it is.
CXXSpecialMemberKind asSpecialMember() const
bool isComparison() const
bool isSpecialMember() const
DefaultedComparisonKind asComparison() const
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.
bool retainInnerDepths() const
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.
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.
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned 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
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
The collection of all-type qualifiers we support.
void removeObjCLifetime()
Represents a struct/union/class.
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
RAII object used to change the argument pack substitution index within a Sema object.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
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.
ExprResult SubstConceptTemplateArguments(const ConceptSpecializationExpr *CSE, const Expr *ConstraintExpr, const MultiLevelTemplateArgumentList &MLTAL)
Substitute concept template arguments in the constraint expression of a concept-id.
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
llvm::function_ref< void(SourceLocation, PartialDiagnostic)> InstantiationContextDiagFuncRef
TemplateName SubstTemplateName(SourceLocation TemplateKWLoc, NestedNameSpecifierLoc &QualifierLoc, TemplateName Name, SourceLocation NameLoc, const MultiLevelTemplateArgumentList &TemplateArgs)
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization,...
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
llvm::function_ref< void(llvm::raw_ostream &)> EntityPrinter
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
concepts::Requirement::SubstitutionDiagnostic * createSubstDiagAt(SourceLocation Location, EntityPrinter Printer)
create a Requirement::SubstitutionDiagnostic with only a SubstitutedEntity and DiagLoc using ASTConte...
bool SubstExprs(ArrayRef< Expr * > Exprs, bool IsCall, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< Expr * > &Outputs)
Substitute the given template arguments into a list of expressions, expanding pack expansions if requ...
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain, bool PrimaryStrictPackMatch)
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
DiagnosticsEngine & getDiagnostics() const
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions, bool Diagnose=true)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
ExprResult SubstConstraintExprWithoutSatisfaction(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
void PrintInstantiationStack()
ASTContext & getASTContext() const
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, bool AllowDeducedTST=false)
Perform substitution on the type T with a given set of template arguments.
void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given variable from its template.
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
bool pushCodeSynthesisContext(CodeSynthesisContext Ctx)
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
const LangOptions & getLangOpts() const
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
bool SubstTemplateArgumentsInParameterMapping(ArrayRef< TemplateArgumentLoc > Args, SourceLocation BaseLoc, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Out)
void InstantiateClassMembers(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiates the definitions of all of the member of the given class, which is an instantiation of a ...
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
void popCodeSynthesisContext()
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero)
llvm::DenseMap< llvm::FoldingSetNodeID, TemplateArgumentLoc > * CurrentCachedTemplateArgs
Cache the instantiation results of template parameter mappings within concepts.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
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 isSFINAEContext() const
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
UnsignedOrNone ArgPackSubstIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
bool InstantiateClass(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK, bool Complain=true)
Instantiate the definition of a class from a given pattern.
bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentLoc &Output, SourceLocation Loc={}, const DeclarationName &Entity={})
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, FunctionDecl *Function, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given function from its template.
bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, const MultiLevelTemplateArgumentList &TemplateArgs, bool ForCallExpr=false)
Substitute the given template arguments into the default argument.
ExprResult SubstConstraintExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
unsigned LastEmittedCodeSynthesisContextDepth
The depth of the context stack at the point when the most recent error or warning was produced.
bool inParameterMappingSubstitution() const
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
bool RebuildingImmediateInvocation
Whether the AST is currently being rebuilt to correct immediate invocations.
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, NamedDecl *Instantiation, bool InstantiatedFromMember, const NamedDecl *Pattern, const NamedDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true, bool *Unreachable=nullptr)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
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.
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
ExprResult SubstCXXIdExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
Substitute an expression as if it is a address-of-operand, which makes it act like a CXXIdExpression ...
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Perform substitution on the base class specifiers of the given class template specialization.
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
ASTMutationListener * getASTMutationListener() const
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
TypeSourceInfo * SubstFunctionDeclType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, bool EvaluateConstraints=true)
A form of SubstType intended specifically for instantiating the type of a FunctionDecl.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Represents the declaration of a struct/union/class/enum.
void setTagKind(TagKind TK)
void startDefinition()
Starts the definition of this tag declaration.
void setBraceRange(SourceRange R)
SourceLocation getNameLoc() const
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool isConceptOrConceptTemplateParameter() const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool isNull() const
Determine whether this template argument has no value.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
@ Template
The template argument is a template name that was provided for a template template parameter.
@ Pack
The template argument is actually a parameter pack.
@ Type
The template argument is a type.
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
@ Template
A single template declaration.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation getTemplateLoc() const
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
SourceLocation getLocation() const
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool isParameterPack() const
Returns whether this is a parameter pack.
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
UnsignedOrNone getArgPackSubstIndex() const
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
TemplateDecl * getNamedConcept() const
const DeclarationNameInfo & getConceptNameInfo() const
ConceptReference * getConceptReference() const
void setLocStart(SourceLocation L)
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc)
Pushes 'T' with all locations pointing to 'Loc'.
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
SourceLocation getNameLoc() const
void setNameLoc(SourceLocation Loc)
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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 * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getUnderlyingType() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
void deduceParmAddressSpace(const ASTContext &Ctxt)
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
CXXRecordDecl * Lambda
The class that describes the lambda.
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.
PRESERVE_NONE bool Ret(InterpState &S)
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)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ OK_Ordinary
An ordinary object is located at an address in memory.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool isPackProducingBuiltinTemplateName(TemplateName N)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
OptionalUnsigned< unsigned > UnsignedOrNone
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.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
for(const auto &A :T->param_types())
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)
@ PackIndex
Index of a pack indexing expression or specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
SourceLocation getLAngleLoc() const
ArrayRef< TemplateArgumentLoc > arguments() const
unsigned getNumTemplateArgs() const
SourceLocation getRAngleLoc() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.
ExceptionSpecInfo ExceptionSpec
constexpr underlying_type toInternalRepresentation() const
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
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
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.
@ 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.
@ SYCLKernelLaunchOverloadResolution
We are performing overload resolution for a call to a function template or variable template named 's...
@ ExpansionStmtInstantiation
We are instantiating an expansion statement.
@ 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<=>.
@ SYCLKernelLaunchLookup
We are performing name lookup for a function template or variable template named 'sycl_kernel_launch'...
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Decl * Entity
The entity that is being synthesized.
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
A stack object to be created when performing template instantiation.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template,...
void Clear()
Note that we have finished instantiating this template.
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
bool ExpandUnderForgetSubstitions
UnsignedOrNone NumExpansions