39#include "llvm/ADT/STLForwardCompat.h"
40#include "llvm/ADT/StringExtras.h"
41#include "llvm/Support/ErrorHandling.h"
42#include "llvm/Support/TimeProfiler.h"
55 const Decl *NextDecl =
nullptr;
57 bool ClearRelativeToPrimary =
true;
58 static Response Done() {
63 static Response ChangeDecl(
const Decl *ND) {
68 static Response ChangeDecl(
const DeclContext *Ctx) {
74 static Response UseNextDecl(
const Decl *CurDecl) {
78 static Response DontClearRelativeToPrimaryNextDecl(
const Decl *CurDecl) {
79 Response R = Response::UseNextDecl(CurDecl);
80 R.ClearRelativeToPrimary =
false;
89getPrimaryTemplateOfGenericLambda(
const FunctionDecl *LambdaCallOperator) {
91 if (
auto *FTD = dyn_cast_if_present<FunctionTemplateDecl>(
93 FTD && FTD->getInstantiatedFromMemberTemplate()) {
95 FTD->getInstantiatedFromMemberTemplate()->getTemplatedDecl();
96 }
else if (
auto *Prev = cast<CXXMethodDecl>(LambdaCallOperator)
97 ->getInstantiatedFromMemberFunction())
98 LambdaCallOperator = Prev;
102 return LambdaCallOperator;
105struct EnclosingTypeAliasTemplateDetails {
110 explicit operator bool()
noexcept {
return Template; }
115EnclosingTypeAliasTemplateDetails
116getEnclosingTypeAliasTemplateDecl(
Sema &SemaRef) {
119 TypeAliasTemplateInstantiation)
121 EnclosingTypeAliasTemplateDetails Result;
122 auto *TATD = cast<TypeAliasTemplateDecl>(CSC.Entity),
123 *Next = TATD->getInstantiatedFromMemberTemplate();
127 CSC.template_arguments(),
130 Result.PrimaryTypeAliasDecl = Next;
131 Next = Next->getInstantiatedFromMemberTemplate();
148bool isLambdaEnclosedByTypeAliasDecl(
151 return cast<CXXRecordDecl>(PrimaryLambdaCallOperator->
getDeclContext())
155 const_cast<FunctionDecl *
>(PrimaryLambdaCallOperator)) ==
163 bool SkipForSpecialization) {
167 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
171 !isa<VarTemplatePartialSpecializationDecl>(VarTemplSpec))
172 return Response::Done();
177 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
181 if (!SkipForSpecialization)
182 Result.addOuterTemplateArguments(
185 if (Partial->isMemberSpecialization())
186 return Response::Done();
189 if (!SkipForSpecialization)
190 Result.addOuterTemplateArguments(
194 return Response::Done();
196 return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
208 for (
unsigned I = 0, N = TTP->
getDepth() + 1; I != N; ++I)
209 Result.addOuterTemplateArguments(std::nullopt);
210 return Response::Done();
213Response HandlePartialClassTemplateSpec(
216 if (!SkipForSpecialization)
218 return Response::Done();
225 bool SkipForSpecialization) {
229 !isa<ClassTemplatePartialSpecializationDecl>(ClassTemplSpec))
230 return Response::Done();
232 if (!SkipForSpecialization)
233 Result.addOuterTemplateArguments(
242 return Response::Done();
250 return Response::ChangeDecl(InstFromPartialTempl->getLexicalDeclContext());
252 return Response::UseNextDecl(ClassTemplSpec);
258 bool ForConstraintInstantiation) {
260 if (!RelativeToPrimary &&
261 Function->getTemplateSpecializationKindForInstantiation() ==
263 return Response::Done();
265 if (!RelativeToPrimary &&
270 return Response::UseNextDecl(
Function);
272 Function->getTemplateSpecializationArgs()) {
275 TemplateArgs->asArray(),
280 assert(
Function->getPrimaryTemplate() &&
"No function template?");
281 if (
Function->getPrimaryTemplate()->isMemberSpecialization())
282 return Response::Done();
285 if (!ForConstraintInstantiation &&
294 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
295 if (isLambdaEnclosedByTypeAliasDecl(
296 getPrimaryTemplateOfGenericLambda(
298 TypeAlias.PrimaryTypeAliasDecl))
299 return Response::UseNextDecl(
Function);
301 return Response::Done();
304 }
else if (
Function->getDescribedFunctionTemplate()) {
306 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
307 "Outer template not instantiated?");
314 Function->getNonTransparentDeclContext()->isFileContext() &&
316 return Response::ChangeDecl(
Function->getLexicalDeclContext());
319 if (ForConstraintInstantiation &&
Function->getFriendObjectKind())
320 return Response::ChangeDecl(
Function->getLexicalDeclContext());
321 return Response::UseNextDecl(
Function);
326 if (!isa<ClassTemplateSpecializationDecl>(FTD->
getDeclContext())) {
327 Result.addOuterTemplateArguments(
355 if (TSTy->isCurrentInstantiation()) {
356 auto *RD = TSTy->getCanonicalTypeInternal()->getAsCXXRecordDecl();
358 Arguments = CTD->getInjectedTemplateArgs();
360 dyn_cast<ClassTemplateSpecializationDecl>(RD))
364 Result.addOuterTemplateArguments(
380 bool ForConstraintInstantiation) {
383 (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
384 "Outer template not instantiated?");
385 if (ClassTemplate->isMemberSpecialization())
386 return Response::Done();
387 if (ForConstraintInstantiation)
388 Result.addOuterTemplateArguments(
const_cast<CXXRecordDecl *
>(Rec),
389 ClassTemplate->getInjectedTemplateArgs(),
396 return Response::Done();
401 if (ForConstraintInstantiation && IsFriend &&
410 return Response::ChangeDecl(LCD);
414 if (
auto TypeAlias = getEnclosingTypeAliasTemplateDecl(SemaRef)) {
417 if (isLambdaEnclosedByTypeAliasDecl(PrimaryLambdaCallOperator,
418 TypeAlias.PrimaryTypeAliasDecl)) {
419 Result.addOuterTemplateArguments(TypeAlias.Template,
420 TypeAlias.AssociatedTemplateArguments,
435 return Response::ChangeDecl(TypeAlias.Template->getDeclContext());
440 return Response::UseNextDecl(Rec);
443Response HandleImplicitConceptSpecializationDecl(
446 Result.addOuterTemplateArguments(
450 return Response::UseNextDecl(CSD);
453Response HandleGenericDeclContext(
const Decl *CurDecl) {
454 return Response::UseNextDecl(CurDecl);
490 const FunctionDecl *Pattern,
bool ForConstraintInstantiation,
491 bool SkipForSpecialization) {
492 assert((ND || DC) &&
"Can't find arguments for a decl if one isn't provided");
497 const Decl *CurDecl = ND;
503 Result.addOuterTemplateArguments(
const_cast<NamedDecl *
>(ND), *Innermost,
513 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
514 HandleDefaultTempArgIntoTempTempParam(TTP,
Result);
515 CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
520 if (
const auto *VarTemplSpec =
521 dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
522 R = HandleVarTemplateSpec(VarTemplSpec,
Result, SkipForSpecialization);
523 }
else if (
const auto *PartialClassTemplSpec =
524 dyn_cast<ClassTemplatePartialSpecializationDecl>(CurDecl)) {
525 R = HandlePartialClassTemplateSpec(PartialClassTemplSpec,
Result,
526 SkipForSpecialization);
527 }
else if (
const auto *ClassTemplSpec =
528 dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
529 R = HandleClassTemplateSpec(ClassTemplSpec,
Result,
530 SkipForSpecialization);
531 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(CurDecl)) {
532 R = HandleFunction(*
this,
Function,
Result, Pattern, RelativeToPrimary,
533 ForConstraintInstantiation);
534 }
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(FTD,
Result);
542 }
else if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(CurDecl)) {
543 R = Response::ChangeDecl(CTD->getLexicalDeclContext());
544 }
else if (!isa<DeclContext>(CurDecl)) {
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;
601 llvm_unreachable(
"Invalid SynthesisKind!");
631 AlreadyInstantiating = !Inst.Entity ?
false :
633 .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
644 PointOfInstantiation, InstantiationRange, Entity) {}
651 PointOfInstantiation, InstantiationRange, Entity) {}
661 Template, TemplateArgs) {}
671 TemplateArgs, &DeductionInfo) {
685 PointOfInstantiation, InstantiationRange, Template, nullptr,
686 TemplateArgs, &DeductionInfo) {}
696 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
697 TemplateArgs, &DeductionInfo) {}
707 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
708 TemplateArgs, &DeductionInfo) {}
716 PointOfInstantiation, InstantiationRange, Param, nullptr,
726 PointOfInstantiation, InstantiationRange, Param, Template,
736 PointOfInstantiation, InstantiationRange, Param, Template,
745 PointOfInstantiation, InstantiationRange, Entity,
746 nullptr, TemplateArgs) {}
754 PointOfInstantiation, InstantiationRange, Param, Template,
763 PointOfInstantiation, InstantiationRange, nullptr,
764 nullptr,
std::nullopt, &DeductionInfo) {
773 PointOfInstantiation, InstantiationRange, nullptr,
774 nullptr,
std::nullopt) {}
781 PointOfInstantiation, InstantiationRange, nullptr,
782 nullptr,
std::nullopt, &DeductionInfo) {
791 PointOfInstantiation, InstantiationRange, Template, nullptr,
800 PointOfInstantiation, InstantiationRange, Template, nullptr,
801 {}, &DeductionInfo) {}
809 PointOfInstantiation, InstantiationRange, Template) {}
817 PointOfInstantiation, InstantiationRange, Template) {}
824 PointOfInstantiation, InstantiationRange, Entity) {}
844 if (!Active.isInstantiationRecord()) {
854 "forgot to remove a lookup module for a template instantiation");
873 if (!AlreadyInstantiating) {
877 {Active.Entity->getCanonicalDecl(), Active.Kind});
891 llvm::raw_string_ostream
OS(
Result);
892 llvm::ListSeparator Comma;
893 for (
const Expr *Arg : Args) {
895 Arg->IgnoreParens()->printPretty(
OS,
nullptr,
901bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
912 diag::err_template_recursion_depth_exceeded)
914 << InstantiationRange;
915 SemaRef.
Diag(PointOfInstantiation, diag::note_template_recursion_depth)
927 SkipStart = Limit / 2 + Limit % 2;
932 unsigned InstantiationIdx = 0;
937 ++Active, ++InstantiationIdx) {
939 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
940 if (InstantiationIdx == SkipStart) {
943 diag::note_instantiation_contexts_suppressed)
949 switch (Active->Kind) {
951 Decl *D = Active->Entity;
953 unsigned DiagID = diag::note_template_member_class_here;
954 if (isa<ClassTemplateSpecializationDecl>(
Record))
955 DiagID = diag::note_template_class_instantiation_here;
957 <<
Record << Active->InstantiationRange;
961 DiagID = diag::note_function_template_spec_here;
963 DiagID = diag::note_template_member_function_here;
966 << Active->InstantiationRange;
967 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
969 VD->isStaticDataMember()?
970 diag::note_template_static_data_member_def_here
971 : diag::note_template_variable_def_here)
973 << Active->InstantiationRange;
974 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
976 diag::note_template_enum_def_here)
978 << Active->InstantiationRange;
979 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
981 diag::note_template_nsdmi_here)
982 << FD << Active->InstantiationRange;
985 diag::note_template_class_instantiation_here)
986 << CTD << Active->InstantiationRange;
992 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
994 llvm::raw_svector_ostream
OS(TemplateArgsStr);
999 diag::note_default_arg_instantiation_here)
1001 << Active->InstantiationRange;
1008 diag::note_explicit_template_arg_substitution_here)
1011 Active->TemplateArgs,
1012 Active->NumTemplateArgs)
1013 << Active->InstantiationRange;
1019 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
1021 diag::note_function_template_deduction_instantiation_here)
1024 Active->TemplateArgs,
1025 Active->NumTemplateArgs)
1026 << Active->InstantiationRange;
1028 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
1029 isa<VarTemplateSpecializationDecl>(Active->Entity);
1030 bool IsTemplate =
false;
1032 if (
auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
1034 Params = D->getTemplateParameters();
1035 }
else if (
auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
1037 Params = D->getTemplateParameters();
1038 }
else if (
auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
1040 Params = D->getTemplateParameters();
1042 llvm_unreachable(
"unexpected template kind");
1046 diag::note_deduced_template_arg_substitution_here)
1047 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
1049 Active->NumTemplateArgs)
1050 << Active->InstantiationRange;
1056 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
1060 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1065 diag::note_default_function_arg_instantiation_here)
1067 << Active->InstantiationRange;
1072 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
1075 Name = std::string(
" '") + Parm->
getName().str() +
"'";
1078 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1079 TemplateParams = Template->getTemplateParameters();
1082 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1083 ->getTemplateParameters();
1085 diag::note_prior_template_arg_substitution)
1086 << isa<TemplateTemplateParmDecl>(Parm)
1089 Active->TemplateArgs,
1090 Active->NumTemplateArgs)
1091 << Active->InstantiationRange;
1097 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
1098 TemplateParams = Template->getTemplateParameters();
1101 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
1102 ->getTemplateParameters();
1105 diag::note_template_default_arg_checking)
1107 Active->TemplateArgs,
1108 Active->NumTemplateArgs)
1109 << Active->InstantiationRange;
1115 diag::note_evaluating_exception_spec_here)
1116 << cast<FunctionDecl>(Active->Entity);
1121 diag::note_template_exception_spec_instantiation_here)
1122 << cast<FunctionDecl>(Active->Entity)
1123 << Active->InstantiationRange;
1128 diag::note_template_requirement_instantiation_here)
1129 << Active->InstantiationRange;
1133 diag::note_template_requirement_params_instantiation_here)
1134 << Active->InstantiationRange;
1139 diag::note_nested_requirement_here)
1140 << Active->InstantiationRange;
1145 diag::note_in_declaration_of_implicit_special_member)
1146 << cast<CXXRecordDecl>(Active->Entity)
1147 << llvm::to_underlying(Active->SpecialMember);
1152 diag::note_in_declaration_of_implicit_equality_comparison);
1158 auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
1162 auto *MD = cast<CXXMethodDecl>(FD);
1164 diag::note_member_synthesized_at)
1165 << MD->isExplicitlyDefaulted()
1171 .getNonReferenceType()
1172 .getUnqualifiedType();
1174 diag::note_comparison_synthesized_at)
1182 diag::note_rewriting_operator_as_spaceship);
1187 diag::note_in_binding_decl_init)
1188 << cast<BindingDecl>(Active->Entity);
1193 diag::note_due_to_dllexported_class)
1194 << cast<CXXRecordDecl>(Active->Entity) << !
getLangOpts().CPlusPlus11;
1199 diag::note_building_builtin_dump_struct_call)
1209 diag::note_lambda_substitution_here);
1212 unsigned DiagID = 0;
1213 if (!Active->Entity) {
1215 diag::note_nested_requirement_here)
1216 << Active->InstantiationRange;
1219 if (isa<ConceptDecl>(Active->Entity))
1220 DiagID = diag::note_concept_specialization_here;
1221 else if (isa<TemplateDecl>(Active->Entity))
1222 DiagID = diag::note_checking_constraints_for_template_id_here;
1223 else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
1224 DiagID = diag::note_checking_constraints_for_var_spec_id_here;
1225 else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
1226 DiagID = diag::note_checking_constraints_for_class_spec_id_here;
1228 assert(isa<FunctionDecl>(Active->Entity));
1229 DiagID = diag::note_checking_constraints_for_function_here;
1232 llvm::raw_svector_ostream
OS(TemplateArgsStr);
1234 if (!isa<FunctionDecl>(Active->Entity)) {
1238 Diags.
Report(Active->PointOfInstantiation, DiagID) <<
OS.str()
1239 << Active->InstantiationRange;
1244 diag::note_constraint_substitution_here)
1245 << Active->InstantiationRange;
1249 diag::note_constraint_normalization_here)
1250 << cast<NamedDecl>(Active->Entity)->getName()
1251 << Active->InstantiationRange;
1255 diag::note_parameter_mapping_substitution_here)
1256 << Active->InstantiationRange;
1260 diag::note_building_deduction_guide_here);
1264 diag::note_template_type_alias_instantiation_here)
1265 << cast<TypeAliasTemplateDecl>(Active->Entity)
1266 << Active->InstantiationRange;
1274 return std::optional<TemplateDeductionInfo *>(
nullptr);
1279 Active != ActiveEnd;
1282 switch (Active->Kind) {
1286 if (isa<TypeAliasTemplateDecl>(Active->Entity))
1297 return std::nullopt;
1304 return std::nullopt;
1325 assert(Active->DeductionInfo &&
"Missing deduction info pointer");
1326 return Active->DeductionInfo;
1337 return std::nullopt;
1351 if (Active->SavedInNonInstantiationSFINAEContext)
1352 return std::optional<TemplateDeductionInfo *>(
nullptr);
1355 return std::nullopt;
1362 class TemplateInstantiator :
public TreeTransform<TemplateInstantiator> {
1367 bool EvaluateConstraints =
true;
1372 TemplateInstantiator(
Sema &SemaRef,
1375 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1378 void setEvaluateConstraints(
bool B) {
1379 EvaluateConstraints = B;
1381 bool getEvaluateConstraints() {
1382 return EvaluateConstraints;
1402 this->Entity = Entity;
1405 unsigned TransformTemplateDepth(
unsigned Depth) {
1410 int Index = getSema().ArgumentPackSubstitutionIndex;
1412 return std::nullopt;
1419 bool &ShouldExpand,
bool &RetainExpansion,
1420 std::optional<unsigned> &NumExpansions) {
1421 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
1422 PatternRange, Unexpanded,
1429 void ExpandingFunctionParameterPack(
ParmVarDecl *Pack) {
1439 unsigned Depth, Index;
1442 Result = TemplateArgs(Depth, Index);
1458 unsigned Depth, Index;
1468 void transformAttrs(
Decl *Old,
Decl *New) {
1475 for (
auto *New : NewDecls)
1477 Old, cast<VarDecl>(New));
1481 assert(NewDecls.size() == 1 &&
1482 "should only have multiple expansions for a pack");
1483 Decl *New = NewDecls.front();
1488 auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1490 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1491 if (
auto *NewTD = NewMD->getDescribedFunctionTemplate())
1492 NewTD->setInstantiatedFromMemberTemplate(
1493 OldMD->getDescribedFunctionTemplate());
1495 NewMD->setInstantiationOfMemberFunction(OldMD,
1503 if (
auto *DC = dyn_cast<DeclContext>(Old);
1504 DC && DC->isDependentContext() && DC->isFunctionOrMethod())
1545 NamedDecl *FirstQualifierInScope =
nullptr,
1546 bool AllowInjectedClassName =
false);
1548 const CXXAssumeAttr *TransformCXXAssumeAttr(
const CXXAssumeAttr *AA);
1549 const LoopHintAttr *TransformLoopHintAttr(
const LoopHintAttr *LH);
1550 const NoInlineAttr *TransformStmtNoInlineAttr(
const Stmt *OrigS,
1552 const NoInlineAttr *A);
1553 const AlwaysInlineAttr *
1554 TransformStmtAlwaysInlineAttr(
const Stmt *OrigS,
const Stmt *InstS,
1555 const AlwaysInlineAttr *A);
1556 const CodeAlignAttr *TransformCodeAlignAttr(
const CodeAlignAttr *CA);
1563 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1565 ExprResult TransformSubstNonTypeTemplateParmExpr(
1582 return inherited::TransformFunctionProtoType(TLB, TL);
1587 auto Type = inherited::TransformInjectedClassNameType(TLB, TL);
1590 if (
Type.isNull() &&
1597 inherited::TransformType(ICT->getInjectedSpecializationType());
1608 bool Uneval =
false) {
1610 std::vector<TemplateArgument> TArgs;
1618 "Transforming a template argument pack is only allowed in building "
1635 return inherited::TransformTemplateArgument(Input, Output, Uneval);
1638 template<
typename Fn>
1643 Fn TransformExceptionSpec);
1646 TransformFunctionTypeParam(
ParmVarDecl *OldParm,
int indexAdjustment,
1647 std::optional<unsigned> NumExpansions,
1648 bool ExpectParameterPack);
1650 using inherited::TransformTemplateTypeParmType;
1655 bool SuppressObjCLifetime);
1657 QualType BuildSubstTemplateTypeParmType(
1659 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
1665 using inherited::TransformSubstTemplateTypeParmPackType;
1669 bool SuppressObjCLifetime);
1676 unsigned TypeAliasDeclDepth = CCS.Entity->getTemplateDepth();
1678 return CXXRecordDecl::LambdaDependencyKind::LDK_AlwaysDependent;
1680 return inherited::ComputeLambdaDependency(LSI);
1687 ExprResult Result = inherited::TransformLambdaExpr(E);
1688 if (Result.isInvalid())
1693 assert(PVD &&
"null in a parameter list");
1694 if (!PVD->hasDefaultArg())
1696 Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1705 { UninstExpr }, UninstExpr->
getType());
1707 PVD->setDefaultArg(ErrorResult.
get());
1724 bool Prev = EvaluateConstraints;
1725 EvaluateConstraints =
true;
1727 EvaluateConstraints = Prev;
1733 ExprResult TransReq = inherited::TransformRequiresExpr(E);
1736 assert(TransReq.
get() != E &&
1737 "Do not change value of isSatisfied for the existing expression. "
1738 "Create a new expression instead.");
1745 if (Trap.hasErrorOccurred())
1751 bool TransformRequiresExprRequirements(
1754 bool SatisfactionDetermined =
false;
1757 if (!SatisfactionDetermined) {
1758 if (
auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1759 TransReq = TransformTypeRequirement(TypeReq);
1760 else if (
auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1761 TransReq = TransformExprRequirement(ExprReq);
1763 TransReq = TransformNestedRequirement(
1764 cast<concepts::NestedRequirement>(Req));
1773 SatisfactionDetermined =
true;
1776 Transformed.push_back(TransReq);
1783 if (!OrigTPL || !OrigTPL->
size())
return OrigTPL;
1787 Owner, TemplateArgs);
1788 DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1789 return DeclInstantiator.SubstTemplateParams(OrigTPL);
1807 transformNonTypeTemplateParmRef(
Decl *AssociatedDecl,
1810 std::optional<unsigned> PackIndex);
1814bool TemplateInstantiator::AlreadyTransformed(
QualType T) {
1821 getSema().MarkDeclarationsReferencedInType(Loc,
T);
1846 TTP->getPosition()))
1851 if (TTP->isParameterPack()) {
1853 "Missing argument pack");
1859 "Wrong kind of template template argument");
1871 Decl *Inst = getSema().SubstDecl(D, getSema().
CurContext, TemplateArgs);
1875 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1879bool TemplateInstantiator::TransformExceptionSpec(
1886 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
1890TemplateInstantiator::TransformFirstQualifierInScope(
NamedDecl *D,
1904 "Missing argument pack");
1914 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1917 return Tag->getDecl();
1920 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) <<
T;
1925 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1929TemplateInstantiator::RebuildExceptionDecl(
VarDecl *ExceptionDecl,
1935 StartLoc, NameLoc, Name);
1937 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1941VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(
VarDecl *ExceptionDecl,
1944 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo,
T);
1946 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1951TemplateInstantiator::RebuildElaboratedType(
SourceLocation KeywordLoc,
1969 SemaRef.
Diag(TagLocation, diag::err_use_with_wrong_tag)
1978 return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc,
T);
1981TemplateName TemplateInstantiator::TransformTemplateName(
1984 bool AllowInjectedClassName) {
1986 = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1993 TTP->getPosition()))
2003 "unexpected pack arguments in template rewrite");
2007 "unexpected nontype template argument kind in template rewrite");
2011 auto [AssociatedDecl, Final] =
2013 std::optional<unsigned> PackIndex;
2016 "Missing argument pack");
2022 return getSema().Context.getSubstTemplateTemplateParmPack(
2023 Arg, AssociatedDecl, TTP->
getIndex(), Final);
2026 PackIndex = getPackIndex(Arg);
2031 assert(!Template.
isNull() &&
"Null template template argument");
2033 "template decl to substitute is qualified?");
2037 return getSema().Context.getSubstTemplateTemplateParm(
2038 Template, AssociatedDecl, TTP->
getIndex(), PackIndex);
2043 = Name.getAsSubstTemplateTemplateParmPack()) {
2050 if (SubstPack->getFinal())
2052 return getSema().Context.getSubstTemplateTemplateParm(
2054 SubstPack->getIndex(), getPackIndex(Pack));
2057 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
2058 FirstQualifierInScope,
2059 AllowInjectedClassName);
2063TemplateInstantiator::TransformPredefinedExpr(
PredefinedExpr *E) {
2071TemplateInstantiator::TransformTemplateParmRefExpr(
DeclRefExpr *E,
2088 "unexpected pack arguments in template rewrite");
2092 "unexpected nontype template argument kind in template rewrite");
2099 std::optional<unsigned> PackIndex;
2102 "Missing argument pack");
2122 PackIndex = getPackIndex(Arg);
2126 return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP, E->
getLocation(),
2130const CXXAssumeAttr *
2131TemplateInstantiator::TransformCXXAssumeAttr(
const CXXAssumeAttr *AA) {
2132 ExprResult Res = getDerived().TransformExpr(AA->getAssumption());
2136 Res = getSema().BuildCXXAssumeExpr(Res.
get(), AA->getAttrName(),
2141 return CXXAssumeAttr::CreateImplicit(getSema().
Context, Res.
get(),
2146TemplateInstantiator::TransformLoopHintAttr(
const LoopHintAttr *LH) {
2147 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
2149 if (TransformedExpr == LH->getValue())
2154 LH->getOption() == LoopHintAttr::UnrollCount))
2159 return LoopHintAttr::CreateImplicit(getSema().
Context, LH->getOption(),
2160 LH->getState(), TransformedExpr, *LH);
2162const NoInlineAttr *TemplateInstantiator::TransformStmtNoInlineAttr(
2163 const Stmt *OrigS,
const Stmt *InstS,
const NoInlineAttr *A) {
2169const AlwaysInlineAttr *TemplateInstantiator::TransformStmtAlwaysInlineAttr(
2170 const Stmt *OrigS,
const Stmt *InstS,
const AlwaysInlineAttr *A) {
2177const CodeAlignAttr *
2178TemplateInstantiator::TransformCodeAlignAttr(
const CodeAlignAttr *CA) {
2179 Expr *TransformedExpr = getDerived().TransformExpr(CA->getAlignment()).get();
2180 return getSema().BuildCodeAlignAttr(*CA, TransformedExpr);
2183ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
2186 std::optional<unsigned> PackIndex) {
2191 auto SubstParamType = [&] {
2198 T = cast<PackExpansionType>(
T)->getPattern();
2202 bool refParam =
false;
2208 Expr *argExpr =
arg.getAsExpr();
2213 QualType paramType = SubstParamType();
2228 VD = cast_or_null<ValueDecl>(
2234 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2235 assert(!paramType.
isNull() &&
"type substitution failed for param type");
2236 assert(!paramType->
isDependentType() &&
"param type still dependent");
2240 QualType paramType =
arg.getNonTypeTemplateArgumentType();
2251 Expr *resultExpr = result.
get();
2255 AssociatedDecl, parm->
getIndex(), PackIndex, refParam);
2259TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
2269 return transformNonTypeTemplateParmRef(
2275TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
2278 if (!isa<ConstantExpr>(SubstReplacement.
get()))
2308 SubstReplacement.
get(), SugaredConverted,
2320 return getSema().BuildDeclarationNameExpr(
CXXScopeSpec(), NameInfo, PD);
2331 return RebuildVarDeclRefExpr(VD, E->
getExprLoc());
2353 getSema().MarkFunctionParmPackReferenced(PackExpr);
2358TemplateInstantiator::TransformFunctionParmPackRefExpr(
DeclRefExpr *E,
2361 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
2362 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
2363 assert(Found &&
"no instantiation for parameter pack");
2365 Decl *TransformedDecl;
2366 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
2375 getSema().MarkFunctionParmPackReferenced(PackExpr);
2379 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
2381 TransformedDecl = Found->get<
Decl*>();
2385 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->
getExprLoc());
2389TemplateInstantiator::TransformDeclRefExpr(
DeclRefExpr *E) {
2396 return TransformTemplateParmRefExpr(E, NTTP);
2403 if (
VarDecl *PD = dyn_cast<VarDecl>(D))
2405 return TransformFunctionParmPackRefExpr(E, PD);
2407 return inherited::TransformDeclRefExpr(E);
2410ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
2413 getDescribedFunctionTemplate() &&
2414 "Default arg expressions are never formed in dependent cases.");
2420template<
typename Fn>
2425 Fn TransformExceptionSpec) {
2428 return inherited::TransformFunctionProtoType(
2429 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
2432ParmVarDecl *TemplateInstantiator::TransformFunctionTypeParam(
2434 std::optional<unsigned> NumExpansions,
bool ExpectParameterPack) {
2436 OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2437 ExpectParameterPack, EvaluateConstraints);
2443QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2445 Decl *AssociatedDecl,
unsigned Index, std::optional<unsigned> PackIndex,
2451 if (SuppressObjCLifetime) {
2453 RQs = Replacement.getQualifiers();
2464 QualType Result = getSema().Context.getSubstTemplateTypeParmType(
2465 Replacement, AssociatedDecl, Index, PackIndex);
2473TemplateInstantiator::TransformTemplateTypeParmType(
TypeLocBuilder &TLB,
2475 bool SuppressObjCLifetime) {
2499 "unexpected pack arguments in template rewrite");
2503 "unexpected nontype template argument kind in template rewrite");
2509 auto [AssociatedDecl, Final] =
2511 std::optional<unsigned> PackIndex;
2512 if (
T->isParameterPack()) {
2514 "Missing argument pack");
2520 QualType Result = getSema().Context.getSubstTemplateTypeParmPackType(
2521 AssociatedDecl,
T->getIndex(), Final, Arg);
2529 PackIndex = getPackIndex(Arg);
2534 "Template argument kind mismatch");
2536 return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2537 AssociatedDecl,
T->getIndex(),
2547 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2551 T->isParameterPack(), NewTTPDecl);
2557QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2559 bool SuppressObjCLifetime) {
2562 Decl *NewReplaced = TransformDecl(TL.
getNameLoc(),
T->getAssociatedDecl());
2567 if (NewReplaced !=
T->getAssociatedDecl())
2568 Result = getSema().Context.getSubstTemplateTypeParmPackType(
2569 NewReplaced,
T->getIndex(),
T->getFinal(),
T->getArgumentPack());
2578 return BuildSubstTemplateTypeParmType(
2579 TLB, SuppressObjCLifetime,
T->getFinal(), NewReplaced,
T->getIndex(),
2593 ErrorLoc = PDA.first;
2597 char *MessageBuf =
new (S.
Context)
char[Message.size()];
2598 std::copy(Message.begin(), Message.end(), MessageBuf);
2600 llvm::raw_svector_ostream
OS(Entity);
2602 char *EntityBuf =
new (S.
Context)
char[Entity.size()];
2603 std::copy(Entity.begin(), Entity.end(), EntityBuf);
2605 StringRef(EntityBuf, Entity.size()), ErrorLoc,
2606 StringRef(MessageBuf, Message.size())};
2613 llvm::raw_svector_ostream
OS(Entity);
2615 char *EntityBuf =
new (S.
Context)
char[Entity.size()];
2616 llvm::copy(Entity, EntityBuf);
2618 StringRef(EntityBuf, Entity.size()),
2619 Location, StringRef()};
2622ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2636 if (getDerived().TransformFunctionTypeParams(
2637 KWLoc, Params,
nullptr,
nullptr, PTypes,
2638 &TransParams, PInfos, &ErrorIdx) ||
2639 Trap.hasErrorOccurred()) {
2645 SemaRef, Info, [&](llvm::raw_ostream &
OS) {
OS << *FailedDecl; })));
2646 return getDerived().RebuildRequiresExpr(KWLoc, Body, RE->
getLParenLoc(),
2648 TransReqs, RBraceLoc);
2659 if (AlwaysRebuild())
2660 return RebuildTypeRequirement(
2670 if (TypeInst.isInvalid())
2673 if (!TransType || Trap.hasErrorOccurred())
2675 [&] (llvm::raw_ostream&
OS) {
2678 return RebuildTypeRequirement(TransType);
2688 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2697 if (ExprInst.isInvalid())
2700 if (!TransExprRes.
isInvalid() && !Trap.hasErrorOccurred() &&
2703 if (TransExprRes.
isInvalid() || Trap.hasErrorOccurred())
2708 TransExpr = TransExprRes.
get();
2711 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
2713 if (RetReq.isEmpty())
2714 TransRetReq.emplace();
2715 else if (RetReq.isSubstitutionFailure())
2716 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2717 else if (RetReq.isTypeConstraint()) {
2719 RetReq.getTypeConstraintTemplateParameterList();
2723 if (TPLInst.isInvalid())
2728 [&] (llvm::raw_ostream&
OS) {
2729 RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2734 TransRetReq.emplace(TPL);
2737 assert(TransRetReq &&
"All code paths leading here must set TransRetReq");
2738 if (
Expr *E = TransExpr.dyn_cast<
Expr *>())
2740 std::move(*TransRetReq));
2741 return RebuildExprRequirement(
2747TemplateInstantiator::TransformNestedRequirement(
2752 if (AlwaysRebuild())
2761 if (!getEvaluateConstraints()) {
2763 if (TransConstraint.
isInvalid() || !TransConstraint.
get())
2783 if (ConstrInst.isInvalid())
2787 nullptr, {Req->getConstraintExpr()},
Result, TemplateArgs,
2790 TransConstraint =
Result[0];
2791 assert(!Trap.hasErrorOccurred() &&
"Substitution failures must be handled "
2792 "by CheckConstraintSatisfaction.");
2798 if (TransConstraint.
isInvalid() || !TransConstraint.
get() ||
2801 llvm::raw_svector_ostream
OS(Entity);
2805 std::copy(Entity.begin(), Entity.end(), EntityBuf);
2807 SemaRef.
Context, StringRef(EntityBuf, Entity.size()), Satisfaction);
2848 bool AllowDeducedTST) {
2850 "Cannot perform an instantiation without some context on the "
2851 "instantiation stack");
2857 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2858 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(
T)
2859 : Instantiator.TransformType(
T);
2867 "Cannot perform an instantiation without some context on the "
2868 "instantiation stack");
2882 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2897 "Cannot perform an instantiation without some context on the "
2898 "instantiation stack");
2905 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc, Entity);
2906 return Instantiator.TransformType(
T);
2914 TypeLoc TL =
T->getTypeLoc().IgnoreParens();
2941 bool EvaluateConstraints) {
2943 "Cannot perform an instantiation without some context on the "
2944 "instantiation stack");
2949 TemplateInstantiator Instantiator(*
this, Args, Loc, Entity);
2950 Instantiator.setEvaluateConstraints(EvaluateConstraints);
2966 Result = Instantiator.TransformFunctionProtoType(
2967 TLB, Proto, ThisContext, ThisTypeQuals,
2969 bool &Changed) {
return false; });
2971 Result = Instantiator.TransformType(TLB, TL);
2985 bool Changed =
false;
2986 TemplateInstantiator Instantiator(*
this, Args, Loc,
DeclarationName());
2987 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
2998 ESI, ExceptionStorage, Args))
3007 struct GetContainedInventedTypeParmVisitor :
3008 public TypeVisitor<GetContainedInventedTypeParmVisitor,
3009 TemplateTypeParmDecl *> {
3010 using TypeVisitor<GetContainedInventedTypeParmVisitor,
3016 return Visit(
T.getTypePtr());
3021 if (!
T->getDecl() || !
T->getDecl()->isImplicit())
3023 return T->getDecl();
3030 return Visit(
T->getNamedType());
3042 return Visit(
T->getPointeeTypeAsWritten());
3050 return Visit(
T->getElementType());
3055 return Visit(
T->getElementType());
3059 return Visit(
T->getElementType());
3063 return VisitFunctionType(
T);
3071 return Visit(
T->getInnerType());
3075 return Visit(
T->getModifiedType());
3079 return Visit(
T->getUnderlyingType());
3083 return Visit(
T->getOriginalType());
3087 return Visit(
T->getPattern());
3096 bool EvaluateConstraints) {
3100 if (!EvaluateConstraints) {
3127 int indexAdjustment, std::optional<unsigned> NumExpansions,
3128 bool ExpectParameterPack,
bool EvaluateConstraint) {
3137 NewDI =
SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
3148 }
else if (ExpectParameterPack) {
3154 diag::err_function_parameter_pack_without_parameter_packs)
3178 GetContainedInventedTypeParmVisitor().Visit(OldDI->
getType())) {
3180 auto *Inst = cast_or_null<TemplateTypeParmDecl>(
3185 if (Inst && !Inst->getTypeConstraint()) {
3257 "Cannot perform an instantiation without some context on the "
3258 "instantiation stack");
3260 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
3262 return Instantiator.TransformFunctionTypeParams(
3263 Loc, Params,
nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
3282 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
3294 std::unique_ptr<LocalInstantiationScope> LIS;
3303 LIS = std::make_unique<LocalInstantiationScope>(*
this);
3306 if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
3309 if (PrimaryTemplate && PrimaryTemplate->
isOutOfLine()) {
3315 CurrentTemplateArgumentList->
asArray(),
true);
3337 Result = InitSeq.Perform(*
this, Entity, Kind, ResultE);
3370 for (
const auto &
Base : Pattern->
bases()) {
3371 if (!
Base.getType()->isDependentType()) {
3373 if (RD->isInvalidDecl())
3382 if (
Base.isPackExpansion()) {
3388 bool ShouldExpand =
false;
3389 bool RetainExpansion =
false;
3390 std::optional<unsigned> NumExpansions;
3392 Base.getSourceRange(),
3394 TemplateArgs, ShouldExpand,
3403 for (
unsigned I = 0; I != *NumExpansions; ++I) {
3408 Base.getSourceRange().getBegin(),
3417 Base.getSourceRange(),
3419 Base.getAccessSpecifierAsWritten(),
3422 InstantiatedBases.push_back(InstantiatedBase);
3431 EllipsisLoc =
Base.getEllipsisLoc();
3435 Base.getSourceRange().getBegin(),
3440 Base.getSourceRange().getBegin(),
3451 Base.getSourceRange(),
3453 Base.getAccessSpecifierAsWritten(),
3456 InstantiatedBases.push_back(InstantiatedBase);
3510 Pattern, PatternDef, TSK, Complain))
3513 llvm::TimeTraceScope TimeScope(
"InstantiateClass", [&]() {
3515 llvm::raw_string_ostream
OS(Name);
3521 Pattern = PatternDef;
3527 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3529 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3530 Spec->setTemplateSpecializationKind(TSK);
3531 Spec->setPointOfInstantiation(PointOfInstantiation);
3539 "instantiating class definition");
3557 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*
this);
3583 bool MightHaveConstexprVirtualFunctions =
false;
3594 if (
Member->getDeclContext() != Pattern)
3601 if (isa<BlockDecl>(
Member) ||
3602 (isa<CXXRecordDecl>(
Member) && cast<CXXRecordDecl>(
Member)->isLambda()))
3605 if (
Member->isInvalidDecl()) {
3612 if (
FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3613 Fields.push_back(Field);
3614 }
else if (
EnumDecl *
Enum = dyn_cast<EnumDecl>(NewMember)) {
3620 Enum->isCompleteDefinition()) {
3622 assert(MSInfo &&
"no spec info for member enum specialization");
3627 if (SA->isFailed()) {
3633 }
else if (
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3636 MightHaveConstexprVirtualFunctions =
true;
3657 if (ParsingClassDepth == 0)
3662 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3663 E = LateAttrs.end(); I != E; ++I) {
3668 auto *ND = cast<NamedDecl>(I->NewDecl);
3669 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3671 ND->isCXXInstanceMember());
3676 I->NewDecl->addAttr(NewAttr);
3705 P->first,
P->second)) {
3718 P->first,
P->second)) {
3735 else if (MightHaveConstexprVirtualFunctions)
3767 Pattern, PatternDef, TSK,
true))
3769 Pattern = PatternDef;
3775 MSInfo->setPointOfInstantiation(PointOfInstantiation);
3784 "instantiating enum definition");
3834 "pattern and instantiation disagree about init style");
3842 Diag(PointOfInstantiation,
3843 diag::err_default_member_initializer_not_yet_parsed)
3844 << OutermostClass << Pattern;
3845 Diag(Pattern->getEndLoc(),
3846 diag::note_default_member_initializer_not_yet_parsed);
3856 Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3861 "instantiating default member init");
3869 PointOfInstantiation, Instantiation,
CurContext};
3880 assert((!
Init || !isa<ParenListExpr>(
Init)) &&
"call-style init in class");
3885 L->DefaultMemberInitializerInstantiated(Instantiation);
3894 struct PartialSpecMatchResult {
3909 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3954 for (
unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3967 Matched.push_back(PartialSpecMatchResult());
3968 Matched.back().Partial = Partial;
3977 if (Matched.size() >= 1) {
3979 if (Matched.size() == 1) {
3992 PEnd = Matched.end();
3995 P->Partial, Best->Partial, PointOfInstantiation) ==
4002 bool Ambiguous =
false;
4004 PEnd = Matched.end();
4007 P->Partial, Best->Partial,
4008 PointOfInstantiation) != Best->Partial) {
4018 S.
Diag(PointOfInstantiation,
4019 diag::err_partial_spec_ordering_ambiguous)
4020 << ClassTemplateSpec;
4024 PEnd = Matched.end();
4026 S.
Diag(
P->Partial->getLocation(), diag::note_partial_spec_match)
4028 P->Partial->getTemplateParameters(), *
P->Args);
4043 if (
auto *PartialSpec =
4046 while (PartialSpec->getInstantiatedFromMember()) {
4049 if (PartialSpec->isMemberSpecialization())
4052 PartialSpec = PartialSpec->getInstantiatedFromMember();
4054 Pattern = PartialSpec;
4076 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
4083 ClassTemplateSpec, TSK);
4088 PointOfInstantiation, ClassTemplateSpec, Pattern.
get(),
4107 "Unexpected template specialization kind!");
4108 for (
auto *D : Instantiation->
decls()) {
4109 bool SuppressNew =
false;
4110 if (
auto *
Function = dyn_cast<FunctionDecl>(D)) {
4112 Function->getInstantiatedFromMemberFunction()) {
4114 if (
Function->isIneligibleOrNotSelected())
4117 if (
Function->getTrailingRequiresClause()) {
4125 if (
Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4129 Function->getMemberSpecializationInfo();
4130 assert(MSInfo &&
"No member specialization information?");
4152 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
4162 std::make_pair(
Function, PointOfInstantiation));
4165 }
else if (
auto *Var = dyn_cast<VarDecl>(D)) {
4166 if (isa<VarTemplateSpecializationDecl>(Var))
4170 if (Var->
hasAttr<ExcludeFromExplicitInstantiationAttr>())
4174 assert(MSInfo &&
"No member specialization information?");
4203 }
else if (
auto *
Record = dyn_cast<CXXRecordDecl>(D)) {
4204 if (
Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
4212 if (
Record->isInjectedClassName() ||
Record->getPreviousDecl() ||
4217 assert(MSInfo &&
"No member specialization information?");
4243 assert(Pattern &&
"Missing instantiated-from-template information");
4245 if (!
Record->getDefinition()) {
4266 Record->getTemplateSpecializationKind() ==
4268 Record->setTemplateSpecializationKind(TSK);
4273 Pattern = cast_or_null<CXXRecordDecl>(
Record->getDefinition());
4277 }
else if (
auto *
Enum = dyn_cast<EnumDecl>(D)) {
4279 assert(MSInfo &&
"No member specialization information?");
4286 PointOfInstantiation, TSK,
Enum,
4292 if (
Enum->getDefinition())
4295 EnumDecl *Pattern =
Enum->getTemplateInstantiationPattern();
4296 assert(Pattern &&
"Missing instantiated-from-template information");
4307 }
else if (
auto *Field = dyn_cast<FieldDecl>(D)) {
4314 ClassPattern->
lookup(Field->getDeclName());
4350 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4353 return Instantiator.TransformStmt(S);
4360 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4362 return Instantiator.TransformTemplateArgument(Input, Output);
4369 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4371 return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
4379 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4382 return Instantiator.TransformExpr(E);
4398 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4400 Instantiator.setEvaluateConstraints(
false);
4401 return Instantiator.TransformExpr(E);
4406 bool CXXDirectInit) {
4407 TemplateInstantiator Instantiator(*
this, TemplateArgs,
SourceLocation(),
4409 return Instantiator.TransformInitializer(
Init, CXXDirectInit);
4418 TemplateInstantiator Instantiator(*
this, TemplateArgs,
4421 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
4431 TemplateInstantiator Instantiator(*
this, TemplateArgs, NNS.
getBeginLoc(),
4433 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
4440 TemplateInstantiator Instantiator(*
this, TemplateArgs, NameInfo.
getLoc(),
4442 return Instantiator.TransformDeclarationNameInfo(NameInfo);
4449 TemplateInstantiator Instantiator(*
this, TemplateArgs, Loc,
4452 SS.
Adopt(QualifierLoc);
4453 return Instantiator.TransformTemplateName(SS, Name, Loc);
4461 if (
const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
4462 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
4463 unsigned i = PV->getFunctionScopeIndex();
4466 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
4474llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4478 Current = Current->Outer) {
4481 const Decl *CheckD = D;
4483 LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
4484 if (Found != Current->LocalDecls.end())
4485 return &Found->second;
4489 if (
const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4496 if (!Current->CombineWithOuterScope)
4502 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
4503 isa<TemplateTemplateParmDecl>(D))
4508 if (RD->isLocalClass())
4513 if (isa<EnumDecl>(D))
4518 if (isa<TypedefNameDecl>(D) &&
4525 assert(isa<LabelDecl>(D) &&
"declaration not instantiated in this scope");
4531 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4532 if (Stored.isNull()) {
4536 while (Current->CombineWithOuterScope && Current->Outer) {
4537 Current = Current->Outer;
4538 assert(!Current->LocalDecls.contains(D) &&
4539 "Instantiated local in inner and outer scopes");
4544 Pack->push_back(cast<VarDecl>(Inst));
4546 assert(Stored.get<
Decl *>() == Inst &&
"Already instantiated this local");
4554 Pack->push_back(Inst);
4561 Current && Current->CombineWithOuterScope; Current = Current->Outer)
4562 assert(!Current->LocalDecls.contains(D) &&
4563 "Creating local pack after instantiation of local");
4567 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4570 ArgumentPacks.push_back(Pack);
4575 if (llvm::is_contained(*Pack, D))
4582 unsigned NumExplicitArgs) {
4583 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4584 "Already have a partially-substituted pack");
4585 assert((!PartiallySubstitutedPack
4586 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4587 "Wrong number of arguments in partially-substituted pack");
4588 PartiallySubstitutedPack = Pack;
4589 ArgsInPartiallySubstitutedPack = ExplicitArgs;
4590 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4595 unsigned *NumExplicitArgs)
const {
4597 *ExplicitArgs =
nullptr;
4598 if (NumExplicitArgs)
4599 *NumExplicitArgs = 0;
4602 Current = Current->Outer) {
4603 if (Current->PartiallySubstitutedPack) {
4605 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4606 if (NumExplicitArgs)
4607 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4609 return Current->PartiallySubstitutedPack;
4612 if (!Current->CombineWithOuterScope)
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the C++ template declaration subclasses.
Defines Expressions and AST nodes for C++2a concepts.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
MatchFinder::MatchResult MatchResult
static const Decl * getCanonicalParmVarDecl(const Decl *D)
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, concepts::EntityPrinter Printer)
static ActionResult< CXXRecordDecl * > getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
Defines utilities for dealing with stack allocation and stack space.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const clang::PrintingPolicy & getPrintingPolicy() const
const TargetInfo & getTargetInfo() const
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Attr - This represents one attribute.
An attributed type is a type to which a type attribute has been applied.
Represents a base class of a C++ class.
A default argument (C++ [dcl.fct.default]).
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
const ParmVarDecl * getParam() const
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXRecordDecl * getDefinition() const
unsigned getNumBases() const
Retrieves the number of base classes of this class.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Represents a C++ nested-name-specifier or a global scope specifier.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)?...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
NamedDecl * getFoundDecl() const
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
bool HasSubstitutionFailure()
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isFileContext() const
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.
A reference to a declared variable, function, enum, etc.
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,...
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
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).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
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.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Information about one declarator, including the parsed type information and the identifier.
Represents an extended vector type where either the type or size is dependent.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool hasFatalErrorOccurred() const
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
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,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class,...
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
EnumDecl * getDefinition() const
This represents one expression.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
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.
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.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
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.
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
VarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
VarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
VarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl * > Params)
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...
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
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 the sequence of initializations required to initialize a given object or reference with a s...
Describes an entity that is being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
Wrapper for source info for injected class names of class templates.
The injected class name of a C++ class template or class template partial specialization.
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...
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.
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)
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.
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Provides information a specialization of a member of a class template, which may be a member function...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Describes a module or submodule.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
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 getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Represents a pack expansion of types.
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
void setDefaultArg(Expr *defarg)
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)
PointerType - C99 6.7.5.1 - Pointer Declarators.
[C99 6.4.2.2] - A predefined identifier such as func.
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.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
The collection of all-type qualifiers we support.
void removeObjCLifetime()
Represents a struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Base for LValueReferenceType and RValueReferenceType.
Represents the body of a requires-expression.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
RequiresExprBodyDecl * getBody() const
Scope - A scope is a transient data structure that is used while parsing the program.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
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.
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, bool &RetainExpansion, std::optional< unsigned > &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, std::optional< unsigned > NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
void ActOnFinishCXXNonNestedClass()
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation.
void ActOnFinishDelayedMemberInitializers(Decl *Record)
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, NamedDecl *Instantiation, bool InstantiatedFromMember, const NamedDecl *Pattern, const NamedDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
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 ...
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
void deduceOpenCLAddressSpace(ValueDecl *decl)
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
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 InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
DiagnosticsEngine & getDiagnostics() const
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
ExprResult BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
ExprResult SubstConstraintExprWithoutSatisfaction(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
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 SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain=true)
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 CheckConstraintSatisfaction(const NamedDecl *Template, ArrayRef< const Expr * > ConstraintExprs, const MultiLevelTemplateArgumentList &TemplateArgLists, SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction)
Check whether the given list of constraint expressions are satisfied (as if in a 'conjunction') given...
void InstantiateClassMembers(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiates the definitions of all of the member of the given class, which is an instantiation of a ...
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained).
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
void popCodeSynthesisContext()
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
void pushCodeSynthesisContext(CodeSynthesisContext Ctx)
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero)
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base 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...
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
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...
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, const AttributeCommonInfo &A)
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, Expr *Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member,...
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param, Expr *Init=nullptr)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed.
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
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 AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, ConceptDecl *NamedConcept, NamedDecl *FoundDecl, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
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)
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
@ 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 CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &SugaredConverted, SmallVectorImpl< TemplateArgument > &CanonicalConverted, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
DiagnosticsEngine & Diags
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier * > Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
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)
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentLoc &Output)
ExprResult BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc)
Given a non-type template argument that refers to a declaration and the type of its corresponding non...
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
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)
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)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
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.
A trivial tuple used to represent a source range.
Represents a C++11 static_assert declaration.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a reference to a non-type template parameter that has been substituted with a template arg...
std::optional< unsigned > getPackIndex() const
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
QualType getParameterType(const ASTContext &Ctx) const
Determine the substituted type of the template parameter.
NonTypeTemplateParmDecl * getParameter() const
Expr * getReplacement() const
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
A structure for storing an already-substituted template template parameter pack.
Wrapper for substituted template type parameters.
Represents the result of substituting a set of types for a template type parameter pack.
Wrapper for substituted template type parameters.
Represents the declaration of a struct/union/class/enum.
void setTagKind(TagKind TK)
SourceRange getBraceRange() const
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
StringRef getKindName() const
void startDefinition()
Starts the definition of this tag declaration.
TagKind getTagKind() const
void setBraceRange(SourceRange R)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
A template argument list.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
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.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool isNull() const
Determine whether this template argument has no value.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ 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.
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
void disableLateAttributeInstantiation()
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
void setEvaluateConstraints(bool B)
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
LocalInstantiationScope * getStartingScope() const
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
bool isNull() const
Determine whether this template name is NULL.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
TemplateName getNameToSubstitute() const
Get the template name to substitute when this template name is used as a template template argument.
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.
Represents a type template specialization; the template must be a class template, a type alias templa...
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.
bool isParameterPack() const
Returns whether this is a parameter pack.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
Wrapper for template type parameters.
bool isParameterPack() const
unsigned getIndex() const
unsigned getDepth() const
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() 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 getEndLoc() const
Get the end source location.
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)
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
The base class of the type hierarchy.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isStaticDataMember() const
Determines whether this is a static data member.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
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.
Represents a GCC generic vector type.
A requires-expression requirement which queries the validity and properties of an expression ('simple...
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...
A requires-expression requirement which queries the existence of a type name or type template special...
bool isSubstitutionFailure() const
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
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.
Defines the clang::TargetInfo interface.
Requirement::SubstitutionDiagnostic * createSubstDiagAt(Sema &S, SourceLocation Location, EntityPrinter Printer)
create a Requirement::SubstitutionDiagnostic with only a SubstitutedEntity and DiagLoc using Sema's a...
llvm::function_ref< void(llvm::raw_ostream &)> EntityPrinter
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
The JSON file list parser is used to communicate input to InstallAPI.
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
NamedDecl * getAsNamedDecl(TemplateParameter P)
bool isStackNearlyExhausted()
Determine whether the stack is nearly exhausted.
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
TagTypeKind
The kind of a tag type.
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...
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
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.
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ None
No keyword precedes the qualified type name.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
Holds information about the various types of exception specification.
ExceptionSpecificationType Type
The kind of exception specification this is.
ExceptionSpecInfo ExceptionSpec
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation,...
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
SynthesisKind
The kind of template instantiation we are performing.
@ MarkingClassDllexported
We are marking a class as __dllexport.
@ RequirementParameterInstantiation
@ DefaultTemplateArgumentInstantiation
We are instantiating a default argument for a template parameter.
@ ExplicitTemplateArgumentSubstitution
We are substituting explicit template arguments provided for a function template.
@ DefaultTemplateArgumentChecking
We are checking the validity of a default template argument that has been used when naming a template...
@ InitializingStructuredBinding
We are initializing a structured binding.
@ ExceptionSpecInstantiation
We are instantiating the exception specification for a function template which was deferred until it ...
@ NestedRequirementConstraintsCheck
We are checking the satisfaction of a nested requirement of a requires expression.
@ BuildingBuiltinDumpStructCall
We are building an implied call from __builtin_dump_struct.
@ ParameterMappingSubstitution
@ DefiningSynthesizedFunction
We are defining a synthesized function (such as a defaulted special member).
@ Memoization
Added for Template instantiation observation.
@ ConstraintNormalization
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
@ TypeAliasTemplateInstantiation
We are instantiating a type alias template declaration.
@ BuildingDeductionGuides
We are building deduction guides for a class.
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
@ PriorTemplateArgumentSubstitution
We are substituting prior template arguments into a new template parameter.
@ ExceptionSpecEvaluation
We are computing the exception specification for a defaulted special member function.
@ TemplateInstantiation
We are instantiating a template declaration.
@ DeclaringSpecialMember
We are declaring an implicit special member function.
@ DeclaringImplicitEqualityComparison
We are declaring an implicit 'operator==' for a defaulted 'operator<=>'.
@ DefaultFunctionArgumentInstantiation
We are instantiating a default argument for a function.
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Decl * Entity
The entity that is being synthesized.
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
A stack object to be created when performing template instantiation.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template,...
void Clear()
Note that we have finished instantiating this template.
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)