36#include "llvm/ADT/SmallVectorExtras.h"
37#include "llvm/ADT/StringExtras.h"
38#include "llvm/Support/ErrorHandling.h"
39#include "llvm/Support/SaveAndRestore.h"
40#include "llvm/Support/TimeProfiler.h"
53 const Decl *NextDecl =
nullptr;
55 bool ClearRelativeToPrimary =
true;
56 static Response Done() {
61 static Response ChangeDecl(
const Decl *ND) {
66 static Response ChangeDecl(
const DeclContext *Ctx) {
72 static Response UseNextDecl(
const Decl *CurDecl) {
76 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
77 Response R = Response::UseNextDecl(CurDecl);
78 R.ClearRelativeToPrimary =
false;
87getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
89 return LambdaCallOperator;
91 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
93 FTD && FTD->getInstantiatedFromMemberTemplate()) {
95 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
102 ->getInstantiatedFromMemberFunction())
103 LambdaCallOperator = Prev;
107 return LambdaCallOperator;
110struct EnclosingTypeAliasTemplateDetails {
120EnclosingTypeAliasTemplateDetails
121getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
124 TypeAliasTemplateInstantiation)
126 EnclosingTypeAliasTemplateDetails Result;
128 *
Next = TATD->getInstantiatedFromMemberTemplate();
132 CSC.template_arguments(),
135 Result.PrimaryTypeAliasDecl =
Next;
136 Next =
Next->getInstantiatedFromMemberTemplate();
149bool isLambdaEnclosedByTypeAliasDecl(
153 Visitor(
const FunctionDecl *CallOperator) : CallOperator(CallOperator) {}
154 bool VisitLambdaExpr(
LambdaExpr *LE)
override {
157 return getPrimaryTemplateOfGenericLambda(LE->getCallOperator()) !=
166 return !Visitor(getPrimaryTemplateOfGenericLambda(LambdaCallOperator))
167 .TraverseType(Underlying);
174 bool SkipForSpecialization) {
178 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
183 return Response::Done();
188 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
191 dyn_cast<VarTemplatePartialSpecializationDecl *>(Specialized)) {
192 if (!SkipForSpecialization)
193 Result.addOuterTemplateArguments(
196 if (Partial->isMemberSpecialization())
197 return Response::Done();
200 if (!SkipForSpecialization)
201 Result.addOuterTemplateArguments(
205 return Response::Done();
207 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
219 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
220 Result.addOuterTemplateArguments(std::nullopt);
221 return Response::Done();
224Response HandlePartialClassTemplateSpec(
227 if (!SkipForSpecialization)
229 return Response::Done();
236 bool SkipForSpecialization) {
241 return Response::Done();
243 if (!SkipForSpecialization)
244 Result.addOuterTemplateArguments(
253 return Response::Done();
259 if (
auto *InstFromPartialTempl =
262 return Response::ChangeDecl(
263 InstFromPartialTempl->getLexicalDeclContext());
265 return Response::UseNextDecl(ClassTemplSpec);
271 bool ForConstraintInstantiation,
272 bool ForDefaultArgumentSubstitution) {
274 if (!RelativeToPrimary &&
275 Function->getTemplateSpecializationKindForInstantiation() ==
277 return Response::Done();
279 if (!RelativeToPrimary &&
284 return Response::UseNextDecl(Function);
286 Function->getTemplateSpecializationArgs()) {
288 Result.addOuterTemplateArguments(
const_cast<FunctionDecl *
>(Function),
289 TemplateArgs->asArray(),
292 if (RelativeToPrimary &&
293 (Function->getTemplateSpecializationKind() ==
295 (Function->getFriendObjectKind() &&
296 !Function->getPrimaryTemplate()->getFriendObjectKind())))
297 return Response::UseNextDecl(Function);
301 assert(Function->getPrimaryTemplate() &&
"No function template?");
302 if (!ForDefaultArgumentSubstitution &&
303 Function->getPrimaryTemplate()->isMemberSpecialization())
304 return Response::Done();
307 if (!ForConstraintInstantiation &&
309 return Response::Done();
311 }
else if (
auto *
Template = Function->getDescribedFunctionTemplate()) {
313 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
314 "Outer template not instantiated?");
315 if (ForConstraintInstantiation) {
323 Result.addOuterTemplateArguments(
Template, Inst.template_arguments(),
334 if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
335 Function->getNonTransparentDeclContext()->isFileContext() &&
337 return Response::ChangeDecl(Function->getLexicalDeclContext());
340 if (ForConstraintInstantiation && Function->getFriendObjectKind())
341 return Response::ChangeDecl(Function->getLexicalDeclContext());
342 return Response::UseNextDecl(Function);
345Response HandleFunctionTemplateDecl(
Sema &SemaRef,
349 Result.addOuterTemplateArguments(
362 Ty = std::exchange(NextTy,
nullptr)) {
365 NextTy = P.getAsType();
366 const auto *TSTy = dyn_cast<TemplateSpecializationType>(Ty);
388 if (TSTy->isCurrentInstantiation()) {
389 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
391 Arguments = CTD->getInjectedTemplateArgs(SemaRef.
Context);
393 dyn_cast<ClassTemplateSpecializationDecl>(RD))
394 Arguments =
Specialization->getTemplateInstantiationArgs().asArray();
396 Result.addOuterTemplateArguments(
397 TSTy->getTemplateName().getAsTemplateDecl(), Arguments,
408 bool ForConstraintInstantiation) {
411 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
412 "Outer template not instantiated?");
413 if (ClassTemplate->isMemberSpecialization())
414 return Response::Done();
415 if (ForConstraintInstantiation)
416 Result.addOuterTemplateArguments(
418 ClassTemplate->getInjectedTemplateArgs(SemaRef.
Context),
425 return Response::Done();
430 if (ForConstraintInstantiation && IsFriend &&
439 return Response::ChangeDecl(LCD);
443 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef);
444 ForConstraintInstantiation &&
TypeAlias) {
447 Result.addOuterTemplateArguments(
TypeAlias.Template,
463 return Response::ChangeDecl(
TypeAlias.Template->getDeclContext());
468 return Response::UseNextDecl(Rec);
471Response HandleImplicitConceptSpecializationDecl(
474 Result.addOuterTemplateArguments(
478 return Response::UseNextDecl(CSD);
481Response HandleGenericDeclContext(
const Decl *CurDecl) {
482 return Response::UseNextDecl(CurDecl);
490 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
491 bool SkipForSpecialization,
bool ForDefaultArgumentSubstitution) {
492 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
497 const Decl *CurDecl = ND;
500 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
510 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
511 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
513 : Response::UseNextDecl(CurDecl).NextDecl;
519 if (
const auto *VarTemplSpec =
520 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
521 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
522 }
else if (
const auto *PartialClassTemplSpec =
523 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
524 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
525 SkipForSpecialization);
526 }
else if (
const auto *ClassTemplSpec =
527 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
528 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
529 SkipForSpecialization);
530 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
531 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
532 ForConstraintInstantiation,
533 ForDefaultArgumentSubstitution);
534 }
else if (
const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
536 ForConstraintInstantiation);
537 }
else if (
const auto *CSD =
538 dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
539 R = HandleImplicitConceptSpecializationDecl(CSD,
Result);
540 }
else if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(CurDecl)) {
541 R = HandleFunctionTemplateDecl(*
this, FTD,
Result);
542 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
543 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
545 R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
546 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
547 R = HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
550 R = HandleGenericDeclContext(CurDecl);
555 if (R.ClearRelativeToPrimary)
556 RelativeToPrimary =
false;
558 CurDecl = R.NextDecl;
603 llvm_unreachable(
"Invalid SynthesisKind!");
614 if (
SemaRef.Diags.hasFatalErrorOccurred() &&
615 SemaRef.hasUncompilableErrorOccurred()) {
628 Inst.InConstraintSubstitution =
630 Inst.InParameterMappingSubstitution =
632 if (!
SemaRef.CodeSynthesisContexts.empty()) {
633 Inst.InConstraintSubstitution |=
634 SemaRef.CodeSynthesisContexts.back().InConstraintSubstitution;
635 Inst.InParameterMappingSubstitution |=
636 SemaRef.CodeSynthesisContexts.back().InParameterMappingSubstitution;
647 PointOfInstantiation, InstantiationRange, Entity) {}
654 PointOfInstantiation, InstantiationRange, Entity) {}
693 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
702 PointOfInstantiation, InstantiationRange, PartialSpec,
nullptr,
711 PointOfInstantiation, InstantiationRange, Param,
nullptr,
721 PointOfInstantiation, InstantiationRange, Param,
Template,
731 PointOfInstantiation, InstantiationRange, Param,
Template,
740 PointOfInstantiation, InstantiationRange, Entity,
749 PointOfInstantiation, InstantiationRange, Param,
Template,
757 PointOfInstantiation, InstantiationRange,
nullptr,
766 PointOfInstantiation, InstantiationRange,
nullptr,
775 PointOfInstantiation, InstantiationRange,
nullptr,
783 PointOfInstantiation, InstantiationRange,
nullptr,
808 PointOfInstantiation, InstantiationRange,
Template) {}
815 PointOfInstantiation, InstantiationRange, Entity) {}
821 ArgLoc, InstantiationRange, PArg) {}
827 assert(
SemaRef.NonInstantiationEntries <=
828 SemaRef.CodeSynthesisContexts.size());
829 if ((
SemaRef.CodeSynthesisContexts.size() -
830 SemaRef.NonInstantiationEntries) >
831 SemaRef.getLangOpts().InstantiationDepth) {
833 diag::err_template_recursion_depth_exceeded)
836 diag::note_template_recursion_depth)
837 <<
SemaRef.getLangOpts().InstantiationDepth;
852 if (!Active.isInstantiationRecord()) {
860 "forgot to remove a lookup module for a template instantiation");
879 SemaRef.popCodeSynthesisContext();
887 llvm::raw_string_ostream
OS(
Result);
888 llvm::ListSeparator Comma;
889 for (
const Expr *Arg : Args) {
891 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
901 llvm::raw_string_ostream
OS(
Result);
902 llvm::ListSeparator Comma;
904 for (
const Expr *Arg : Args) {
906 const char *ValueCategory =
908 : (EVK ==
VK_XValue ?
"xvalue" :
"prvalue"));
909 OS << Comma << ValueCategory <<
" of type '";
920 unsigned Limit =
Diags.getTemplateBacktraceLimit();
922 SkipStart = Limit / 2 + Limit % 2;
927 unsigned InstantiationIdx = 0;
932 ++Active, ++InstantiationIdx) {
934 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
935 if (InstantiationIdx == SkipStart) {
937 DiagFunc(Active->PointOfInstantiation,
938 PDiag(diag::note_instantiation_contexts_suppressed)
944 switch (Active->Kind) {
946 Decl *D = Active->Entity;
948 unsigned DiagID = diag::note_template_member_class_here;
950 DiagID = diag::note_template_class_instantiation_here;
951 DiagFunc(Active->PointOfInstantiation,
952 PDiag(DiagID) <<
Record << Active->InstantiationRange);
956 DiagID = diag::note_function_template_spec_here;
958 DiagID = diag::note_template_member_function_here;
959 DiagFunc(Active->PointOfInstantiation,
961 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
962 DiagFunc(Active->PointOfInstantiation,
963 PDiag(VD->isStaticDataMember()
964 ? diag::note_template_static_data_member_def_here
965 : diag::note_template_variable_def_here)
966 << VD << Active->InstantiationRange);
967 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
968 DiagFunc(Active->PointOfInstantiation,
969 PDiag(diag::note_template_enum_def_here)
970 << ED << Active->InstantiationRange);
971 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
972 DiagFunc(Active->PointOfInstantiation,
973 PDiag(diag::note_template_nsdmi_here)
974 << FD << Active->InstantiationRange);
976 DiagFunc(Active->PointOfInstantiation,
977 PDiag(diag::note_template_class_instantiation_here)
978 << CTD << Active->InstantiationRange);
986 llvm::raw_svector_ostream
OS(TemplateArgsStr);
988 printTemplateArgumentList(
OS, Active->template_arguments(),
990 DiagFunc(Active->PointOfInstantiation,
991 PDiag(diag::note_default_arg_instantiation_here)
992 <<
OS.str() << Active->InstantiationRange);
998 DiagFunc(Active->PointOfInstantiation,
999 PDiag(diag::note_explicit_template_arg_substitution_here)
1003 Active->NumTemplateArgs)
1004 << Active->InstantiationRange);
1010 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1012 Active->PointOfInstantiation,
1013 PDiag(diag::note_function_template_deduction_instantiation_here)
1016 FnTmpl->getTemplateParameters(), Active->TemplateArgs,
1017 Active->NumTemplateArgs)
1018 << Active->InstantiationRange);
1022 bool IsTemplate =
false;
1024 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1026 Params = D->getTemplateParameters();
1027 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1029 Params = D->getTemplateParameters();
1030 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1032 Params = D->getTemplateParameters();
1034 llvm_unreachable(
"unexpected template kind");
1037 DiagFunc(Active->PointOfInstantiation,
1038 PDiag(diag::note_deduced_template_arg_substitution_here)
1041 Active->TemplateArgs,
1042 Active->NumTemplateArgs)
1043 << Active->InstantiationRange);
1053 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1055 printTemplateArgumentList(
OS, Active->template_arguments(),
1057 DiagFunc(Active->PointOfInstantiation,
1058 PDiag(diag::note_default_function_arg_instantiation_here)
1059 <<
OS.str() << Active->InstantiationRange);
1067 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1071 TemplateParams =
Template->getTemplateParameters();
1075 ->getTemplateParameters();
1076 DiagFunc(Active->PointOfInstantiation,
1077 PDiag(diag::note_prior_template_arg_substitution)
1080 Active->TemplateArgs,
1081 Active->NumTemplateArgs)
1082 << Active->InstantiationRange);
1089 TemplateParams =
Template->getTemplateParameters();
1093 ->getTemplateParameters();
1095 DiagFunc(Active->PointOfInstantiation,
1096 PDiag(diag::note_template_default_arg_checking)
1098 Active->TemplateArgs,
1099 Active->NumTemplateArgs)
1100 << Active->InstantiationRange);
1105 DiagFunc(Active->PointOfInstantiation,
1106 PDiag(diag::note_evaluating_exception_spec_here)
1111 DiagFunc(Active->PointOfInstantiation,
1112 PDiag(diag::note_template_exception_spec_instantiation_here)
1114 << Active->InstantiationRange);
1118 DiagFunc(Active->PointOfInstantiation,
1119 PDiag(diag::note_template_requirement_instantiation_here)
1120 << Active->InstantiationRange);
1123 DiagFunc(Active->PointOfInstantiation,
1124 PDiag(diag::note_template_requirement_params_instantiation_here)
1125 << Active->InstantiationRange);
1129 DiagFunc(Active->PointOfInstantiation,
1130 PDiag(diag::note_nested_requirement_here)
1131 << Active->InstantiationRange);
1135 DiagFunc(Active->PointOfInstantiation,
1136 PDiag(diag::note_in_declaration_of_implicit_special_member)
1138 << Active->SpecialMember);
1143 Active->Entity->getLocation(),
1144 PDiag(diag::note_in_declaration_of_implicit_equality_comparison));
1150 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1158 DiagFunc(Active->PointOfInstantiation,
1159 PDiag(diag::note_member_synthesized_at)
1161 <<
Context.getCanonicalTagType(MD->getParent()));
1163 QualType RecordType = FD->getParamDecl(0)
1165 .getNonReferenceType()
1166 .getUnqualifiedType();
1167 DiagFunc(Active->PointOfInstantiation,
1168 PDiag(diag::note_comparison_synthesized_at)
1175 DiagFunc(Active->Entity->getLocation(),
1176 PDiag(diag::note_rewriting_operator_as_spaceship));
1180 DiagFunc(Active->PointOfInstantiation,
1181 PDiag(diag::note_in_binding_decl_init)
1186 DiagFunc(Active->PointOfInstantiation,
1187 PDiag(diag::note_due_to_dllexported_class)
1193 DiagFunc(Active->PointOfInstantiation,
1194 PDiag(diag::note_building_builtin_dump_struct_call)
1197 Active->NumCallArgs)));
1204 DiagFunc(Active->PointOfInstantiation,
1205 PDiag(diag::note_lambda_substitution_here));
1208 unsigned DiagID = 0;
1209 if (!Active->Entity) {
1210 DiagFunc(Active->PointOfInstantiation,
1211 PDiag(diag::note_nested_requirement_here)
1212 << Active->InstantiationRange);
1216 DiagID = diag::note_concept_specialization_here;
1218 DiagID = diag::note_checking_constraints_for_template_id_here;
1220 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1222 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1225 DiagID = diag::note_checking_constraints_for_function_here;
1228 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1231 printTemplateArgumentList(
OS, Active->template_arguments(),
1234 DiagFunc(Active->PointOfInstantiation,
1235 PDiag(DiagID) <<
OS.str() << Active->InstantiationRange);
1239 DiagFunc(Active->PointOfInstantiation,
1240 PDiag(diag::note_constraint_substitution_here)
1241 << Active->InstantiationRange);
1244 DiagFunc(Active->PointOfInstantiation,
1245 PDiag(diag::note_parameter_mapping_substitution_here)
1246 << Active->InstantiationRange);
1249 DiagFunc(Active->PointOfInstantiation,
1250 PDiag(diag::note_building_deduction_guide_here));
1257 if (Active->NumTemplateArgs == 0)
1259 DiagFunc(Active->PointOfInstantiation,
1260 PDiag(diag::note_template_type_alias_instantiation_here)
1262 << Active->InstantiationRange);
1265 DiagFunc(Active->PointOfInstantiation,
1266 PDiag(diag::note_template_arg_template_params_mismatch));
1269 DiagFunc(ParamLoc,
PDiag(diag::note_template_prev_declaration)
1271 << Active->InstantiationRange);
1274 const auto *SKEPAttr =
1275 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1276 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1277 assert(!SKEPAttr->isInvalidAttr() &&
1278 "sycl_kernel_entry_point attribute is invalid");
1279 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1280 DiagFunc(SKEPAttr->getLocation(),
1281 PDiag(diag::note_sycl_kernel_launch_lookup_here)
1282 << SKEPAttr->getKernelName());
1286 const auto *SKEPAttr =
1287 Active->Entity->getAttr<SYCLKernelEntryPointAttr>();
1288 assert(SKEPAttr &&
"Missing sycl_kernel_entry_point attribute");
1289 assert(!SKEPAttr->isInvalidAttr() &&
1290 "sycl_kernel_entry_point attribute is invalid");
1291 DiagFunc(SKEPAttr->getLocation(),
PDiag(diag::note_sycl_runtime_defect));
1292 DiagFunc(SKEPAttr->getLocation(),
1293 PDiag(diag::note_sycl_kernel_launch_overload_resolution_here)
1294 << SKEPAttr->getKernelName()
1297 Active->NumCallArgs)));
1301 Diags.Report(Active->PointOfInstantiation,
1302 diag::note_expansion_stmt_instantiation_here);
1312 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1317 bool EvaluateConstraints =
true;
1318 bool EvaluateLambdaConstraint =
false;
1321 bool IsIncomplete =
false;
1323 bool BailOutOnIncomplete;
1325 std::optional<llvm::FoldingSetNodeID> TemplateArgsHashValue;
1330 bool maybeInstantiateFunctionParameterToScope(
ParmVarDecl *OldParm);
1335 TemplateInstantiator(
Sema &SemaRef,
1338 bool BailOutOnIncomplete =
false)
1339 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1340 Entity(Entity), BailOutOnIncomplete(BailOutOnIncomplete) {
1343 "Cannot perform an instantiation without some context on the "
1344 "instantiation stack");
1347 void setEvaluateConstraints(
bool B) {
1348 EvaluateConstraints = B;
1350 bool getEvaluateConstraints() {
1351 return EvaluateConstraints;
1354 inline static struct ForParameterMappingSubstitution_t {
1355 } ForParameterMappingSubstitution;
1357 inline static struct ForConstraintSubstitution_t {
1358 } ForConstraintSubstitution;
1360 TemplateInstantiator(ForParameterMappingSubstitution_t, Sema &SemaRef,
1362 const MultiLevelTemplateArgumentList &TemplateArgs)
1363 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1364 EvaluateLambdaConstraint(
true), BailOutOnIncomplete(
false) {
1367 auto &
V = TemplateArgsHashValue.emplace();
1369 for (
auto &Arg :
Level.Args)
1373 TemplateInstantiator(ForConstraintSubstitution_t, Sema &SemaRef,
1374 const MultiLevelTemplateArgumentList &TemplateArgs,
1375 SourceLocation Loc, DeclarationName Entity,
1376 bool BailOutOnIncomplete =
false)
1377 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1378 EvaluateLambdaConstraint(
true), BailOutOnIncomplete(
false) {}
1385 bool AlreadyTransformed(QualType
T);
1388 SourceLocation getBaseLocation() {
return Loc; }
1391 DeclarationName getBaseEntity() {
return Entity; }
1394 bool getIsIncomplete()
const {
return IsIncomplete; }
1398 void setBase(SourceLocation Loc, DeclarationName Entity) {
1400 this->Entity = Entity;
1403 unsigned TransformTemplateDepth(
unsigned Depth) {
1404 return TemplateArgs.getNewDepth(Depth);
1407 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1408 SourceRange PatternRange,
1409 ArrayRef<UnexpandedParameterPack> Unexpanded,
1410 bool FailOnPackProducingTemplates,
1411 bool &ShouldExpand,
bool &RetainExpansion,
1417 NamedDecl *VD = ParmPack.first.dyn_cast<NamedDecl *>();
1418 if (
auto *PVD = dyn_cast_if_present<ParmVarDecl>(VD);
1419 PVD && maybeInstantiateFunctionParameterToScope(PVD))
1424 return getSema().CheckParameterPacksForExpansion(
1425 EllipsisLoc, PatternRange, Unexpanded, TemplateArgs,
1426 FailOnPackProducingTemplates, ShouldExpand, RetainExpansion,
1430 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1434 TemplateArgument ForgetPartiallySubstitutedPack() {
1438 MultiLevelTemplateArgumentList &TemplateArgs =
1439 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1440 unsigned Depth, Index;
1443 Result = TemplateArgs(Depth, Index);
1444 TemplateArgs.
setArgument(Depth, Index, TemplateArgument());
1446 IsIncomplete =
true;
1447 if (BailOutOnIncomplete)
1448 return TemplateArgument();
1455 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1461 MultiLevelTemplateArgumentList &TemplateArgs =
1462 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1463 unsigned Depth, Index;
1469 MultiLevelTemplateArgumentList ForgetSubstitution() {
1470 MultiLevelTemplateArgumentList
New;
1473 MultiLevelTemplateArgumentList Old =
1474 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs);
1475 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1480 void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
1481 const_cast<MultiLevelTemplateArgumentList &
>(this->TemplateArgs) =
1486 getTemplateArgumentPackPatternForRewrite(
const TemplateArgument &TA) {
1492 "unexpected pack arguments in template rewrite");
1501 Decl *TransformDecl(SourceLocation Loc, Decl *D);
1503 void transformAttrs(Decl *Old, Decl *
New) {
1507 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1509 (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) {
1511 for (
auto *
New : NewDecls)
1517 assert(NewDecls.size() == 1 &&
1518 "should only have multiple expansions for a pack");
1524 auto *NewMD = dyn_cast<CXXMethodDecl>(
New);
1526 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1527 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1528 NewTD->setInstantiatedFromMemberTemplate(
1529 OldMD->getDescribedFunctionTemplate());
1531 NewMD->setInstantiationOfMemberFunction(OldMD,
1539 if (
auto *DC = dyn_cast<DeclContext>(Old);
1540 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1546 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1550 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1552 bool TransformExceptionSpec(SourceLocation Loc,
1553 FunctionProtoType::ExceptionSpecInfo &ESI,
1554 SmallVectorImpl<QualType> &Exceptions,
1559 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1560 TypeSourceInfo *Declarator,
1561 SourceLocation StartLoc,
1562 SourceLocation NameLoc,
1563 IdentifierInfo *Name);
1567 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1568 TypeSourceInfo *TSInfo, QualType
T);
1571 TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc,
1573 SourceLocation NameLoc,
1574 QualType ObjectType = QualType(),
1575 NamedDecl *FirstQualifierInScope =
nullptr,
1576 bool AllowInjectedClassName =
false);
1578 const AnnotateAttr *TransformAnnotateAttr(
const AnnotateAttr *AA);
1579 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1580 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1581 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1583 const NoInlineAttr *A);
1584 const AlwaysInlineAttr *
1585 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1586 const AlwaysInlineAttr *A);
1587 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1588 const OpenACCRoutineDeclAttr *
1589 TransformOpenACCRoutineDeclAttr(
const OpenACCRoutineDeclAttr *A);
1590 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1591 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1592 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1594 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1595 NonTypeTemplateParmDecl *D);
1598 ExprResult RebuildVarDeclRefExpr(ValueDecl *PD, SourceLocation Loc);
1601 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, ValueDecl *PD);
1606 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1608 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1609 FunctionProtoTypeLoc TL) {
1611 return inherited::TransformFunctionProtoType(TLB, TL);
1614 QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL) {
1615 auto Type = inherited::TransformTagType(TLB, TL);
1621 if (
const auto *ICNT = dyn_cast<InjectedClassNameType>(TL.
getTypePtr());
1624 Type = inherited::TransformType(
1625 ICNT->getDecl()->getCanonicalTemplateSpecializationType(
1635 bool TransformTemplateArgument(
const TemplateArgumentLoc &Input,
1636 TemplateArgumentLoc &Output,
1637 bool Uneval =
false) {
1638 const TemplateArgument &Arg = Input.
getArgument();
1640 Cache && TemplateArgsHashValue) {
1641 llvm::FoldingSetNodeID
ID = *TemplateArgsHashValue;
1651 if (
auto Iter =
Cache->find(ID); Iter !=
Cache->end()) {
1652 Output = Iter->second;
1655 bool Ret = inherited::TransformTemplateArgument(Input, Output, Uneval);
1662 std::vector<TemplateArgument> TArgs;
1670 pack, QualType(), SourceLocation{});
1671 TemplateArgumentLoc Output;
1672 if (TransformTemplateArgument(Input, Output, Uneval))
1677 TemplateArgument(llvm::ArrayRef(TArgs).copy(SemaRef.
Context)),
1678 QualType(), SourceLocation{});
1684 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1689 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
1690 TemplateSpecializationTypeLoc TL) {
1692 if (!getSema().ArgPackSubstIndex || !
T->
isSugared() ||
1702 QualType
R = TransformType(
T->
desugar());
1708 ArrayRef<TemplateArgument> PackArgs) {
1719 return std::nullopt;
1721 return inherited::ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1724 template<
typename Fn>
1725 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1726 FunctionProtoTypeLoc TL,
1727 CXXRecordDecl *ThisContext,
1728 Qualifiers ThisTypeQuals,
1729 Fn TransformExceptionSpec);
1731 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1732 int indexAdjustment,
1734 bool ExpectParameterPack);
1736 using inherited::TransformTemplateTypeParmType;
1739 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1740 TemplateTypeParmTypeLoc TL,
1741 bool SuppressObjCLifetime);
1743 QualType BuildSubstTemplateTypeParmType(
1744 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
1746 TemplateArgument Arg, SourceLocation NameLoc);
1751 using inherited::TransformSubstTemplateTypeParmPackType;
1753 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1754 SubstTemplateTypeParmPackTypeLoc TL,
1755 bool SuppressObjCLifetime);
1757 TransformSubstBuiltinTemplatePackType(TypeLocBuilder &TLB,
1758 SubstBuiltinTemplatePackTypeLoc TL);
1761 ComputeLambdaDependency(LambdaScopeInfo *LSI) {
1763 TemplateInstArgsHelpers::getEnclosingTypeAliasTemplateDecl(
1765 TypeAlias && TemplateInstArgsHelpers::isLambdaEnclosedByTypeAliasDecl(
1767 unsigned TypeAliasDeclDepth =
TypeAlias.Template->getTemplateDepth();
1769 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1770 for (
const TemplateArgument &TA :
TypeAlias.AssociatedTemplateArguments)
1772 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1774 if (
auto *CD = dyn_cast_if_present<ImplicitConceptSpecializationDecl>(
1776 if (llvm::any_of(CD->getTemplateArguments(),
1777 [](
const auto &TA) { return TA.isDependent(); }))
1778 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1780 return inherited::ComputeLambdaDependency(LSI);
1783 ExprResult TransformLambdaConstraint(Expr *AC) {
1784 if (AC && EvaluateLambdaConstraint)
1785 return TransformExpr(
const_cast<Expr *
>(AC));
1795 LocalInstantiationScope Scope(SemaRef,
true,
1797 llvm::SaveAndRestore RAII(EvaluateConstraints, EvaluateLambdaConstraint);
1799 return inherited::TransformLambdaExpr(E);
1802 ExprResult TransformBlockExpr(BlockExpr *E) {
1803 LocalInstantiationScope Scope(SemaRef,
true,
1805 return inherited::TransformBlockExpr(E);
1808 ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
1809 LambdaScopeInfo *LSI) {
1812 assert(PVD &&
"null in a parameter list");
1813 if (!PVD->hasDefaultArg())
1815 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1817 SourceLocation EqualLoc = UninstExpr->
getBeginLoc();
1826 PVD->setDefaultArg(ErrorResult.
get());
1829 return inherited::RebuildLambdaExpr(StartLoc, EndLoc, LSI);
1842 llvm::SaveAndRestore _(EvaluateConstraints,
true);
1843 return inherited::TransformLambdaBody(E, Body);
1847 LocalInstantiationScope Scope(SemaRef,
true);
1848 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1851 assert(TransReq.
get() != E &&
1852 "Do not change value of isSatisfied for the existing expression. "
1853 "Create a new expression instead.");
1855 Sema::SFINAETrap Trap(SemaRef);
1860 if (Trap.hasErrorOccurred())
1866 bool TransformRequiresExprRequirements(
1867 ArrayRef<concepts::Requirement *> Reqs,
1868 SmallVectorImpl<concepts::Requirement *> &Transformed) {
1869 bool SatisfactionDetermined =
false;
1870 for (concepts::Requirement *Req : Reqs) {
1871 concepts::Requirement *TransReq =
nullptr;
1872 if (!SatisfactionDetermined) {
1873 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1874 TransReq = TransformTypeRequirement(TypeReq);
1875 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1876 TransReq = TransformExprRequirement(ExprReq);
1878 TransReq = TransformNestedRequirement(
1888 SatisfactionDetermined =
true;
1891 Transformed.push_back(TransReq);
1896 TemplateParameterList *TransformTemplateParameterList(
1897 TemplateParameterList *OrigTPL) {
1898 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1901 TemplateDeclInstantiator DeclInstantiator(getSema(),
1904 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1905 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1908 concepts::TypeRequirement *
1909 TransformTypeRequirement(concepts::TypeRequirement *Req);
1910 concepts::ExprRequirement *
1911 TransformExprRequirement(concepts::ExprRequirement *Req);
1912 concepts::NestedRequirement *
1913 TransformNestedRequirement(concepts::NestedRequirement *Req);
1915 SourceLocation KWLoc, SourceLocation RBraceLoc,
const RequiresExpr *RE,
1916 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params,
1917 SmallVectorImpl<QualType> &PTypes,
1918 SmallVectorImpl<ParmVarDecl *> &TransParams,
1919 Sema::ExtParameterInfoBuilder &PInfos);
1921 ExprResult TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1923 if (
Ret.isInvalid())
1925 QualType
T =
Ret.get()->getType();
1929 if (DestDecl && DestDecl->isEffectivelyFinal())
1930 getSema().MarkVTableUsed(
Ret.get()->getExprLoc(), DestDecl);
1936bool TemplateInstantiator::AlreadyTransformed(QualType
T) {
1944 getSema().MarkDeclarationsReferencedInType(Loc,
T);
1948Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1952 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1959 TTP->getPosition())) {
1960 IsIncomplete =
true;
1961 return BailOutOnIncomplete ?
nullptr : D;
1964 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1966 if (TTP->isParameterPack()) {
1968 "Missing argument pack");
1969 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
1974 "Wrong kind of template template argument");
1975 return Template.getAsTemplateDecl();
1982 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(D);
1983 PVD &&
SemaRef.CurrentInstantiationScope &&
1984 (
SemaRef.inConstraintSubstitution() ||
1985 SemaRef.inParameterMappingSubstitution()) &&
1986 maybeInstantiateFunctionParameterToScope(PVD))
1990 assert(
SemaRef.CurrentInstantiationScope);
1992 *
SemaRef.CurrentInstantiationScope->findInstantiationOf(D));
1998bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
1999 ParmVarDecl *OldParm) {
2000 if (
SemaRef.CurrentInstantiationScope->getInstantiationOfIfExists(OldParm))
2004 return !TransformFunctionTypeParam(OldParm, 0,
2008 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2012 PackExpansionTypeLoc ExpansionTL = TL.
castAs<PackExpansionTypeLoc>();
2014 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
2015 assert(!Unexpanded.empty() &&
"Pack expansion without parameter packs?");
2017 bool ShouldExpand =
false;
2018 bool RetainExpansion =
false;
2020 ExpansionTL.
getTypePtr()->getNumExpansions();
2023 Pattern.getSourceRange(), Unexpanded,
2025 ShouldExpand, RetainExpansion, NumExpansions))
2028 assert(ShouldExpand && !RetainExpansion &&
2029 "Shouldn't preserve pack expansion when evaluating constraints");
2030 ExpandingFunctionParameterPack(OldParm);
2031 for (
unsigned I = 0; I != *NumExpansions; ++I) {
2032 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
2033 if (!TransformFunctionTypeParam(OldParm, 0,
2041Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
2042 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
2046 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2050bool TemplateInstantiator::TransformExceptionSpec(
2051 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
2052 SmallVectorImpl<QualType> &Exceptions,
bool &Changed) {
2057 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
2061TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
2062 SourceLocation Loc) {
2065 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
2066 const TemplateTypeParmType *TTP
2071 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
2073 if (TTP->isParameterPack()) {
2075 "Missing argument pack");
2080 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2085 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2087 if (
const TagType *Tag =
T->
getAs<TagType>())
2088 return Tag->getDecl();
2091 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
2096 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
2100TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
2101 TypeSourceInfo *Declarator,
2102 SourceLocation StartLoc,
2103 SourceLocation NameLoc,
2104 IdentifierInfo *Name) {
2105 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
2106 StartLoc, NameLoc, Name);
2108 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2112VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
2113 TypeSourceInfo *TSInfo,
2115 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
2117 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
2121TemplateName TemplateInstantiator::TransformTemplateName(
2122 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
2123 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
2124 NamedDecl *FirstQualifierInScope,
bool AllowInjectedClassName) {
2126 assert(!QualifierLoc &&
"Unexpected qualifier");
2129 TTP && TTP->getDepth() < TemplateArgs.
getNumLevels()) {
2135 TTP->getPosition())) {
2136 IsIncomplete =
true;
2140 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
2145 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2147 "unexpected nontype template argument kind in template rewrite");
2151 auto [AssociatedDecl, Final] =
2154 if (TTP->isParameterPack()) {
2156 "Missing argument pack");
2162 return getSema().Context.getSubstTemplateTemplateParmPack(
2163 Arg, AssociatedDecl, TTP->getIndex(), Final);
2167 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2171 assert(!
Template.isNull() &&
"Null template template argument");
2172 return getSema().Context.getSubstTemplateTemplateParm(
2177 if (SubstTemplateTemplateParmPackStorage *SubstPack
2182 TemplateArgument Pack = SubstPack->getArgumentPack();
2184 SemaRef.getPackSubstitutedTemplateArgument(Pack).getAsTemplate();
2185 return getSema().Context.getSubstTemplateTemplateParm(
2186 Template, SubstPack->getAssociatedDecl(), SubstPack->getIndex(),
2187 SemaRef.getPackIndex(Pack), SubstPack->getFinal());
2190 return inherited::TransformTemplateName(
2191 QualifierLoc, TemplateKWLoc, Name, NameLoc, ObjectType,
2192 FirstQualifierInScope, AllowInjectedClassName);
2196TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
2204TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
2205 NonTypeTemplateParmDecl *NTTP) {
2215 IsIncomplete =
true;
2216 return BailOutOnIncomplete ?
ExprError() : E;
2224 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2226 "unexpected nontype template argument kind in template rewrite");
2239 assert(!ParamType.
isNull() &&
"Shouldn't substitute to an invalid type");
2241 auto [AssociatedDecl, Final] =
2261 return new (
SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
2266 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2268 return SemaRef.BuildSubstNonTypeTemplateParmExpr(
2274TemplateInstantiator::TransformAnnotateAttr(
const AnnotateAttr *AA) {
2275 SmallVector<Expr *> Args;
2276 for (Expr *Arg : AA->args()) {
2277 ExprResult Res = getDerived().TransformExpr(Arg);
2279 Args.push_back(Res.
get());
2281 return AnnotateAttr::CreateImplicit(getSema().
Context, AA->getAnnotation(),
2282 Args.data(), Args.size(), AA->getRange());
2285const CXXAssumeAttr *
2286TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2287 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2291 if (!(Res.
get()->
getDependence() & ExprDependence::TypeValueInstantiation)) {
2292 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2298 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2303TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2304 ExprResult TransformedExprResult = getDerived().TransformExpr(LH->getValue());
2305 if (!TransformedExprResult.
isUsable() ||
2306 TransformedExprResult.
get() == LH->getValue())
2308 Expr *TransformedExpr = TransformedExprResult.
get();
2312 LH->getSemanticSpelling() ==
2313 LoopHintAttr::Pragma_unroll))
2316 LoopHintAttr::OptionType Option = LH->getOption();
2317 LoopHintAttr::LoopHintState State = LH->getState();
2324 if (Option == LoopHintAttr::UnrollCount &&
2326 llvm::APSInt ValueAPS =
2330 if (ValueAPS.isZero() || ValueAPS.isOne()) {
2331 Option = LoopHintAttr::Unroll;
2332 State = LoopHintAttr::Disable;
2338 return LoopHintAttr::CreateImplicit(getSema().
Context, Option, State,
2339 TransformedExpr, *LH);
2341const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2342 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2348const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2349 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2356const CodeAlignAttr *
2357TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2358 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2359 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2361const OpenACCRoutineDeclAttr *
2362TemplateInstantiator::TransformOpenACCRoutineDeclAttr(
2363 const OpenACCRoutineDeclAttr *A) {
2364 llvm_unreachable(
"RoutineDecl should only be a declaration attribute, as it "
2365 "applies to a Function Decl (and a few places for VarDecl)");
2368ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(ValueDecl *PD,
2369 SourceLocation Loc) {
2370 DeclarationNameInfo NameInfo(PD->
getDeclName(), Loc);
2371 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
2375TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
2379 ValueDecl *VD = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), D));
2382 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2385 QualType
T = TransformType(E->
getType());
2391 SmallVector<ValueDecl *, 8> Vars;
2395 ValueDecl *D = cast_or_null<ValueDecl>(TransformDecl(E->
getExprLoc(), *I));
2404 getSema().MarkFunctionParmPackReferenced(PackExpr);
2409TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
2412 llvm::PointerUnion<Decl *, DeclArgumentPack *> *
Found =
2413 getSema().CurrentInstantiationScope->getInstantiationOfIfExists(PD);
2420 Decl *TransformedDecl;
2421 if (DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(*
Found)) {
2425 QualType
T = TransformType(E->
getType());
2430 getSema().MarkFunctionParmPackReferenced(PackExpr);
2434 TransformedDecl = (*Pack)[*getSema().ArgPackSubstIndex];
2445TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
2450 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
2452 return TransformTemplateParmRefExpr(E, NTTP);
2459 if (VarDecl *PD = dyn_cast<VarDecl>(D))
2461 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(PD);
2462 PVD &&
SemaRef.CurrentInstantiationScope &&
2463 (
SemaRef.inConstraintSubstitution() ||
2464 SemaRef.inParameterMappingSubstitution()) &&
2465 maybeInstantiateFunctionParameterToScope(PVD))
2468 return TransformFunctionParmPackRefExpr(E, PD);
2471 return inherited::TransformDeclRefExpr(E);
2474ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2475 CXXDefaultArgExpr *E) {
2477 getDescribedFunctionTemplate() &&
2478 "Default arg expressions are never formed in dependent cases.");
2479 return SemaRef.BuildCXXDefaultArgExpr(
2484template<
typename Fn>
2485QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
2486 FunctionProtoTypeLoc TL,
2487 CXXRecordDecl *ThisContext,
2488 Qualifiers ThisTypeQuals,
2489 Fn TransformExceptionSpec) {
2497 LocalInstantiationScope *Current = getSema().CurrentInstantiationScope;
2498 std::optional<LocalInstantiationScope> Scope;
2502 return inherited::TransformFunctionProtoType(
2503 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2506ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2507 ParmVarDecl *OldParm,
int indexAdjustment,
UnsignedOrNone NumExpansions,
2508 bool ExpectParameterPack) {
2509 auto NewParm =
SemaRef.SubstParmVarDecl(
2510 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2511 ExpectParameterPack, EvaluateConstraints);
2512 if (NewParm &&
SemaRef.getLangOpts().OpenCL)
2513 SemaRef.deduceOpenCLAddressSpace(NewParm);
2517QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2518 TypeLocBuilder &TLB,
bool SuppressObjCLifetime,
bool Final,
2520 TemplateArgument Arg, SourceLocation NameLoc) {
2525 if (SuppressObjCLifetime) {
2527 RQs = Replacement.getQualifiers();
2530 SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2534 QualType
Result = getSema().Context.getSubstTemplateTypeParmType(
2535 Replacement, AssociatedDecl, Index,
PackIndex, Final);
2536 SubstTemplateTypeParmTypeLoc NewTL =
2537 TLB.
push<SubstTemplateTypeParmTypeLoc>(
Result);
2543TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2544 TemplateTypeParmTypeLoc TL,
2545 bool SuppressObjCLifetime) {
2556 IsIncomplete =
true;
2557 if (BailOutOnIncomplete)
2560 TemplateTypeParmTypeLoc NewTL
2561 = TLB.
push<TemplateTypeParmTypeLoc>(TL.
getType());
2566 TemplateArgument Arg = TemplateArgs(
T->getDepth(),
T->getIndex());
2571 Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2573 "unexpected nontype template argument kind in template rewrite");
2579 auto [AssociatedDecl, Final] =
2582 if (
T->isParameterPack() ||
2589 (
T->getDecl() &&
T->getDecl()->isTemplateParameterPack())) {
2591 "Missing argument pack");
2597 QualType
Result = getSema().Context.getSubstTemplateTypeParmPackType(
2598 AssociatedDecl,
T->getIndex(), Final, Arg);
2599 SubstTemplateTypeParmPackTypeLoc NewTL
2600 = TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2607 Arg =
SemaRef.getPackSubstitutedTemplateArgument(Arg);
2611 "Template argument kind mismatch");
2613 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2614 AssociatedDecl,
T->getIndex(),
2622 TemplateTypeParmDecl *NewTTPDecl =
nullptr;
2623 if (TemplateTypeParmDecl *OldTTPDecl =
T->getDecl())
2624 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2626 QualType
Result = getSema().Context.getTemplateTypeParmType(
2630 T->getIndex(),
T->isParameterPack(), NewTTPDecl);
2631 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
2636QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2637 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
2638 bool SuppressObjCLifetime) {
2639 const SubstTemplateTypeParmPackType *
T = TL.
getTypePtr();
2641 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2646 if (NewReplaced !=
T->getAssociatedDecl())
2647 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2648 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2649 SubstTemplateTypeParmPackTypeLoc NewTL =
2650 TLB.
push<SubstTemplateTypeParmPackTypeLoc>(
Result);
2655 TemplateArgument Pack =
T->getArgumentPack();
2656 TemplateArgument Arg =
SemaRef.getPackSubstitutedTemplateArgument(Pack);
2657 return BuildSubstTemplateTypeParmType(
2658 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2662QualType TemplateInstantiator::TransformSubstBuiltinTemplatePackType(
2663 TypeLocBuilder &TLB, SubstBuiltinTemplatePackTypeLoc TL) {
2665 return TreeTransform::TransformSubstBuiltinTemplatePackType(TLB, TL);
2666 TemplateArgument
Result =
SemaRef.getPackSubstitutedTemplateArgument(
2670 return Result.getAsType();
2673static concepts::Requirement::SubstitutionDiagnostic *
2683 ErrorLoc = PDA.first;
2688 llvm::raw_svector_ostream
OS(Entity);
2692 C.backupStr(Entity), ErrorLoc,
C.backupStr(Message)};
2695concepts::Requirement::SubstitutionDiagnostic *
2698 llvm::raw_svector_ostream
OS(Entity);
2702 C.backupStr(Entity),
2703 Location, StringRef()};
2706ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2719 if (getDerived().TransformFunctionTypeParams(
2720 KWLoc, Params,
nullptr,
nullptr, PTypes,
2721 &TransParams, PInfos, &ErrorIdx) ||
2722 Trap.hasErrorOccurred()) {
2728 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2729 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2731 TransReqs, RBraceLoc);
2737concepts::TypeRequirement *
2738TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2742 if (AlwaysRebuild())
2743 return RebuildTypeRequirement(
2749 Sema::SFINAETrap Trap(
SemaRef, Info);
2750 Sema::InstantiatingTemplate TypeInst(
2753 if (TypeInst.isInvalid())
2755 TypeSourceInfo *TransType = TransformType(Req->
getType());
2756 if (!TransType || Trap.hasErrorOccurred())
2758 [&] (llvm::raw_ostream&
OS) {
2761 return RebuildTypeRequirement(TransType);
2764concepts::ExprRequirement *
2765TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2769 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2776 Sema::SFINAETrap Trap(
SemaRef, Info);
2779 if (ExprInst.isInvalid())
2782 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2784 TransExprRes =
SemaRef.CheckPlaceholderExpr(TransExprRes.
get());
2785 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2790 TransExpr = TransExprRes.
get();
2793 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2795 if (RetReq.isEmpty())
2796 TransRetReq.emplace();
2797 else if (RetReq.isSubstitutionFailure())
2798 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2799 else if (RetReq.isTypeConstraint()) {
2800 TemplateParameterList *OrigTPL =
2801 RetReq.getTypeConstraintTemplateParameterList();
2803 Sema::SFINAETrap Trap(
SemaRef, Info);
2806 if (TPLInst.isInvalid())
2808 TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2809 if (!TPL || Trap.hasErrorOccurred())
2811 [&] (llvm::raw_ostream&
OS) {
2812 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2813 ->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2817 TransRetReq.emplace(TPL);
2820 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2821 if (Expr *E = TransExpr.dyn_cast<Expr *>())
2823 std::move(*TransRetReq));
2824 return RebuildExprRequirement(
2829concepts::NestedRequirement *
2830TemplateInstantiator::TransformNestedRequirement(
2831 concepts::NestedRequirement *Req) {
2836 ConstraintSatisfaction Satisfaction;
2838 auto NestedReqWithDiag = [&
C,
this](Expr *E,
2839 ConstraintSatisfaction Satisfaction) {
2841 SmallString<128> Entity;
2842 llvm::raw_svector_ostream
OS(Entity);
2843 E->printPretty(
OS,
nullptr,
SemaRef.getPrintingPolicy());
2844 return new (
C) concepts::NestedRequirement(
2845 SemaRef.Context,
C.backupStr(Entity), std::move(Satisfaction));
2849 if (AlwaysRebuild())
2855 if (!getEvaluateConstraints()) {
2857 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2861 concepts::NestedRequirement(TransConstraint.
get());
2862 ConstraintSatisfaction Satisfaction;
2863 return new (
SemaRef.Context) concepts::NestedRequirement(
2864 SemaRef.Context, TransConstraint.
get(), Satisfaction);
2868 Expr *NewConstraint;
2872 Sema::InstantiatingTemplate ConstrInst(
2874 Sema::InstantiatingTemplate::ConstraintsCheck(),
2877 if (ConstrInst.isInvalid())
2881 Req, AssociatedConstraint(Constraint), TemplateArgs,
2883 nullptr, &NewConstraint);
2887 return NestedReqWithDiag(Constraint, Satisfaction);
2891 if (!NewConstraint) {
2893 return NestedReqWithDiag(Constraint, Satisfaction);
2895 NewConstraint = Constraint;
2897 return new (
C) concepts::NestedRequirement(
C, NewConstraint, Satisfaction);
2903 bool AllowDeducedTST) {
2904 if (!
T->getType()->isInstantiationDependentType() &&
2905 !
T->getType()->isVariablyModifiedType())
2908 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2909 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2910 : Instantiator.TransformType(
T);
2928 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2942 bool *IsIncompleteSubstitution) {
2945 if (!
T->isInstantiationDependentType() && !
T->isVariablyModifiedType())
2948 TemplateInstantiator Instantiator(
2949 *
this, TemplateArgs, Loc, Entity,
2950 IsIncompleteSubstitution !=
nullptr);
2951 QualType QT = Instantiator.TransformType(
T);
2952 if (IsIncompleteSubstitution && Instantiator.getIsIncomplete())
2953 *IsIncompleteSubstitution =
true;
2958 if (
T->getType()->isInstantiationDependentType() ||
2959 T->getType()->isVariablyModifiedType())
2962 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2982 Qualifiers ThisTypeQuals,
bool EvaluateConstraints) {
2986 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2987 Instantiator.setEvaluateConstraints(EvaluateConstraints);
3003 Result = Instantiator.TransformFunctionProtoType(
3004 TLB, Proto, ThisContext, ThisTypeQuals,
3006 bool &Changed) {
return false; });
3008 Result = Instantiator.TransformType(TLB, TL);
3022 bool Changed =
false;
3023 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
3024 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
3035 ESI, ExceptionStorage, Args))
3044 struct GetContainedInventedTypeParmVisitor :
3045 public TypeVisitor<GetContainedInventedTypeParmVisitor,
3046 TemplateTypeParmDecl *> {
3047 using TypeVisitor<GetContainedInventedTypeParmVisitor,
3053 return Visit(
T.getTypePtr());
3057 const TemplateTypeParmType *
T) {
3058 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
3060 return T->getDecl();
3066 TemplateTypeParmDecl *VisitPointerType(
const PointerType *
T) {
3070 TemplateTypeParmDecl *VisitBlockPointerType(
const BlockPointerType *
T) {
3074 TemplateTypeParmDecl *VisitReferenceType(
const ReferenceType *
T) {
3075 return Visit(
T->getPointeeTypeAsWritten());
3078 TemplateTypeParmDecl *VisitMemberPointerType(
const MemberPointerType *
T) {
3082 TemplateTypeParmDecl *VisitArrayType(
const ArrayType *
T) {
3083 return Visit(
T->getElementType());
3086 TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
3087 const DependentSizedExtVectorType *
T) {
3088 return Visit(
T->getElementType());
3091 TemplateTypeParmDecl *VisitVectorType(
const VectorType *
T) {
3092 return Visit(
T->getElementType());
3095 TemplateTypeParmDecl *VisitFunctionProtoType(
const FunctionProtoType *
T) {
3096 return VisitFunctionType(
T);
3099 TemplateTypeParmDecl *VisitFunctionType(
const FunctionType *
T) {
3103 TemplateTypeParmDecl *VisitParenType(
const ParenType *
T) {
3104 return Visit(
T->getInnerType());
3107 TemplateTypeParmDecl *VisitAttributedType(
const AttributedType *
T) {
3108 return Visit(
T->getModifiedType());
3111 TemplateTypeParmDecl *VisitMacroQualifiedType(
const MacroQualifiedType *
T) {
3112 return Visit(
T->getUnderlyingType());
3115 TemplateTypeParmDecl *VisitAdjustedType(
const AdjustedType *
T) {
3116 return Visit(
T->getOriginalType());
3119 TemplateTypeParmDecl *VisitPackExpansionType(
const PackExpansionType *
T) {
3120 return Visit(
T->getPattern());
3129 bool EvaluateConstraints) {
3133 if (!EvaluateConstraints) {
3135 bool ContainsUnexpandedPack =
3139 return TA.getArgument().containsUnexpandedParameterPack();
3141 if (!Index && ContainsUnexpandedPack)
3142 Index =
SemaRef.ArgPackSubstIndex;
3171 bool ExpectParameterPack,
bool EvaluateConstraint) {
3191 }
else if (ExpectParameterPack) {
3197 diag::err_function_parameter_pack_without_parameter_packs)
3221 GetContainedInventedTypeParmVisitor().Visit(OldTSI->
getType())) {
3223 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3228 if (Inst && !Inst->getTypeConstraint()) {
3296 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3298 return Instantiator.TransformFunctionTypeParams(
3299 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3308 Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
3312 if (AlreadyInstantiating) {
3313 Param->setInvalidDecl();
3314 return Diag(Param->getBeginLoc(), diag::err_recursive_default_argument)
3332 std::optional<LocalInstantiationScope> LIS;
3343 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3360 Param->getLocation(),
3365 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3395 auto ComputeInfo = [&S, &TemplateArgs, BaseSourceRange, BaseEllipsisLoc](
3402 if (IsLateExpansionAttempt) {
3407 return P.first.dyn_cast<
const SubstBuiltinTemplatePackType *>();
3409 if (!SawPackTypes) {
3421 BaseEllipsisLoc, BaseSourceRange, Unexpanded, TemplateArgs,
3426 if (ComputeInfo(
Base.getTypeSourceInfo(),
false, Info))
3430 Out =
Base.getTypeSourceInfo();
3440 if (!Out->getType()->containsUnexpandedParameterPack())
3445 if (ComputeInfo(Out,
true, Info))
3458 for (
const auto &
Base : Pattern->
bases()) {
3459 if (!
Base.getType()->isInstantiationDependentType()) {
3461 if (RD->isInvalidDecl())
3470 if (
Base.isPackExpansion()) {
3482 ArgsForSubst = &EmptyList;
3497 Instantiation,
Base.getSourceRange(),
Base.isVirtual(),
3498 Base.getAccessSpecifierAsWritten(), Expanded,
3500 InstantiatedBases.push_back(InstantiatedBase);
3509 EllipsisLoc =
Base.getEllipsisLoc();
3517 Base.getSourceRange().getBegin(),
3528 Base.getSourceRange(),
3530 Base.getAccessSpecifierAsWritten(),
3533 InstantiatedBases.push_back(InstantiatedBase);
3563 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3566 return InstantiateClassImpl(PointOfInstantiation, Instantiation, Pattern,
3567 TemplateArgs, TSK, Complain);
3570bool Sema::InstantiateClassImpl(
3577 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3579 Pattern, PatternDef, TSK, Complain))
3582 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3583 llvm::TimeTraceMetadata M;
3584 llvm::raw_string_ostream OS(M.Detail);
3587 if (llvm::isTimeTraceVerbose()) {
3588 auto Loc = SourceMgr.getExpansionLoc(Instantiation->
getLocation());
3589 M.File = SourceMgr.getFilename(Loc);
3590 M.Line = SourceMgr.getExpansionLineNumber(Loc);
3595 Pattern = PatternDef;
3598 if (MemberSpecializationInfo *MSInfo
3600 MSInfo->setTemplateSpecializationKind(TSK);
3601 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3602 }
else if (ClassTemplateSpecializationDecl *Spec
3603 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3604 Spec->setTemplateSpecializationKind(TSK);
3605 Spec->setPointOfInstantiation(PointOfInstantiation);
3608 NonSFINAEContext _(*
this);
3609 InstantiatingTemplate Inst(*
this, PointOfInstantiation, Instantiation);
3610 if (Inst.isInvalid())
3612 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3613 "instantiating class definition");
3617 ContextRAII SavedContext(*
this, Instantiation);
3618 EnterExpressionEvaluationContext EvalContext(
3619 *
this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
3625 LocalInstantiationScope Scope(*
this, MergeWithParentScope);
3631 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3634 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3644 Instantiation->
setTagKind(Pattern->getTagKind());
3647 if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
3650 TemplateDeclInstantiator Instantiator(*
this, Instantiation, TemplateArgs);
3651 Instantiator.setEvaluateConstraints(
false);
3652 SmallVector<Decl*, 4> Fields;
3654 LateInstantiatedAttrVec LateAttrs;
3655 Instantiator.enableLateAttributeInstantiation(&LateAttrs);
3657 bool MightHaveConstexprVirtualFunctions =
false;
3658 for (
auto *
Member : Pattern->decls()) {
3668 if (
Member->getDeclContext() != Pattern)
3679 if (
Member->isInvalidDecl()) {
3689 Decl *NewMember = Instantiator.Visit(
Member);
3691 if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3692 Fields.push_back(Field);
3693 }
else if (EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3699 Enum->isCompleteDefinition()) {
3700 MemberSpecializationInfo *MSInfo =
Enum->getMemberSpecializationInfo();
3701 assert(MSInfo &&
"no spec info for member enum specialization");
3705 }
else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
3706 if (SA->isFailed()) {
3712 }
else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3715 MightHaveConstexprVirtualFunctions =
true;
3718 if (
Member->isInvalidDecl())
3732 ActOnFields(
nullptr, Instantiation->
getLocation(), Instantiation, Fields,
3733 SourceLocation(), SourceLocation(), ParsedAttributesView());
3734 CheckCompletedCXXClass(
nullptr, Instantiation);
3739 if (ParsingClassDepth == 0)
3740 ActOnFinishCXXNonNestedClass();
3744 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3745 E = LateAttrs.end(); I != E; ++I) {
3746 assert(CurrentInstantiationScope == Instantiator.getStartingScope());
3747 CurrentInstantiationScope = I->Scope;
3751 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3752 CXXThisScopeRAII ThisScope(*
this, ThisContext, Qualifiers(),
3753 ND->isCXXInstanceMember());
3757 if (NewAttr && checkInstantiatedThreadSafetyAttrs(I->NewDecl, NewAttr))
3758 I->NewDecl->addAttr(NewAttr);
3760 Instantiator.getStartingScope());
3762 Instantiator.disableLateAttributeInstantiation();
3765 ActOnFinishDelayedMemberInitializers(Instantiation);
3770 Instantiation->
setLocation(Pattern->getLocation());
3771 Instantiation->
setLocStart(Pattern->getInnerLocStart());
3777 if (Pattern->isDependentContext())
3778 PerformDependentDiagnostics(Pattern, TemplateArgs);
3783 P = Instantiator.delayed_partial_spec_begin(),
3784 PEnd = Instantiator.delayed_partial_spec_end();
3786 if (!Instantiator.InstantiateClassTemplatePartialSpecialization(
3787 P->first, P->second)) {
3796 P = Instantiator.delayed_var_partial_spec_begin(),
3797 PEnd = Instantiator.delayed_var_partial_spec_end();
3799 if (!Instantiator.InstantiateVarTemplatePartialSpecialization(
3800 P->first, P->second)) {
3818 MarkVTableUsed(PointOfInstantiation, Instantiation,
true);
3819 else if (MightHaveConstexprVirtualFunctions)
3820 MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
3824 Consumer.HandleTagDeclDefinition(Instantiation);
3836 assert(!AlreadyInstantiating &&
"should have been caught by caller");
3842 Pattern, PatternDef, TSK,
true))
3844 Pattern = PatternDef;
3858 "instantiating enum definition");
3893 "pattern and instantiation disagree about init style");
3897 if (AlreadyInstantiating)
3899 return Diag(PointOfInstantiation,
3900 diag::err_default_member_initializer_cycle)
3909 Diag(PointOfInstantiation,
3910 diag::err_default_member_initializer_not_yet_parsed)
3911 << OutermostClass << Pattern;
3912 Diag(Pattern->getEndLoc(),
3913 diag::note_default_member_initializer_not_yet_parsed);
3923 "instantiating default member init");
3932 PointOfInstantiation, Instantiation,
CurContext};
3948 L->DefaultMemberInitializerInstantiated(Instantiation);
3957 struct PartialSpecMatchResult {
4002 std::optional<Sema::NonSFINAEContext> NSC(S);
4022 typedef PartialSpecMatchResult MatchResult;
4025 Template->getPartialSpecializations(PartialSpecs);
4038 if (
Template->isMemberSpecialization() &&
4039 !Partial->isMemberSpecialization())
4057 if (Matched.empty() && PrimaryStrictPackMatch)
4058 Matched = std::move(ExtraMatched);
4064 if (Matched.size() >= 1) {
4066 if (Matched.size() == 1) {
4079 PEnd = Matched.end();
4082 P->Partial, Best->Partial, PointOfInstantiation) ==
4091 PEnd = Matched.end();
4094 P->Partial, Best->Partial,
4095 PointOfInstantiation) != Best->Partial) {
4105 S.
Diag(PointOfInstantiation,
4106 diag::err_partial_spec_ordering_ambiguous)
4107 << ClassTemplateSpec;
4111 PEnd = Matched.end();
4113 S.
Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
4115 P->Partial->getTemplateParameters(), *P->Args);
4130 if (
auto *PartialSpec =
4133 while (PartialSpec->getInstantiatedFromMember()) {
4136 if (PartialSpec->isMemberSpecialization())
4139 PartialSpec = PartialSpec->getInstantiatedFromMember();
4141 Pattern = PartialSpec;
4144 while (
Template->getInstantiatedFromMemberTemplate()) {
4147 if (
Template->isMemberSpecialization())
4152 Pattern =
Template->getTemplatedDecl();
4162 bool PrimaryStrictPackMatch) {
4171 if (AlreadyInstantiating)
4174 bool HadAvaibilityWarning =
4180 ClassTemplateSpec, TSK,
4181 PrimaryStrictPackMatch);
4186 bool Err = InstantiateClassImpl(
4187 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4194 if (!Err && !HadAvaibilityWarning) {
4214 "Unexpected template specialization kind!");
4215 for (
auto *D : Instantiation->
decls()) {
4216 bool SuppressNew =
false;
4217 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4219 Function->getInstantiatedFromMemberFunction()) {
4221 if (
Function->getTrailingRequiresClause()) {
4229 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4233 Function->getTemplateSpecializationKind();
4238 PointOfInstantiation, TSK,
Function, PrevTSK,
4239 Function->getPointOfInstantiation(), SuppressNew) ||
4252 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4262 std::make_pair(
Function, PointOfInstantiation));
4265 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4270 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4274 assert(MSInfo &&
"No member specialization information?");
4303 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4304 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4312 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4317 assert(MSInfo &&
"No member specialization information?");
4323 if (
Context.getTargetInfo().getTriple().isOSWindows() &&
4343 assert(Pattern &&
"Missing instantiated-from-template information");
4345 if (!
Record->getDefinition()) {
4366 Record->getTemplateSpecializationKind() ==
4368 Record->setTemplateSpecializationKind(TSK);
4373 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4377 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4379 assert(MSInfo &&
"No member specialization information?");
4386 PointOfInstantiation, TSK,
Enum,
4392 if (
Enum->getDefinition())
4395 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4396 assert(Pattern &&
"Missing instantiated-from-template information");
4407 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4418 ClassPattern->
lookup(Field->getDeclName());
4451 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4454 return Instantiator.TransformStmt(S);
4462 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
4463 return Instantiator.TransformTemplateArgument(Input, Output);
4470 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4472 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4479 TemplateInstantiator Instantiator(
4480 TemplateInstantiator::ForParameterMappingSubstitution, *
this, BaseLoc,
4482 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4490 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4493 return Instantiator.TransformExpr(E);
4502 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4504 return Instantiator.TransformAddressOfOperand(E);
4513 TemplateInstantiator Instantiator(
4514 TemplateInstantiator::ForConstraintSubstitution, *
this, TemplateArgs,
4516 return Instantiator.TransformExpr(E);
4524 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4526 Instantiator.setEvaluateConstraints(
false);
4527 return Instantiator.TransformExpr(E);
4535 TemplateInstantiator Instantiator(*
this, MLTAL,
SourceLocation(),
4542 if (Instantiator.TransformConceptTemplateArguments(
4567 struct ConstraintExprTransformer :
TreeTransform<ConstraintExprTransformer> {
4579 case Stmt::BinaryOperatorClass:
4580 case Stmt::ConceptSpecializationExprClass:
4581 case Stmt::ParenExprClass:
4582 case Stmt::UnresolvedLookupExprClass:
4583 return Base::TransformExpr(E);
4594 if (!(E->
getOpcode() == BinaryOperatorKind::BO_LAnd ||
4595 E->
getOpcode() == BinaryOperatorKind::BO_LOr))
4612 bool Uneval =
false) {
4614 return Base::TransformTemplateArgument(Input, Output, Uneval);
4621 bool IsAddressOfOperand =
false) {
4622 if (!E->isConceptReference())
4625 assert(E->getNumDecls() == 1 &&
4626 "ConceptReference must have single declaration");
4630 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
4631 unsigned Depth = TTP->getDepth();
4632 unsigned Pos = TTP->getPosition();
4640 if (ResolvedConcept ==
nullptr)
4646 if (TransformTemplateArguments(E->getTemplateArgs(),
4647 E->getNumTemplateArgs(), TransArgs))
4654 ResolvedConcept, ResolvedConcept,
4659 ConstraintExprTransformer Transformer(*
this, MLTALForConstraint);
4661 Transformer.TransformExpr(
const_cast<Expr *
>(ConstraintExpr));
4667 bool CXXDirectInit) {
4668 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4670 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4679 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4682 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4692 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4694 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4700 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4702 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4710 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameLoc,
4712 return Instantiator.TransformTemplateName(QualifierLoc, TemplateKWLoc, Name,
4721 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4722 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4723 unsigned i = PV->getFunctionScopeIndex();
4726 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4727 return FD->getCanonicalDecl()->getParamDecl(i);
4733llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4737 Current = Current->Outer) {
4740 const Decl *CheckD = D;
4742 LocalDeclsMap::iterator
Found = Current->LocalDecls.find(CheckD);
4743 if (
Found != Current->LocalDecls.end())
4744 return &
Found->second;
4748 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4755 if (!Current->CombineWithOuterScope)
4762llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4775 if (RD->isLocalClass())
4792 assert(
isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4798 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4799 if (Stored.isNull()) {
4803 while (Current->CombineWithOuterScope && Current->Outer) {
4804 Current = Current->Outer;
4805 assert(!Current->LocalDecls.contains(D) &&
4806 "Instantiated local in inner and outer scopes");
4810 }
else if (
DeclArgumentPack *Pack = dyn_cast<DeclArgumentPack *>(Stored)) {
4813 assert(
cast<Decl *>(Stored) == Inst &&
"Already instantiated this local");
4821 Pack->push_back(Inst);
4828 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4829 assert(!Current->LocalDecls.contains(D) &&
4830 "Creating local pack after instantiation of local");
4834 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4837 ArgumentPacks.push_back(Pack);
4842 if (llvm::is_contained(*Pack, D))
4849 unsigned NumExplicitArgs) {
4850 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4851 "Already have a partially-substituted pack");
4852 assert((!PartiallySubstitutedPack
4853 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4854 "Wrong number of arguments in partially-substituted pack");
4855 PartiallySubstitutedPack = Pack;
4856 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4857 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4862 unsigned *NumExplicitArgs)
const {
4864 *ExplicitArgs =
nullptr;
4865 if (NumExplicitArgs)
4866 *NumExplicitArgs = 0;
4869 Current = Current->Outer) {
4870 if (Current->PartiallySubstitutedPack) {
4872 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4873 if (NumExplicitArgs)
4874 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4876 return Current->PartiallySubstitutedPack;
4879 if (!Current->CombineWithOuterScope)
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines Expressions and AST nodes for C++2a concepts.
Result
Implement __builtin_bit_cast and related operations.
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Record Record
static TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, ArrayRef< TemplateArgument > Ps, ArrayRef< TemplateArgument > As, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool NumberOfArgumentsMustMatch, bool PartialOrdering, PackFold PackFold, bool *HasDeducedAnyParam)
static bool PreparePackForExpansion(Sema &S, const CXXBaseSpecifier &Base, const MultiLevelTemplateArgumentList &TemplateArgs, TypeSourceInfo *&Out, UnexpandedInfo &Info)
static const Decl * getCanonicalParmVarDecl(const Decl *D)
static std::string convertCallArgsValueCategoryAndTypeToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
static ActionResult< CXXRecordDecl * > getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool PrimaryStrictPackMatch)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, Sema::EntityPrinter Printer)
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
Defines the clang::TypeLoc interface and its subclasses.
TypePropertyCache< Private > Cache
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const clang::PrintingPolicy & getPrintingPolicy() const
The result of parsing/analyzing an expression, statement etc.
Attr - This represents one attribute.
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getOperatorLoc() const
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a base class of a C++ class.
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXRecordDecl * getDefinition() const
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
void setIsHLSLBuiltinRecord(bool Value)
Sets the flag that the class is a built-in HLSL record.
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ nested-name-specifier or a global scope specifier.
Declaration of a class template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)?
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
Declaration of a C++20 concept.
NamedDecl * getFoundDecl() const
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
const TypeClass * getTypePtr() const
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
bool HasSubstitutionFailure()
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
DeclContextLookupResult lookup_result
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isParameterPack() const
Whether this declaration is a parameter pack.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isFileContextDecl() const
static Decl * castFromDeclContext(const DeclContext *)
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setLocation(SourceLocation L)
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getDeclContext()
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
The name of a declaration.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
TypeSourceInfo * getTypeSourceInfo() const
RAII object that enters a new expression evaluation context.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
EnumDecl * getDefinition() const
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
ExprDependence getDependence() const
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Represents a function declaration or definition.
ArrayRef< ParmVarDecl * > parameters() const
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, ArrayRef< ValueDecl * > Params)
ValueDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
ValueDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
Represents a prototype with parameter type info, e.g.
ExtProtoInfo getExtProtoInfo() const
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
ArrayRef< ParmVarDecl * > getParams() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
QualType getReturnType() const
ArrayRef< TemplateArgument > getTemplateArguments() const
const TypeClass * getTypePtr() const
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Describes an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
A stack-allocated class that identifies which local variable declaration instantiations are present i...
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false, bool InstantiatingLambdaOrBlock=false)
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
SmallVector< ValueDecl *, 4 > DeclArgumentPack
A set of declarations.
llvm::PointerUnion< Decl *, DeclArgumentPack * > * getInstantiationOfIfExists(const Decl *D)
Similar to findInstantiationOf(), but it wouldn't assert if the instantiation was not found within th...
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
void InstantiatedLocal(const Decl *D, Decl *Inst)
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
bool isLambdaOrBlock() const
Determine whether this scope is for instantiating a lambda or block.
void MakeInstantiatedLocalArgPack(const Decl *D)
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Provides information a specialization of a member of a class template, which may be a member function...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Describes a module or submodule.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
bool retainInnerDepths() const
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const Type * getAsType() const
@ Type
A type, stored as a Type*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
SourceLocation getEllipsisLoc() const
TypeLoc getPatternLoc() const
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
SourceLocation getExplicitObjectParamThisLoc() const
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
void setUninstantiatedDefaultArg(Expr *arg)
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
bool hasUninstantiatedDefaultArg() const
bool hasInheritedDefaultArg() const
void setExplicitObjectParameterLoc(SourceLocation Loc)
Expr * getUninstantiatedDefaultArg()
unsigned getFunctionScopeDepth() const
void setHasInheritedDefaultArg(bool I=true)
PredefinedIdentKind getIdentKind() const
SourceLocation getLocation() const
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
A (possibly-)qualified type.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
void addConst()
Add the const type qualifier to this QualType.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
The collection of all-type qualifiers we support.
void removeObjCLifetime()
Represents a struct/union/class.
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
RAII object used to change the argument pack substitution index within a Sema object.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
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.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getUnderlyingType() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
void deduceParmAddressSpace(const ASTContext &Ctxt)
StorageClass getStorageClass() const
Returns the storage class as written in the source.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
bool isClassScopeExplicitSpecialization() const
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
bool isExprSubstitutionFailure() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
bool hasInvalidConstraint() const
Expr * getConstraintExpr() const
StringRef getInvalidConstraintEntity()
A static requirement that can be used in a requires-expression to check properties of types and expre...
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
CXXRecordDecl * Lambda
The class that describes the lambda.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Provides information about an attempted template argument deduction, whose success or failure was des...
TemplateArgumentList * takeCanonical()
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
void takeSFINAEDiagnostic(PartialDiagnosticAt &PD)
Take ownership of the SFINAE diagnostic.
bool hasStrictPackMatch() const
Defines the clang::TargetInfo interface.
PRESERVE_NONE bool Ret(InterpState &S)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ OK_Ordinary
An ordinary object is located at an address in memory.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool isPackProducingBuiltinTemplateName(TemplateName N)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema's representation of template deduction information to the form used in overload-can...
@ Type
The name was classified as a type.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
for(const auto &A :T->param_types())
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
TemplateDeductionResult
Describes the result of template argument deduction.
@ Success
Template argument deduction was successful.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
U cast(CodeGen::Address addr)
@ PackIndex
Index of a pack indexing expression or specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
ActionResult< Stmt * > StmtResult
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
SourceLocation getLAngleLoc() const
ArrayRef< TemplateArgumentLoc > arguments() const
unsigned getNumTemplateArgs() const
SourceLocation getRAngleLoc() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.
ExceptionSpecInfo ExceptionSpec
constexpr underlying_type toInternalRepresentation() const
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
SynthesisKind
The kind of template instantiation we are performing.
@ MarkingClassDllexported
We are marking a class as __dllexport.
@ RequirementParameterInstantiation
@ DefaultTemplateArgumentInstantiation
We are instantiating a default argument for a template parameter.
@ ExplicitTemplateArgumentSubstitution
We are substituting explicit template arguments provided for a function template.
@ DefaultTemplateArgumentChecking
We are checking the validity of a default template argument that has been used when naming a template...
@ InitializingStructuredBinding
We are initializing a structured binding.
@ ExceptionSpecInstantiation
We are instantiating the exception specification for a function template which was deferred until it ...
@ NestedRequirementConstraintsCheck
We are checking the satisfaction of a nested requirement of a requires expression.
@ BuildingBuiltinDumpStructCall
We are building an implied call from __builtin_dump_struct.
@ ParameterMappingSubstitution
@ DefiningSynthesizedFunction
We are defining a synthesized function (such as a defaulted special member).
@ Memoization
Added for Template instantiation observation.
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
@ TypeAliasTemplateInstantiation
We are instantiating a type alias template declaration.
@ BuildingDeductionGuides
We are building deduction guides for a class.
@ PartialOrderingTTP
We are performing partial ordering for template template parameters.
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
@ PriorTemplateArgumentSubstitution
We are substituting prior template arguments into a new template parameter.
@ SYCLKernelLaunchOverloadResolution
We are performing overload resolution for a call to a function template or variable template named 's...
@ ExpansionStmtInstantiation
We are instantiating an expansion statement.
@ ExceptionSpecEvaluation
We are computing the exception specification for a defaulted special member function.
@ TemplateInstantiation
We are instantiating a template declaration.
@ DeclaringSpecialMember
We are declaring an implicit special member function.
@ DeclaringImplicitEqualityComparison
We are declaring an implicit 'operator==' for a defaulted 'operator<=>'.
@ DefaultFunctionArgumentInstantiation
We are instantiating a default argument for a function.
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
@ SYCLKernelLaunchLookup
We are performing name lookup for a function template or variable template named 'sycl_kernel_launch'...
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Decl * Entity
The entity that is being synthesized.
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
A stack object to be created when performing template instantiation.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template,...
void Clear()
Note that we have finished instantiating this template.
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
bool ExpandUnderForgetSubstitions
UnsignedOrNone NumExpansions