37#include "llvm/ADT/SmallVectorExtras.h"
38#include "llvm/ADT/StringExtras.h"
39#include "llvm/Support/ErrorHandling.h"
40#include "llvm/Support/SaveAndRestore.h"
41#include "llvm/Support/TimeProfiler.h"
54 const Decl *NextDecl =
nullptr;
56 bool ClearRelativeToPrimary =
true;
57 static Response Done() {
62 static Response ChangeDecl(
const Decl *ND) {
67 static Response ChangeDecl(
const DeclContext *Ctx) {
73 static Response UseNextDecl(
const Decl *CurDecl) {
77 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
78 Response R = Response::UseNextDecl(CurDecl);
79 R.ClearRelativeToPrimary =
false;
88getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
90 return LambdaCallOperator;
92 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
94 FTD && FTD->getInstantiatedFromMemberTemplate()) {
96 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
103 ->getInstantiatedFromMemberFunction())
104 LambdaCallOperator = Prev;
108 return LambdaCallOperator;
111struct EnclosingTypeAliasTemplateDetails {
121EnclosingTypeAliasTemplateDetails
122getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
125 TypeAliasTemplateInstantiation)
127 EnclosingTypeAliasTemplateDetails Result;
129 *
Next = TATD->getInstantiatedFromMemberTemplate();
133 CSC.template_arguments(),
136 Result.PrimaryTypeAliasDecl =
Next;
137 Next =
Next->getInstantiatedFromMemberTemplate();
150bool isLambdaEnclosedByTypeAliasDecl(
154 Visitor(
const FunctionDecl *CallOperator) : CallOperator(CallOperator) {}
155 bool VisitLambdaExpr(
LambdaExpr *LE)
override {
158 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
167 return !Visitor(getPrimaryTemplateOfGenericLambda(LambdaCallOperator))
168 .TraverseType(Underlying);
175 bool SkipForSpecialization) {
179 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
184 return Response::Done();
189 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
192 dyn_cast<VarTemplatePartialSpecializationDecl *>(Specialized)) {
193 if (!SkipForSpecialization)
194 Result.addOuterTemplateArguments(
197 if (Partial->isMemberSpecialization())
198 return Response::Done();
201 if (!SkipForSpecialization)
202 Result.addOuterTemplateArguments(
206 return Response::Done();
208 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
220 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
221 Result.addOuterTemplateArguments(std::nullopt);
222 return Response::Done();
225Response HandlePartialClassTemplateSpec(
228 if (!SkipForSpecialization)
230 return Response::Done();
237 bool SkipForSpecialization) {
242 return Response::Done();
244 if (!SkipForSpecialization)
245 Result.addOuterTemplateArguments(
254 return Response::Done();
260 if (
auto *InstFromPartialTempl =
263 return Response::ChangeDecl(
264 InstFromPartialTempl->getLexicalDeclContext());
266 return Response::UseNextDecl(ClassTemplSpec);
272 bool ForConstraintInstantiation,
273 bool ForDefaultArgumentSubstitution) {
275 if (!RelativeToPrimary &&
276 Function->getTemplateSpecializationKindForInstantiation() ==
278 return Response::Done();
280 if (!RelativeToPrimary &&
285 return Response::UseNextDecl(Function);
287 Function->getTemplateSpecializationArgs()) {
289 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
290 TemplateArgs->asArray(),
293 if (RelativeToPrimary &&
294 (Function->getTemplateSpecializationKind() ==
296 (Function->getFriendObjectKind() &&
297 !Function->getPrimaryTemplate()->getFriendObjectKind())))
298 return Response::UseNextDecl(Function);
302 assert(Function->getPrimaryTemplate() &&
"No function template?");
303 if (!ForDefaultArgumentSubstitution &&
304 Function->getPrimaryTemplate()->isMemberSpecialization())
305 return Response::Done();
308 if (!ForConstraintInstantiation &&
310 return Response::Done();
312 }
else if (
auto *
Template = Function->getDescribedFunctionTemplate()) {
314 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
315 "Outer template not instantiated?");
316 if (ForConstraintInstantiation) {
324 Result.addOuterTemplateArguments(
Template, Inst.template_arguments(),
335 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
336 Function->getNonTransparentDeclContext()->isFileContext() &&
338 return Response::ChangeDecl(Function->getLexicalDeclContext());
341 if (ForConstraintInstantiation && Function->getFriendObjectKind())
342 return Response::ChangeDecl(Function->getLexicalDeclContext());
343 return Response::UseNextDecl(Function);
346Response HandleFunctionTemplateDecl(
Sema &SemaRef,
350 Result.addOuterTemplateArguments(
363 Ty = std::exchange(NextTy,
nullptr)) {
366 NextTy = P.getAsType();
367 const auto *TSTy = dyn_cast<TemplateSpecializationType>(Ty);
389 if (TSTy->isCurrentInstantiation()) {
390 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
392 Arguments = CTD->getInjectedTemplateArgs(SemaRef.
Context);
394 dyn_cast<ClassTemplateSpecializationDecl>(RD))
395 Arguments =
Specialization->getTemplateInstantiationArgs().asArray();
397 Result.addOuterTemplateArguments(
398 TSTy->getTemplateName().getAsTemplateDecl(), Arguments,
409 bool ForConstraintInstantiation) {
412 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
413 "Outer template not instantiated?");
414 if (ClassTemplate->isMemberSpecialization())
415 return Response::Done();
416 if (ForConstraintInstantiation)
417 Result.addOuterTemplateArguments(
419 ClassTemplate->getInjectedTemplateArgs(SemaRef.
Context),
426 return Response::Done();
431 if (ForConstraintInstantiation && IsFriend &&
440 return Response::ChangeDecl(LCD);
444 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef);
445 ForConstraintInstantiation &&
TypeAlias) {
448 Result.addOuterTemplateArguments(
TypeAlias.Template,
464 return Response::ChangeDecl(
TypeAlias.Template->getDeclContext());
469 return Response::UseNextDecl(Rec);
472Response HandleImplicitConceptSpecializationDecl(
475 Result.addOuterTemplateArguments(
479 return Response::UseNextDecl(CSD);
482Response HandleGenericDeclContext(
const Decl *CurDecl) {
483 return Response::UseNextDecl(CurDecl);
491 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
492 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
493 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
498 const Decl *CurDecl = ND;
501 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
511 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
512 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
514 : Response::UseNextDecl(CurDecl).NextDecl;
520 if (
const auto *VarTemplSpec =
521 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
522 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
523 }
else if (
const auto *PartialClassTemplSpec =
524 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
525 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
526 SkipForSpecialization);
527 }
else if (
const auto *ClassTemplSpec =
528 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
529 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
530 SkipForSpecialization);
531 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
532 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
533 ForConstraintInstantiation,
534 ForDefaultArgumentSubstitution);
535 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
537 ForConstraintInstantiation);
538 }
else if (
const auto *CSD =
539 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
540 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
541 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
542 R = HandleFunctionTemplateDecl(*
this, FTD,
Result);
543 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
544 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
546 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
547 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
548 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
551 R = HandleGenericDeclContext(CurDecl);
556 if (R.ClearRelativeToPrimary)
557 RelativeToPrimary =
false;
559 CurDecl = R.NextDecl;
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;
649 PointOfInstantiation, InstantiationRange, Entity) {}
656 PointOfInstantiation, InstantiationRange, Entity) {}
695 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
704 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
713 PointOfInstantiation, InstantiationRange, Param,
nullptr,
723 PointOfInstantiation, InstantiationRange, Param,
Template,
733 PointOfInstantiation, InstantiationRange, Param,
Template,
742 PointOfInstantiation, InstantiationRange, Entity,
751 PointOfInstantiation, InstantiationRange, Param,
Template,
759 PointOfInstantiation, InstantiationRange,
nullptr,
768 PointOfInstantiation, InstantiationRange,
nullptr,
776 PointOfInstantiation, InstantiationRange,
nullptr,
801 PointOfInstantiation, InstantiationRange,
Template) {}
808 PointOfInstantiation, InstantiationRange, Entity) {}
814 ArgLoc, InstantiationRange, PArg) {}
820 assert(
SemaRef.NonInstantiationEntries <=
821 SemaRef.CodeSynthesisContexts.size());
822 if ((
SemaRef.CodeSynthesisContexts.size() -
823 SemaRef.NonInstantiationEntries) >
824 SemaRef.getLangOpts().InstantiationDepth) {
826 diag::err_template_recursion_depth_exceeded)
829 diag::note_template_recursion_depth)
830 <<
SemaRef.getLangOpts().InstantiationDepth;
845 if (!Active.isInstantiationRecord()) {
853 "forgot to remove a lookup module for a template instantiation");
873 SemaRef.CodeSynthesisContexts.back());
875 SemaRef.popCodeSynthesisContext();
883 llvm::raw_string_ostream
OS(
Result);
884 llvm::ListSeparator Comma;
885 for (
const Expr *Arg : Args) {
887 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
897 llvm::raw_string_ostream
OS(
Result);
898 llvm::ListSeparator Comma;
900 for (
const Expr *Arg : Args) {
902 const char *ValueCategory =
904 : (EVK ==
VK_XValue ?
"xvalue" :
"prvalue"));
905 OS << Comma << ValueCategory <<
" of type '";
916 unsigned Limit =
Diags.getTemplateBacktraceLimit();
918 SkipStart = Limit / 2 + Limit % 2;
923 unsigned InstantiationIdx = 0;
928 ++Active, ++InstantiationIdx) {
930 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
931 if (InstantiationIdx == SkipStart) {
933 DiagFunc(Active->PointOfInstantiation,
934 PDiag(diag::note_instantiation_contexts_suppressed)
940 switch (Active->Kind) {
942 Decl *D = Active->Entity;
944 unsigned DiagID = diag::note_template_member_class_here;
946 DiagID = diag::note_template_class_instantiation_here;
947 DiagFunc(Active->PointOfInstantiation,
948 PDiag(DiagID) <<
Record << Active->InstantiationRange);
952 DiagID = diag::note_function_template_spec_here;
954 DiagID = diag::note_template_member_function_here;
955 DiagFunc(Active->PointOfInstantiation,
957 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
958 DiagFunc(Active->PointOfInstantiation,
959 PDiag(VD->isStaticDataMember()
960 ? diag::note_template_static_data_member_def_here
961 : diag::note_template_variable_def_here)
962 << VD << Active->InstantiationRange);
963 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
964 DiagFunc(Active->PointOfInstantiation,
965 PDiag(diag::note_template_enum_def_here)
966 << ED << Active->InstantiationRange);
967 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
968 DiagFunc(Active->PointOfInstantiation,
969 PDiag(diag::note_template_nsdmi_here)
970 << FD << Active->InstantiationRange);
972 DiagFunc(Active->PointOfInstantiation,
973 PDiag(diag::note_template_class_instantiation_here)
974 << CTD << Active->InstantiationRange);
982 llvm::raw_svector_ostream
OS(TemplateArgsStr);
984 printTemplateArgumentList(
OS, Active->template_arguments(),
986 DiagFunc(Active->PointOfInstantiation,
987 PDiag(diag::note_default_arg_instantiation_here)
988 <<
OS.str() << Active->InstantiationRange);
994 DiagFunc(Active->PointOfInstantiation,
995 PDiag(diag::note_explicit_template_arg_substitution_here)
999 Active->NumTemplateArgs)
1000 << Active->InstantiationRange);
1006 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1008 Active->PointOfInstantiation,
1009 PDiag(diag::note_function_template_deduction_instantiation_here)
1012 FnTmpl->getTemplateParameters(), Active->TemplateArgs,
1013 Active->NumTemplateArgs)
1014 << Active->InstantiationRange);
1018 bool IsTemplate =
false;
1020 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1022 Params = D->getTemplateParameters();
1023 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1025 Params = D->getTemplateParameters();
1026 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1028 Params = D->getTemplateParameters();
1030 llvm_unreachable(
"unexpected template kind");
1033 DiagFunc(Active->PointOfInstantiation,
1034 PDiag(diag::note_deduced_template_arg_substitution_here)
1037 Active->TemplateArgs,
1038 Active->NumTemplateArgs)
1039 << Active->InstantiationRange);
1049 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1051 printTemplateArgumentList(
OS, Active->template_arguments(),
1053 DiagFunc(Active->PointOfInstantiation,
1054 PDiag(diag::note_default_function_arg_instantiation_here)
1055 <<
OS.str() << Active->InstantiationRange);
1063 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1067 TemplateParams =
Template->getTemplateParameters();
1071 ->getTemplateParameters();
1072 DiagFunc(Active->PointOfInstantiation,
1073 PDiag(diag::note_prior_template_arg_substitution)
1076 Active->TemplateArgs,
1077 Active->NumTemplateArgs)
1078 << Active->InstantiationRange);
1085 TemplateParams =
Template->getTemplateParameters();
1089 ->getTemplateParameters();
1091 DiagFunc(Active->PointOfInstantiation,
1092 PDiag(diag::note_template_default_arg_checking)
1094 Active->TemplateArgs,
1095 Active->NumTemplateArgs)
1096 << Active->InstantiationRange);
1101 DiagFunc(Active->PointOfInstantiation,
1102 PDiag(diag::note_evaluating_exception_spec_here)
1107 DiagFunc(Active->PointOfInstantiation,
1108 PDiag(diag::note_template_exception_spec_instantiation_here)
1110 << Active->InstantiationRange);
1114 DiagFunc(Active->PointOfInstantiation,
1115 PDiag(diag::note_template_requirement_instantiation_here)
1116 << Active->InstantiationRange);
1119 DiagFunc(Active->PointOfInstantiation,
1120 PDiag(diag::note_template_requirement_params_instantiation_here)
1121 << Active->InstantiationRange);
1125 DiagFunc(Active->PointOfInstantiation,
1126 PDiag(diag::note_nested_requirement_here)
1127 << Active->InstantiationRange);
1131 DiagFunc(Active->PointOfInstantiation,
1132 PDiag(diag::note_in_declaration_of_implicit_special_member)
1134 << Active->SpecialMember);
1139 Active->Entity->getLocation(),
1140 PDiag(diag::note_in_declaration_of_implicit_equality_comparison));
1146 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1154 DiagFunc(Active->PointOfInstantiation,
1155 PDiag(diag::note_member_synthesized_at)
1157 <<
Context.getCanonicalTagType(MD->getParent()));
1159 QualType RecordType = FD->getParamDecl(0)
1161 .getNonReferenceType()
1162 .getUnqualifiedType();
1163 DiagFunc(Active->PointOfInstantiation,
1164 PDiag(diag::note_comparison_synthesized_at)
1171 DiagFunc(Active->Entity->getLocation(),
1172 PDiag(diag::note_rewriting_operator_as_spaceship));
1176 DiagFunc(Active->PointOfInstantiation,
1177 PDiag(diag::note_in_binding_decl_init)
1182 DiagFunc(Active->PointOfInstantiation,
1183 PDiag(diag::note_due_to_dllexported_class)
1189 DiagFunc(Active->PointOfInstantiation,
1190 PDiag(diag::note_building_builtin_dump_struct_call)
1193 Active->NumCallArgs)));
1200 DiagFunc(Active->PointOfInstantiation,
1201 PDiag(diag::note_lambda_substitution_here));
1204 unsigned DiagID = 0;
1205 if (!Active->Entity) {
1206 DiagFunc(Active->PointOfInstantiation,
1207 PDiag(diag::note_nested_requirement_here)
1208 << Active->InstantiationRange);
1212 DiagID = diag::note_concept_specialization_here;
1214 DiagID = diag::note_checking_constraints_for_template_id_here;
1216 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1218 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1221 DiagID = diag::note_checking_constraints_for_function_here;
1224 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1227 printTemplateArgumentList(
OS, Active->template_arguments(),
1230 DiagFunc(Active->PointOfInstantiation,
1231 PDiag(DiagID) <<
OS.str() << Active->InstantiationRange);
1235 DiagFunc(Active->PointOfInstantiation,
1236 PDiag(diag::note_constraint_substitution_here)
1237 << Active->InstantiationRange);
1240 DiagFunc(Active->PointOfInstantiation,
1241 PDiag(diag::note_parameter_mapping_substitution_here)
1242 << Active->InstantiationRange);
1245 DiagFunc(Active->PointOfInstantiation,
1246 PDiag(diag::note_building_deduction_guide_here));
1253 if (Active->NumTemplateArgs == 0)
1255 DiagFunc(Active->PointOfInstantiation,
1256 PDiag(diag::note_template_type_alias_instantiation_here)
1258 << Active->InstantiationRange);
1261 DiagFunc(Active->PointOfInstantiation,
1262 PDiag(diag::note_template_arg_template_params_mismatch));
1265 DiagFunc(ParamLoc,
PDiag(diag::note_template_prev_declaration)
1267 << Active->InstantiationRange);
1270 const auto *SKEPAttr =
1271 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1272 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1273 assert(!SKEPAttr->isInvalidAttr() &&
1274 "sycl_kernel_entry_point attribute is invalid");
1275 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1276 DiagFunc(SKEPAttr->getLocation(),
1277 PDiag(diag::note_sycl_kernel_launch_lookup_here)
1278 << SKEPAttr->getKernelName());
1282 const auto *SKEPAttr =
1283 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1284 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1285 assert(!SKEPAttr->isInvalidAttr() &&
1286 "sycl_kernel_entry_point attribute is invalid");
1287 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1288 DiagFunc(SKEPAttr->getLocation(),
1289 PDiag(diag::note_sycl_kernel_launch_overload_resolution_here)
1290 << SKEPAttr->getKernelName()
1293 Active->NumCallArgs)));
1305 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1310 bool EvaluateConstraints =
true;
1313 bool IsIncomplete =
false;
1315 bool BailOutOnIncomplete;
1317 std::optional<llvm::FoldingSetNodeID> TemplateArgsHashValue;
1322 bool maybeInstantiateFunctionParameterToScope(
ParmVarDecl *OldParm);
1327 TemplateInstantiator(
Sema &SemaRef,
1330 bool BailOutOnIncomplete =
false)
1331 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1332 Entity(Entity), BailOutOnIncomplete(BailOutOnIncomplete) {
1335 "Cannot perform an instantiation without some context on the "
1336 "instantiation stack");
1339 void setEvaluateConstraints(
bool B) {
1340 EvaluateConstraints = B;
1342 bool getEvaluateConstraints() {
1343 return EvaluateConstraints;
1346 inline static struct ForParameterMappingSubstitution_t {
1347 } ForParameterMappingSubstitution;
1349 TemplateInstantiator(ForParameterMappingSubstitution_t, Sema &SemaRef,
1351 const MultiLevelTemplateArgumentList &TemplateArgs)
1352 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1353 BailOutOnIncomplete(
false) {
1356 auto &
V = TemplateArgsHashValue.emplace();
1358 for (
auto &Arg :
Level.Args)
1367 bool AlreadyTransformed(QualType T);
1370 SourceLocation getBaseLocation() {
return Loc; }
1373 DeclarationName getBaseEntity() {
return Entity; }
1376 bool getIsIncomplete()
const {
return IsIncomplete; }
1380 void setBase(SourceLocation Loc, DeclarationName Entity) {
1382 this->Entity = Entity;
1385 unsigned TransformTemplateDepth(
unsigned Depth) {
1386 return TemplateArgs.getNewDepth(Depth);
1389 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1390 SourceRange PatternRange,
1391 ArrayRef<UnexpandedParameterPack> Unexpanded,
1392 bool FailOnPackProducingTemplates,
1393 bool &ShouldExpand,
bool &RetainExpansion,
1399 NamedDecl *VD = ParmPack.first.dyn_cast<NamedDecl *>();
1400 if (
auto *PVD = dyn_cast_if_present<ParmVarDecl>(VD);
1401 PVD && maybeInstantiateFunctionParameterToScope(PVD))
1406 return getSema().CheckParameterPacksForExpansion(
1407 EllipsisLoc, PatternRange, Unexpanded, TemplateArgs,
1408 FailOnPackProducingTemplates, ShouldExpand, RetainExpansion,
1412 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1416 TemplateArgument ForgetPartiallySubstitutedPack() {
1420 MultiLevelTemplateArgumentList &TemplateArgs =
1421 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1422 unsigned Depth, Index;
1425 Result = TemplateArgs(Depth, Index);
1426 TemplateArgs.
setArgument(Depth, Index, TemplateArgument());
1428 IsIncomplete =
true;
1429 if (BailOutOnIncomplete)
1430 return TemplateArgument();
1437 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1443 MultiLevelTemplateArgumentList &TemplateArgs =
1444 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1445 unsigned Depth, Index;
1451 MultiLevelTemplateArgumentList ForgetSubstitution() {
1452 MultiLevelTemplateArgumentList
New;
1455 MultiLevelTemplateArgumentList Old =
1456 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1457 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1462 void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
1463 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1468 getTemplateArgumentPackPatternForRewrite(
const TemplateArgument &TA) {
1474 "unexpected pack arguments in template rewrite");
1483 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1485 void transformAttrs(Decl *Old, Decl *
New) {
1489 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1491 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1493 for (
auto *
New : NewDecls)
1499 assert(NewDecls.size() == 1 &&
1500 "should only have multiple expansions for a pack");
1506 auto *NewMD = dyn_cast<CXXMethodDecl>(
New);
1508 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1509 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1510 NewTD->setInstantiatedFromMemberTemplate(
1511 OldMD->getDescribedFunctionTemplate());
1513 NewMD->setInstantiationOfMemberFunction(OldMD,
1521 if (
auto *DC = dyn_cast<DeclContext>(Old);
1522 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1528 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1532 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1534 bool TransformExceptionSpec(SourceLocation Loc,
1535 FunctionProtoType::ExceptionSpecInfo &ESI,
1536 SmallVectorImpl<QualType> &Exceptions,
1541 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1542 TypeSourceInfo *Declarator,
1543 SourceLocation StartLoc,
1544 SourceLocation NameLoc,
1545 IdentifierInfo *Name);
1549 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1550 TypeSourceInfo *TSInfo, QualType T);
1553 TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc,
1555 SourceLocation NameLoc,
1556 QualType ObjectType = QualType(),
1557 NamedDecl *FirstQualifierInScope =
nullptr,
1558 bool AllowInjectedClassName =
false);
1560 const AnnotateAttr *TransformAnnotateAttr(
const AnnotateAttr *AA);
1561 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1562 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1563 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1565 const NoInlineAttr *A);
1566 const AlwaysInlineAttr *
1567 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1568 const AlwaysInlineAttr *A);
1569 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1570 const OpenACCRoutineDeclAttr *
1571 TransformOpenACCRoutineDeclAttr(
const OpenACCRoutineDeclAttr *A);
1572 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1573 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1574 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1576 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1577 NonTypeTemplateParmDecl *D);
1580 ExprResult RebuildVarDeclRefExpr(ValueDecl *PD, SourceLocation Loc);
1583 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, ValueDecl *PD);
1588 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1590 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1591 FunctionProtoTypeLoc TL) {
1593 return inherited::TransformFunctionProtoType(TLB, TL);
1596 QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL) {
1597 auto Type = inherited::TransformTagType(TLB, TL);
1603 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TL.
getTypePtr());
1606 Type = inherited::TransformType(
1607 ICNT->getDecl()->getCanonicalTemplateSpecializationType(
1617 bool TransformTemplateArgument(
const TemplateArgumentLoc &Input,
1618 TemplateArgumentLoc &Output,
1619 bool Uneval =
false) {
1620 const TemplateArgument &Arg = Input.
getArgument();
1622 Cache && TemplateArgsHashValue) {
1623 llvm::FoldingSetNodeID
ID = *TemplateArgsHashValue;
1633 if (
auto Iter =
Cache->find(ID); Iter !=
Cache->end()) {
1634 Output = Iter->second;
1637 bool Ret = inherited::TransformTemplateArgument(Input, Output, Uneval);
1644 std::vector<TemplateArgument> TArgs;
1652 pack, QualType(), SourceLocation{});
1653 TemplateArgumentLoc Output;
1654 if (TransformTemplateArgument(Input, Output, Uneval))
1659 TemplateArgument(llvm::ArrayRef(TArgs).copy(SemaRef.
Context)),
1660 QualType(), SourceLocation{});
1666 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1671 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
1672 TemplateSpecializationTypeLoc TL) {
1674 if (!getSema().ArgPackSubstIndex || !T->isSugared() ||
1684 QualType
R = TransformType(T->desugar());
1690 ArrayRef<TemplateArgument> PackArgs) {
1701 return std::nullopt;
1703 return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1706 template<
typename Fn>
1707 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1708 FunctionProtoTypeLoc TL,
1709 CXXRecordDecl *ThisContext,
1710 Qualifiers ThisTypeQuals,
1711 Fn TransformExceptionSpec);
1713 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1714 int indexAdjustment,
1716 bool ExpectParameterPack);
1718 using inherited::TransformTemplateTypeParmType;
1721 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1722 TemplateTypeParmTypeLoc TL,
1723 bool SuppressObjCLifetime);
1725 QualType BuildSubstTemplateTypeParmType(
1726 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
1728 TemplateArgument Arg, SourceLocation NameLoc);
1733 using inherited::TransformSubstTemplateTypeParmPackType;
1735 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1736 SubstTemplateTypeParmPackTypeLoc TL,
1737 bool SuppressObjCLifetime);
1739 TransformSubstBuiltinTemplatePackType(TypeLocBuilder &TLB,
1740 SubstBuiltinTemplatePackTypeLoc TL);
1743 ComputeLambdaDependency(LambdaScopeInfo *LSI) {
1745 TemplateInstArgsHelpers::getEnclosingTypeAliasTemplateDecl(
1747 TypeAlias && TemplateInstArgsHelpers::isLambdaEnclosedByTypeAliasDecl(
1749 unsigned TypeAliasDeclDepth =
TypeAlias.Template->getTemplateDepth();
1751 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1752 for (
const TemplateArgument &TA :
TypeAlias.AssociatedTemplateArguments)
1754 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1756 return inherited::ComputeLambdaDependency(LSI);
1764 LocalInstantiationScope Scope(SemaRef,
true,
1766 Sema::ConstraintEvalRAII<TemplateInstantiator> RAII(*
this);
1768 return inherited::TransformLambdaExpr(E);
1771 ExprResult TransformBlockExpr(BlockExpr *E) {
1772 LocalInstantiationScope Scope(SemaRef,
true,
1774 return inherited::TransformBlockExpr(E);
1777 ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1778 LambdaScopeInfo *LSI) {
1781 assert(PVD &&
"null in a parameter list");
1782 if (!PVD->hasDefaultArg())
1784 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1786 SourceLocation EqualLoc = UninstExpr->
getBeginLoc();
1795 PVD->setDefaultArg(ErrorResult.
get());
1798 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1811 llvm::SaveAndRestore _(EvaluateConstraints,
true);
1812 return inherited::TransformLambdaBody(E, Body);
1816 LocalInstantiationScope Scope(SemaRef,
true);
1817 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1820 assert(TransReq.
get() != E &&
1821 "Do not change value of isSatisfied for the existing expression. "
1822 "Create a new expression instead.");
1824 Sema::SFINAETrap Trap(SemaRef);
1829 if (Trap.hasErrorOccurred())
1835 bool TransformRequiresExprRequirements(
1836 ArrayRef<concepts::Requirement *> Reqs,
1837 SmallVectorImpl<concepts::Requirement *> &Transformed) {
1838 bool SatisfactionDetermined =
false;
1839 for (concepts::Requirement *Req : Reqs) {
1840 concepts::Requirement *TransReq =
nullptr;
1841 if (!SatisfactionDetermined) {
1842 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1843 TransReq = TransformTypeRequirement(TypeReq);
1844 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1845 TransReq = TransformExprRequirement(ExprReq);
1847 TransReq = TransformNestedRequirement(
1857 SatisfactionDetermined =
true;
1860 Transformed.push_back(TransReq);
1865 TemplateParameterList *TransformTemplateParameterList(
1866 TemplateParameterList *OrigTPL) {
1867 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1870 TemplateDeclInstantiator DeclInstantiator(getSema(),
1873 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1874 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1877 concepts::TypeRequirement *
1878 TransformTypeRequirement(concepts::TypeRequirement *Req);
1879 concepts::ExprRequirement *
1880 TransformExprRequirement(concepts::ExprRequirement *Req);
1881 concepts::NestedRequirement *
1882 TransformNestedRequirement(concepts::NestedRequirement *Req);
1884 SourceLocation KWLoc, SourceLocation RBraceLoc,
const RequiresExpr *RE,
1885 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params,
1886 SmallVectorImpl<QualType> &PTypes,
1887 SmallVectorImpl<ParmVarDecl *> &TransParams,
1888 Sema::ExtParameterInfoBuilder &PInfos);
1890 ExprResult TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1892 if (
Ret.isInvalid())
1894 auto *DestDecl =
Ret.get()->getType()->getPointeeCXXRecordDecl();
1895 if (DestDecl && DestDecl->isEffectivelyFinal())
1896 getSema().MarkVTableUsed(
Ret.get()->getExprLoc(), DestDecl);
1902bool TemplateInstantiator::AlreadyTransformed(QualType T) {
1910 getSema().MarkDeclarationsReferencedInType(Loc, T);
1914Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1918 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1925 TTP->getPosition())) {
1926 IsIncomplete =
true;
1927 return BailOutOnIncomplete ?
nullptr : D;
1930 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1932 if (TTP->isParameterPack()) {
1934 "Missing argument pack");
1935 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
1940 "Wrong kind of template template argument");
1941 return Template.getAsTemplateDecl();
1948 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(D);
1949 PVD &&
SemaRef.CurrentInstantiationScope &&
1950 (
SemaRef.inConstraintSubstitution() ||
1951 SemaRef.inParameterMappingSubstitution()) &&
1952 maybeInstantiateFunctionParameterToScope(PVD))
1958bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
1959 ParmVarDecl *OldParm) {
1960 if (
SemaRef.CurrentInstantiationScope->getInstantiationOfIfExists(OldParm))
1964 return !TransformFunctionTypeParam(OldParm, 0,
1968 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
1972 PackExpansionTypeLoc ExpansionTL = TL.
castAs<PackExpansionTypeLoc>();
1974 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
1975 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
1977 bool ShouldExpand =
false;
1978 bool RetainExpansion =
false;
1980 ExpansionTL.
getTypePtr()->getNumExpansions();
1983 Pattern.getSourceRange(), Unexpanded,
1985 ShouldExpand, RetainExpansion, NumExpansions))
1988 assert(ShouldExpand && !RetainExpansion &&
1989 "Shouldn't preserve pack expansion when evaluating constraints");
1990 ExpandingFunctionParameterPack(OldParm);
1991 for (
unsigned I = 0; I != *NumExpansions; ++I) {
1992 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
1993 if (!TransformFunctionTypeParam(OldParm, 0,
2001Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
2002 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
2006 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2010bool TemplateInstantiator::TransformExceptionSpec(
2011 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
2012 SmallVectorImpl<QualType> &Exceptions,
bool &Changed) {
2017 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
2021TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
2022 SourceLocation Loc) {
2025 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
2026 const TemplateTypeParmType *TTP
2031 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
2033 if (TTP->isParameterPack()) {
2035 "Missing argument pack");
2040 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2045 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2047 if (
const TagType *Tag = T->
getAs<TagType>())
2048 return Tag->getDecl();
2051 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
2056 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2060TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
2061 TypeSourceInfo *Declarator,
2062 SourceLocation StartLoc,
2063 SourceLocation NameLoc,
2064 IdentifierInfo *Name) {
2065 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
2066 StartLoc, NameLoc, Name);
2068 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2072VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
2073 TypeSourceInfo *TSInfo,
2075 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
2077 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2081TemplateName TemplateInstantiator::TransformTemplateName(
2082 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
2083 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
2084 NamedDecl *FirstQualifierInScope,
bool AllowInjectedClassName) {
2086 assert(!QualifierLoc &&
"Unexpected qualifier");
2089 TTP && TTP->getDepth() < TemplateArgs.
getNumLevels()) {
2095 TTP->getPosition())) {
2096 IsIncomplete =
true;
2100 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
2105 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2107 "unexpected nontype template argument kind in template rewrite");
2111 auto [AssociatedDecl, Final] =
2114 if (TTP->isParameterPack()) {
2116 "Missing argument pack");
2122 return getSema().Context.getSubstTemplateTemplateParmPack(
2123 Arg, AssociatedDecl, TTP->getIndex(), Final);
2127 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2131 assert(!
Template.isNull() &&
"Null template template argument");
2132 return getSema().Context.getSubstTemplateTemplateParm(
2137 if (SubstTemplateTemplateParmPackStorage *SubstPack
2142 TemplateArgument Pack = SubstPack->getArgumentPack();
2144 SemaRef.getPackSubstitutedTemplateArgument(Pack).getAsTemplate();
2145 return getSema().Context.getSubstTemplateTemplateParm(
2146 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2147 SemaRef.getPackIndex(Pack), SubstPack->getFinal());
2150 return inherited::TransformTemplateName(
2151 QualifierLoc, TemplateKWLoc, Name, NameLoc, ObjectType,
2152 FirstQualifierInScope, AllowInjectedClassName);
2156TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
2164TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
2165 NonTypeTemplateParmDecl *NTTP) {
2172 IsIncomplete =
true;
2173 return BailOutOnIncomplete ?
ExprError() : E;
2181 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2183 "unexpected nontype template argument kind in template rewrite");
2196 assert(!ParamType.
isNull() &&
"Shouldn't substitute to an invalid type");
2198 auto [AssociatedDecl, Final] =
2203 "Missing argument pack");
2212 return new (
SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
2217 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2219 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
2225TemplateInstantiator::TransformAnnotateAttr(
const AnnotateAttr *AA) {
2226 SmallVector<Expr *> Args;
2227 for (Expr *Arg : AA->args()) {
2228 ExprResult Res = getDerived().TransformExpr(Arg);
2230 Args.push_back(Res.
get());
2232 return AnnotateAttr::CreateImplicit(getSema().
Context, AA->getAnnotation(),
2233 Args.data(), Args.size(), AA->getRange());
2236const CXXAssumeAttr *
2237TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2238 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2242 if (!(Res.
get()->
getDependence() & ExprDependence::TypeValueInstantiation)) {
2243 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2249 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2254TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2255 ExprResult TransformedExprResult = getDerived().TransformExpr(LH->getValue());
2256 if (!TransformedExprResult.
isUsable() ||
2257 TransformedExprResult.
get() == LH->getValue())
2259 Expr *TransformedExpr = TransformedExprResult.
get();
2263 LH->getSemanticSpelling() ==
2264 LoopHintAttr::Pragma_unroll))
2267 LoopHintAttr::OptionType Option = LH->getOption();
2268 LoopHintAttr::LoopHintState State = LH->getState();
2275 if (Option == LoopHintAttr::UnrollCount &&
2277 llvm::APSInt ValueAPS =
2281 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2282 Option = LoopHintAttr::Unroll;
2283 State = LoopHintAttr::Disable;
2289 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2290 TransformedExpr, *LH);
2292const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2293 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2299const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2300 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2307const CodeAlignAttr *
2308TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2309 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2310 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2312const OpenACCRoutineDeclAttr *
2313TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
2314 const OpenACCRoutineDeclAttr *A) {
2315 llvm_unreachable(
"RoutineDecl should only be a declaration attribute, as it "
2316 "applies to a Function Decl (and a few places for VarDecl)");
2319ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,
2320 SourceLocation Loc) {
2321 DeclarationNameInfo NameInfo(PD->
getDeclName(), Loc);
2322 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
2326TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
2330 ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), D));
2333 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2336 QualType T = TransformType(E->
getType());
2342 SmallVector<ValueDecl *, 8> Vars;
2346 ValueDecl *D = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), *I));
2355 getSema().MarkFunctionParmPackReferenced(PackExpr);
2360TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
2363 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found
2364 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2365 assert(
Found &&
"no instantiation for parameter pack");
2367 Decl *TransformedDecl;
2368 if (DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(*
Found)) {
2372 QualType T = TransformType(E->
getType());
2377 getSema().MarkFunctionParmPackReferenced(PackExpr);
2381 TransformedDecl = (*Pack)[*getSema().ArgPackSubstIndex];
2392TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
2397 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2399 return TransformTemplateParmRefExpr(E, NTTP);
2406 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2408 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(PD);
2409 PVD &&
SemaRef.CurrentInstantiationScope &&
2410 (
SemaRef.inConstraintSubstitution() ||
2411 SemaRef.inParameterMappingSubstitution()) &&
2412 maybeInstantiateFunctionParameterToScope(PVD))
2415 return TransformFunctionParmPackRefExpr(E, PD);
2418 return inherited::TransformDeclRefExpr(E);
2421ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2422 CXXDefaultArgExpr *E) {
2424 getDescribedFunctionTemplate() &&
2425 "Default arg expressions are never formed in dependent cases.");
2426 return SemaRef.BuildCXXDefaultArgExpr(
2431template<
typename Fn>
2432QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2433 FunctionProtoTypeLoc TL,
2434 CXXRecordDecl *ThisContext,
2435 Qualifiers ThisTypeQuals,
2436 Fn TransformExceptionSpec) {
2444 LocalInstantiationScope *Current = getSema().CurrentInstantiationScope;
2445 std::optional<LocalInstantiationScope> Scope;
2449 return inherited::TransformFunctionProtoType(
2450 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2453ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2454 ParmVarDecl *OldParm,
int indexAdjustment,
UnsignedOrNone NumExpansions,
2455 bool ExpectParameterPack) {
2456 auto NewParm =
SemaRef.SubstParmVarDecl(
2457 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2458 ExpectParameterPack, EvaluateConstraints);
2459 if (NewParm &&
SemaRef.getLangOpts().OpenCL)
2460 SemaRef.deduceOpenCLAddressSpace(NewParm);
2464QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2465 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
2467 TemplateArgument Arg, SourceLocation NameLoc) {
2472 if (SuppressObjCLifetime) {
2474 RQs = Replacement.getQualifiers();
2477 SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2481 QualType
Result = getSema().Context.getSubstTemplateTypeParmType(
2482 Replacement, AssociatedDecl, Index,
PackIndex, Final);
2483 SubstTemplateTypeParmTypeLoc NewTL =
2484 TLB.
push<SubstTemplateTypeParmTypeLoc>(
Result);
2490TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2491 TemplateTypeParmTypeLoc TL,
2492 bool SuppressObjCLifetime) {
2493 const TemplateTypeParmType *T = TL.
getTypePtr();
2503 IsIncomplete =
true;
2504 if (BailOutOnIncomplete)
2507 TemplateTypeParmTypeLoc NewTL
2508 = TLB.
push<TemplateTypeParmTypeLoc>(TL.
getType());
2513 TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
2518 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2520 "unexpected nontype template argument kind in template rewrite");
2526 auto [AssociatedDecl, Final] =
2529 if (T->isParameterPack() ||
2536 (T->getDecl() && T->getDecl()->isTemplateParameterPack())) {
2538 "Missing argument pack");
2544 QualType
Result = getSema().Context.getSubstTemplateTypeParmPackType(
2545 AssociatedDecl, T->getIndex(), Final, Arg);
2546 SubstTemplateTypeParmPackTypeLoc NewTL
2547 = TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2554 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2558 "Template argument kind mismatch");
2560 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2561 AssociatedDecl, T->getIndex(),
2569 TemplateTypeParmDecl *NewTTPDecl =
nullptr;
2570 if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
2571 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2573 QualType
Result = getSema().Context.getTemplateTypeParmType(
2575 T->isParameterPack(), NewTTPDecl);
2576 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
2581QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2582 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2583 bool SuppressObjCLifetime) {
2584 const SubstTemplateTypeParmPackType *T = TL.
getTypePtr();
2586 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(), T->getAssociatedDecl());
2591 if (NewReplaced != T->getAssociatedDecl())
2592 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2593 NewReplaced, T->getIndex(), T->getFinal(), T->getArgumentPack());
2594 SubstTemplateTypeParmPackTypeLoc NewTL =
2595 TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2600 TemplateArgument Pack = T->getArgumentPack();
2601 TemplateArgument Arg =
SemaRef.getPackSubstitutedTemplateArgument(Pack);
2602 return BuildSubstTemplateTypeParmType(
2603 TLB, SuppressObjCLifetime, T->getFinal(), NewReplaced, T->getIndex(),
2607QualType TemplateInstantiator::TransformSubstBuiltinTemplatePackType(
2608 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
2610 return TreeTransform::TransformSubstBuiltinTemplatePackType(TLB, TL);
2611 TemplateArgument
Result =
SemaRef.getPackSubstitutedTemplateArgument(
2615 return Result.getAsType();
2618static concepts::Requirement::SubstitutionDiagnostic *
2628 ErrorLoc = PDA.first;
2633 llvm::raw_svector_ostream
OS(Entity);
2637 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2640concepts::Requirement::SubstitutionDiagnostic *
2643 llvm::raw_svector_ostream
OS(Entity);
2647 C.backupStr(Entity),
2648 Location, StringRef()};
2651ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2664 if (getDerived().TransformFunctionTypeParams(
2665 KWLoc, Params,
nullptr,
nullptr, PTypes,
2666 &TransParams, PInfos, &ErrorIdx) ||
2667 Trap.hasErrorOccurred()) {
2673 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2674 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2676 TransReqs, RBraceLoc);
2682concepts::TypeRequirement *
2683TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2687 if (AlwaysRebuild())
2688 return RebuildTypeRequirement(
2694 Sema::SFINAETrap Trap(
SemaRef, Info);
2695 Sema::InstantiatingTemplate TypeInst(
2698 if (TypeInst.isInvalid())
2700 TypeSourceInfo *TransType = TransformType(Req->
getType());
2701 if (!TransType || Trap.hasErrorOccurred())
2703 [&] (llvm::raw_ostream&
OS) {
2706 return RebuildTypeRequirement(TransType);
2709concepts::ExprRequirement *
2710TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2714 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2721 Sema::SFINAETrap Trap(
SemaRef, Info);
2724 if (ExprInst.isInvalid())
2727 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2729 TransExprRes =
SemaRef.CheckPlaceholderExpr(TransExprRes.
get());
2730 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2735 TransExpr = TransExprRes.
get();
2738 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2740 if (RetReq.isEmpty())
2741 TransRetReq.emplace();
2742 else if (RetReq.isSubstitutionFailure())
2743 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2744 else if (RetReq.isTypeConstraint()) {
2745 TemplateParameterList *OrigTPL =
2746 RetReq.getTypeConstraintTemplateParameterList();
2748 Sema::SFINAETrap Trap(
SemaRef, Info);
2751 if (TPLInst.isInvalid())
2753 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2754 if (!TPL || Trap.hasErrorOccurred())
2756 [&] (llvm::raw_ostream&
OS) {
2757 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2758 ->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2762 TransRetReq.emplace(TPL);
2765 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2766 if (Expr *E = TransExpr.dyn_cast<Expr *>())
2768 std::move(*TransRetReq));
2769 return RebuildExprRequirement(
2774concepts::NestedRequirement *
2775TemplateInstantiator::TransformNestedRequirement(
2776 concepts::NestedRequirement *Req) {
2781 ConstraintSatisfaction Satisfaction;
2783 auto NestedReqWithDiag = [&
C,
this](Expr *E,
2784 ConstraintSatisfaction Satisfaction) {
2786 SmallString<128> Entity;
2787 llvm::raw_svector_ostream
OS(Entity);
2788 E->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2789 return new (
C) concepts::NestedRequirement(
2790 SemaRef.Context,
C.backupStr(Entity), std::move(Satisfaction));
2794 if (AlwaysRebuild())
2800 if (!getEvaluateConstraints()) {
2802 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2806 concepts::NestedRequirement(TransConstraint.
get());
2807 ConstraintSatisfaction Satisfaction;
2808 return new (
SemaRef.Context) concepts::NestedRequirement(
2809 SemaRef.Context, TransConstraint.
get(), Satisfaction);
2813 Expr *NewConstraint;
2817 Sema::InstantiatingTemplate ConstrInst(
2819 Sema::InstantiatingTemplate::ConstraintsCheck(),
2822 if (ConstrInst.isInvalid())
2826 Req, AssociatedConstraint(Constraint), TemplateArgs,
2828 nullptr, &NewConstraint);
2832 return NestedReqWithDiag(Constraint, Satisfaction);
2836 if (!NewConstraint) {
2838 return NestedReqWithDiag(Constraint, Satisfaction);
2840 NewConstraint = Constraint;
2842 return new (
C) concepts::NestedRequirement(
C, NewConstraint, Satisfaction);
2848 bool AllowDeducedTST) {
2849 if (!T->getType()->isInstantiationDependentType() &&
2850 !T->getType()->isVariablyModifiedType())
2853 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2854 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
2855 : Instantiator.TransformType(T);
2873 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2887 bool *IsIncompleteSubstitution) {
2890 if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
2893 TemplateInstantiator Instantiator(
2894 *
this, TemplateArgs, Loc, Entity,
2895 IsIncompleteSubstitution !=
nullptr);
2896 QualType QT = Instantiator.TransformType(T);
2897 if (IsIncompleteSubstitution && Instantiator.getIsIncomplete())
2898 *IsIncompleteSubstitution =
true;
2903 if (T->getType()->isInstantiationDependentType() ||
2904 T->getType()->isVariablyModifiedType())
2927 Qualifiers ThisTypeQuals,
bool EvaluateConstraints) {
2931 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2932 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2948 Result = Instantiator.TransformFunctionProtoType(
2949 TLB, Proto, ThisContext, ThisTypeQuals,
2951 bool &Changed) {
return false; });
2953 Result = Instantiator.TransformType(TLB, TL);
2967 bool Changed =
false;
2968 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
2969 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
2980 ESI, ExceptionStorage, Args))
2989 struct GetContainedInventedTypeParmVisitor :
2990 public TypeVisitor<GetContainedInventedTypeParmVisitor,
2991 TemplateTypeParmDecl *> {
2992 using TypeVisitor<GetContainedInventedTypeParmVisitor,
2998 return Visit(T.getTypePtr());
3002 const TemplateTypeParmType *T) {
3003 if (!T->getDecl() || !T->getDecl()->isImplicit())
3005 return T->getDecl();
3011 TemplateTypeParmDecl *VisitPointerType(
const PointerType *T) {
3015 TemplateTypeParmDecl *VisitBlockPointerType(
const BlockPointerType *T) {
3019 TemplateTypeParmDecl *VisitReferenceType(
const ReferenceType *T) {
3023 TemplateTypeParmDecl *VisitMemberPointerType(
const MemberPointerType *T) {
3027 TemplateTypeParmDecl *VisitArrayType(
const ArrayType *T) {
3031 TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
3032 const DependentSizedExtVectorType *T) {
3036 TemplateTypeParmDecl *VisitVectorType(
const VectorType *T) {
3040 TemplateTypeParmDecl *VisitFunctionProtoType(
const FunctionProtoType *T) {
3041 return VisitFunctionType(T);
3044 TemplateTypeParmDecl *VisitFunctionType(
const FunctionType *T) {
3048 TemplateTypeParmDecl *VisitParenType(
const ParenType *T) {
3052 TemplateTypeParmDecl *VisitAttributedType(
const AttributedType *T) {
3053 return Visit(T->getModifiedType());
3056 TemplateTypeParmDecl *VisitMacroQualifiedType(
const MacroQualifiedType *T) {
3060 TemplateTypeParmDecl *VisitAdjustedType(
const AdjustedType *T) {
3064 TemplateTypeParmDecl *VisitPackExpansionType(
const PackExpansionType *T) {
3065 return Visit(T->getPattern());
3074 bool EvaluateConstraints) {
3080 bool ContainsUnexpandedPack =
3084 return TA.getArgument().containsUnexpandedParameterPack();
3086 if (!Index && ContainsUnexpandedPack)
3087 Index =
SemaRef.ArgPackSubstIndex;
3116 bool ExpectParameterPack,
bool EvaluateConstraint) {
3136 }
else if (ExpectParameterPack) {
3142 diag::err_function_parameter_pack_without_parameter_packs)
3166 GetContainedInventedTypeParmVisitor().Visit(OldTSI->
getType())) {
3168 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3173 if (Inst && !Inst->getTypeConstraint()) {
3241 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3243 return Instantiator.TransformFunctionTypeParams(
3244 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3253 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3257 if (AlreadyInstantiating) {
3258 Param->setInvalidDecl();
3259 return Diag(Param->getBeginLoc(), diag::err_recursive_default_argument)
3277 std::optional<LocalInstantiationScope> LIS;
3288 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3305 Param->getLocation(),
3310 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3340 auto ComputeInfo = [&S, &TemplateArgs, BaseSourceRange, BaseEllipsisLoc](
3347 if (IsLateExpansionAttempt) {
3352 return P.first.dyn_cast<
const SubstBuiltinTemplatePackType *>();
3354 if (!SawPackTypes) {
3366 BaseEllipsisLoc, BaseSourceRange, Unexpanded, TemplateArgs,
3371 if (ComputeInfo(
Base.getTypeSourceInfo(),
false, Info))
3375 Out =
Base.getTypeSourceInfo();
3385 if (!Out->getType()->containsUnexpandedParameterPack())
3390 if (ComputeInfo(Out,
true, Info))
3403 for (
const auto &
Base : Pattern->
bases()) {
3404 if (!
Base.getType()->isInstantiationDependentType()) {
3406 if (RD->isInvalidDecl())
3415 if (
Base.isPackExpansion()) {
3427 ArgsForSubst = &EmptyList;
3442 Instantiation,
Base.getSourceRange(),
Base.isVirtual(),
3443 Base.getAccessSpecifierAsWritten(), Expanded,
3445 InstantiatedBases.push_back(InstantiatedBase);
3454 EllipsisLoc =
Base.getEllipsisLoc();
3462 Base.getSourceRange().getBegin(),
3473 Base.getSourceRange(),
3475 Base.getAccessSpecifierAsWritten(),
3478 InstantiatedBases.push_back(InstantiatedBase);
3508 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3511 return InstantiateClassImpl(PointOfInstantiation, Instantiation, Pattern,
3512 TemplateArgs, TSK, Complain);
3515bool Sema::InstantiateClassImpl(
3522 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3524 Pattern, PatternDef, TSK, Complain))
3527 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3528 llvm::TimeTraceMetadata M;
3529 llvm::raw_string_ostream OS(M.Detail);
3532 if (llvm::isTimeTraceVerbose()) {
3533 auto Loc = SourceMgr.getExpansionLoc(Instantiation->
getLocation());
3534 M.File = SourceMgr.getFilename(Loc);
3535 M.Line = SourceMgr.getExpansionLineNumber(Loc);
3540 Pattern = PatternDef;
3543 if (MemberSpecializationInfo *MSInfo
3545 MSInfo->setTemplateSpecializationKind(TSK);
3546 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3547 }
else if (ClassTemplateSpecializationDecl *Spec
3548 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3549 Spec->setTemplateSpecializationKind(TSK);
3550 Spec->setPointOfInstantiation(PointOfInstantiation);
3553 NonSFINAEContext _(*
this);
3554 InstantiatingTemplate Inst(*
this, PointOfInstantiation, Instantiation);
3555 if (Inst.isInvalid())
3557 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3558 "instantiating class definition");
3562 ContextRAII SavedContext(*
this, Instantiation);
3563 EnterExpressionEvaluationContext EvalContext(
3564 *
this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
3570 LocalInstantiationScope Scope(*
this, MergeWithParentScope);
3576 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3579 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3589 Instantiation->
setTagKind(Pattern->getTagKind());
3592 if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
3595 TemplateDeclInstantiator Instantiator(*
this, Instantiation, TemplateArgs);
3596 Instantiator.setEvaluateConstraints(
false);
3597 SmallVector<Decl*, 4> Fields;
3599 LateInstantiatedAttrVec LateAttrs;
3600 Instantiator.enableLateAttributeInstantiation(&LateAttrs);
3602 bool MightHaveConstexprVirtualFunctions =
false;
3603 for (
auto *
Member : Pattern->decls()) {
3613 if (
Member->getDeclContext() != Pattern)
3624 if (
Member->isInvalidDecl()) {
3629 Decl *NewMember = Instantiator.Visit(
Member);
3631 if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3632 Fields.push_back(Field);
3633 }
else if (EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3639 Enum->isCompleteDefinition()) {
3640 MemberSpecializationInfo *MSInfo =
Enum->getMemberSpecializationInfo();
3641 assert(MSInfo &&
"no spec info for member enum specialization");
3645 }
else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
3646 if (SA->isFailed()) {
3652 }
else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3655 MightHaveConstexprVirtualFunctions =
true;
3669 ActOnFields(
nullptr, Instantiation->
getLocation(), Instantiation, Fields,
3670 SourceLocation(), SourceLocation(), ParsedAttributesView());
3671 CheckCompletedCXXClass(
nullptr, Instantiation);
3676 if (ParsingClassDepth == 0)
3677 ActOnFinishCXXNonNestedClass();
3681 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3682 E = LateAttrs.end(); I != E; ++I) {
3683 assert(CurrentInstantiationScope == Instantiator.getStartingScope());
3684 CurrentInstantiationScope = I->Scope;
3688 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3689 CXXThisScopeRAII ThisScope(*
this, ThisContext, Qualifiers(),
3690 ND->isCXXInstanceMember());
3694 if (NewAttr && checkInstantiatedThreadSafetyAttrs(I->NewDecl, NewAttr))
3695 I->NewDecl->addAttr(NewAttr);
3697 Instantiator.getStartingScope());
3699 Instantiator.disableLateAttributeInstantiation();
3702 ActOnFinishDelayedMemberInitializers(Instantiation);
3707 Instantiation->
setLocation(Pattern->getLocation());
3708 Instantiation->
setLocStart(Pattern->getInnerLocStart());
3714 if (Pattern->isDependentContext())
3715 PerformDependentDiagnostics(Pattern, TemplateArgs);
3720 P = Instantiator.delayed_partial_spec_begin(),
3721 PEnd = Instantiator.delayed_partial_spec_end();
3723 if (!Instantiator.InstantiateClassTemplatePartialSpecialization(
3724 P->first, P->second)) {
3733 P = Instantiator.delayed_var_partial_spec_begin(),
3734 PEnd = Instantiator.delayed_var_partial_spec_end();
3736 if (!Instantiator.InstantiateVarTemplatePartialSpecialization(
3737 P->first, P->second)) {
3755 MarkVTableUsed(PointOfInstantiation, Instantiation,
true);
3756 else if (MightHaveConstexprVirtualFunctions)
3757 MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
3761 Consumer.HandleTagDeclDefinition(Instantiation);
3773 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3779 Pattern, PatternDef, TSK,
true))
3781 Pattern = PatternDef;
3795 "instantiating enum definition");
3830 "pattern and instantiation disagree about init style");
3834 if (AlreadyInstantiating)
3836 return Diag(PointOfInstantiation,
3837 diag::err_default_member_initializer_cycle)
3846 Diag(PointOfInstantiation,
3847 diag::err_default_member_initializer_not_yet_parsed)
3848 << OutermostClass << Pattern;
3849 Diag(Pattern->getEndLoc(),
3850 diag::note_default_member_initializer_not_yet_parsed);
3860 "instantiating default member init");
3869 PointOfInstantiation, Instantiation,
CurContext};
3885 L->DefaultMemberInitializerInstantiated(Instantiation);
3894 struct PartialSpecMatchResult {
3939 std::optional<Sema::NonSFINAEContext> NSC(S);
3959 typedef PartialSpecMatchResult MatchResult;
3962 Template->getPartialSpecializations(PartialSpecs);
3975 if (
Template->isMemberSpecialization() &&
3976 !Partial->isMemberSpecialization())
3994 if (Matched.empty() && PrimaryStrictPackMatch)
3995 Matched = std::move(ExtraMatched);
4001 if (Matched.size() >= 1) {
4003 if (Matched.size() == 1) {
4016 PEnd = Matched.end();
4019 P->Partial, Best->Partial, PointOfInstantiation) ==
4028 PEnd = Matched.end();
4031 P->Partial, Best->Partial,
4032 PointOfInstantiation) != Best->Partial) {
4042 S.
Diag(PointOfInstantiation,
4043 diag::err_partial_spec_ordering_ambiguous)
4044 << ClassTemplateSpec;
4048 PEnd = Matched.end();
4050 S.
Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
4052 P->Partial->getTemplateParameters(), *P->Args);
4067 if (
auto *PartialSpec =
4070 while (PartialSpec->getInstantiatedFromMember()) {
4073 if (PartialSpec->isMemberSpecialization())
4076 PartialSpec = PartialSpec->getInstantiatedFromMember();
4078 Pattern = PartialSpec;
4081 while (
Template->getInstantiatedFromMemberTemplate()) {
4084 if (
Template->isMemberSpecialization())
4089 Pattern =
Template->getTemplatedDecl();
4099 bool PrimaryStrictPackMatch) {
4108 if (AlreadyInstantiating)
4111 bool HadAvaibilityWarning =
4117 ClassTemplateSpec, TSK,
4118 PrimaryStrictPackMatch);
4123 bool Err = InstantiateClassImpl(
4124 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4131 if (!Err && !HadAvaibilityWarning) {
4151 "Unexpected template specialization kind!");
4152 for (
auto *D : Instantiation->
decls()) {
4153 bool SuppressNew =
false;
4154 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4156 Function->getInstantiatedFromMemberFunction()) {
4158 if (
Function->getTrailingRequiresClause()) {
4166 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4170 Function->getTemplateSpecializationKind();
4175 PointOfInstantiation, TSK,
Function, PrevTSK,
4176 Function->getPointOfInstantiation(), SuppressNew) ||
4189 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4199 std::make_pair(
Function, PointOfInstantiation));
4202 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4207 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4211 assert(MSInfo &&
"No member specialization information?");
4240 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4241 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4249 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4254 assert(MSInfo &&
"No member specialization information?");
4260 if (
Context.getTargetInfo().getTriple().isOSWindows() &&
4280 assert(Pattern &&
"Missing instantiated-from-template information");
4282 if (!
Record->getDefinition()) {
4303 Record->getTemplateSpecializationKind() ==
4305 Record->setTemplateSpecializationKind(TSK);
4310 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4314 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4316 assert(MSInfo &&
"No member specialization information?");
4323 PointOfInstantiation, TSK,
Enum,
4329 if (
Enum->getDefinition())
4332 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4333 assert(Pattern &&
"Missing instantiated-from-template information");
4344 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4355 ClassPattern->
lookup(Field->getDeclName());
4388 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4391 return Instantiator.TransformStmt(S);
4399 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
4400 return Instantiator.TransformTemplateArgument(Input, Output);
4407 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4409 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4416 TemplateInstantiator Instantiator(
4417 TemplateInstantiator::ForParameterMappingSubstitution, *
this, BaseLoc,
4419 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4427 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4430 return Instantiator.TransformExpr(E);
4439 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4441 return Instantiator.TransformAddressOfOperand(E);
4457 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4459 Instantiator.setEvaluateConstraints(
false);
4460 return Instantiator.TransformExpr(E);
4468 TemplateInstantiator Instantiator(*
this, MLTAL,
SourceLocation(),
4475 if (Instantiator.TransformConceptTemplateArguments(
4500 struct ConstraintExprTransformer :
TreeTransform<ConstraintExprTransformer> {
4512 case Stmt::BinaryOperatorClass:
4513 case Stmt::ConceptSpecializationExprClass:
4514 case Stmt::ParenExprClass:
4515 case Stmt::UnresolvedLookupExprClass:
4516 return Base::TransformExpr(E);
4527 if (!(E->
getOpcode() == BinaryOperatorKind::BO_LAnd ||
4528 E->
getOpcode() == BinaryOperatorKind::BO_LOr))
4545 bool Uneval =
false) {
4547 return Base::TransformTemplateArgument(Input, Output, Uneval);
4554 bool IsAddressOfOperand =
false) {
4555 if (!E->isConceptReference())
4558 assert(E->getNumDecls() == 1 &&
4559 "ConceptReference must have single declaration");
4563 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
4564 unsigned Depth = TTP->getDepth();
4565 unsigned Pos = TTP->getPosition();
4573 if (ResolvedConcept ==
nullptr)
4579 if (TransformTemplateArguments(E->getTemplateArgs(),
4580 E->getNumTemplateArgs(), TransArgs))
4587 ResolvedConcept, ResolvedConcept,
4592 ConstraintExprTransformer Transformer(*
this, MLTALForConstraint);
4594 Transformer.TransformExpr(
const_cast<Expr *
>(ConstraintExpr));
4600 bool CXXDirectInit) {
4601 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4603 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4612 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4615 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4625 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4627 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4633 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4635 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4643 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameLoc,
4645 return Instantiator.TransformTemplateName(QualifierLoc, TemplateKWLoc, Name,
4654 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4655 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4656 unsigned i = PV->getFunctionScopeIndex();
4659 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4660 return FD->getCanonicalDecl()->getParamDecl(i);
4666llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4670 Current = Current->Outer) {
4673 const Decl *CheckD = D;
4675 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4676 if (
Found != Current->LocalDecls.end())
4677 return &
Found->second;
4681 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4688 if (!Current->CombineWithOuterScope)
4695llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4708 if (RD->isLocalClass())
4725 assert(
isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4731 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4732 if (Stored.isNull()) {
4736 while (Current->CombineWithOuterScope && Current->Outer) {
4737 Current = Current->Outer;
4738 assert(!Current->LocalDecls.contains(D) &&
4739 "Instantiated local in inner and outer scopes");
4743 }
else if (
DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(Stored)) {
4746 assert(
cast<Decl *>(Stored) == Inst &&
"Already instantiated this local");
4754 Pack->push_back(Inst);
4761 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4762 assert(!Current->LocalDecls.contains(D) &&
4763 "Creating local pack after instantiation of local");
4767 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4770 ArgumentPacks.push_back(Pack);
4775 if (llvm::is_contained(*Pack, D))
4782 unsigned NumExplicitArgs) {
4783 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4784 "Already have a partially-substituted pack");
4785 assert((!PartiallySubstitutedPack
4786 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4787 "Wrong number of arguments in partially-substituted pack");
4788 PartiallySubstitutedPack = Pack;
4789 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4790 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4795 unsigned *NumExplicitArgs)
const {
4797 *ExplicitArgs =
nullptr;
4798 if (NumExplicitArgs)
4799 *NumExplicitArgs = 0;
4802 Current = Current->Outer) {
4803 if (Current->PartiallySubstitutedPack) {
4805 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4806 if (NumExplicitArgs)
4807 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4809 return Current->PartiallySubstitutedPack;
4812 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.
QualType getOriginalType() const
QualType getElementType() const
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)
QualType getPointeeType() const
Represents a base class of a C++ class.
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXRecordDecl * getDefinition() const
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
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.
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
QualType getElementType() 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.
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.
QualType getUnderlyingType() const
QualType getPointeeType() const
Provides information a specialization of a member of a class template, which may be a member function...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Describes a module or submodule.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
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
QualType getInnerType() 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)
QualType getPointeeType() const
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.
QualType getPointeeTypeAsWritten() const
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
RAII object used to change the argument pack substitution index within a Sema object.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
For a defaulted function, the kind of defaulted function that it is.
DefaultedComparisonKind asComparison() const
bool isSpecialMember() const
bool isComparison() const
CXXSpecialMemberKind asSpecialMember() const
A helper class for building up ExtParameterInfos.
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Sema - This implements semantic analysis and AST building for C.
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, const MultiLevelTemplateArgumentList &TemplateArgs, bool EvaluateConstraint)
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD)
Determine the kind of defaulting that would be done for a given function.
ExprResult SubstConceptTemplateArguments(const ConceptSpecializationExpr *CSE, const Expr *ConstraintExpr, const MultiLevelTemplateArgumentList &MLTAL)
Substitute concept template arguments in the constraint expression of a concept-id.
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
llvm::function_ref< void(SourceLocation, PartialDiagnostic)> InstantiationContextDiagFuncRef
TemplateName SubstTemplateName(SourceLocation TemplateKWLoc, NestedNameSpecifierLoc &QualifierLoc, TemplateName Name, SourceLocation NameLoc, const MultiLevelTemplateArgumentList &TemplateArgs)
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization,...
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
llvm::function_ref< void(llvm::raw_ostream &)> EntityPrinter
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
concepts::Requirement::SubstitutionDiagnostic * createSubstDiagAt(SourceLocation Location, EntityPrinter Printer)
create a Requirement::SubstitutionDiagnostic with only a SubstitutedEntity and DiagLoc using ASTConte...
bool SubstExprs(ArrayRef< Expr * > Exprs, bool IsCall, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< Expr * > &Outputs)
Substitute the given template arguments into a list of expressions, expanding pack expansions if requ...
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain, bool PrimaryStrictPackMatch)
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.
bool isReferenceType() const
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getUnderlyingType() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
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.
QualType getElementType() const
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
bool isExprSubstitutionFailure() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
bool hasInvalidConstraint() const
Expr * getConstraintExpr() const
StringRef getInvalidConstraintEntity()
A static requirement that can be used in a requires-expression to check properties of types and expre...
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Provides information about an attempted template argument deduction, whose success or failure was des...
TemplateArgumentList * takeCanonical()
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
void takeSFINAEDiagnostic(PartialDiagnosticAt &PD)
Take ownership of the SFINAE diagnostic.
bool hasStrictPackMatch() const
Defines the clang::TargetInfo interface.
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)
The JSON file list parser is used to communicate input to InstallAPI.
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
bool isa(CodeGen::Address addr)
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ OK_Ordinary
An ordinary object is located at an address in memory.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool isPackProducingBuiltinTemplateName(TemplateName N)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
OptionalUnsigned< unsigned > UnsignedOrNone
@ 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...
@ 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