44#include "llvm/ADT/ArrayRef.h"
45#include "llvm/ADT/STLExtras.h"
46#include "llvm/ADT/SmallVector.h"
47#include "llvm/Support/Casting.h"
48#include "llvm/Support/ErrorHandling.h"
59class ExtractTypeForDeductionGuide
61 llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs;
62 ClassTemplateDecl *NestedPattern;
63 const MultiLevelTemplateArgumentList *OuterInstantiationArgs;
64 std::optional<TemplateDeclInstantiator> TypedefNameInstantiator;
67 typedef TreeTransform<ExtractTypeForDeductionGuide> Base;
68 ExtractTypeForDeductionGuide(
70 llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs,
71 ClassTemplateDecl *NestedPattern =
nullptr,
72 const MultiLevelTemplateArgumentList *OuterInstantiationArgs =
nullptr)
73 : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
74 NestedPattern(NestedPattern),
75 OuterInstantiationArgs(OuterInstantiationArgs) {
76 if (OuterInstantiationArgs)
77 TypedefNameInstantiator.emplace(
79 *OuterInstantiationArgs);
82 TypeSourceInfo *transform(TypeSourceInfo *TSI) {
return TransformType(TSI); }
86 bool mightReferToOuterTemplateParameters(TypedefNameDecl *
Typedef) {
90 static auto WalkUp = [](DeclContext *DC, DeclContext *TargetDC) {
101 if (WalkUp(
Typedef->getDeclContext(), NestedPattern->getTemplatedDecl()))
103 if (WalkUp(NestedPattern->getTemplatedDecl(),
Typedef->getDeclContext()))
108 QualType RebuildTemplateSpecializationType(
110 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
111 if (!OuterInstantiationArgs ||
112 !isa_and_present<TypeAliasTemplateDecl>(
Template.getAsTemplateDecl()))
117 auto *Pattern = TATD;
118 while (Pattern->getInstantiatedFromMemberTemplate())
119 Pattern = Pattern->getInstantiatedFromMemberTemplate();
120 if (!mightReferToOuterTemplateParameters(Pattern->getTemplatedDecl()))
125 TypedefNameInstantiator->InstantiateTypeAliasTemplateDecl(TATD);
130 MaterializedTypedefs.push_back(NewTATD->getTemplatedDecl());
136 QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
138 TypedefNameDecl *OrigDecl = TL.
getDecl();
139 TypedefNameDecl *
Decl = OrigDecl;
157 if (OuterInstantiationArgs && InDependentContext &&
159 Decl = cast_if_present<TypedefNameDecl>(
160 TypedefNameInstantiator->InstantiateTypedefNameDecl(
164 MaterializedTypedefs.push_back(Decl);
165 }
else if (InDependentContext) {
166 TypeLocBuilder InnerTLB;
167 QualType Transformed =
180 MaterializedTypedefs.push_back(Decl);
185 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
212 auto DeductionGuideName =
222 SemaRef.
Context, DC, LocStart, ES, Name, TInfo->
getType(), TInfo, LocEnd,
224 Guide->setImplicit(IsImplicit);
225 Guide->setParams(Params);
227 for (
auto *Param : Params)
228 Param->setDeclContext(Guide);
229 for (
auto *TD : MaterializedTypedefs)
230 TD->setDeclContext(Guide);
234 if (!TemplateParams) {
240 SemaRef.
Context, DC, Loc, DeductionGuideName, TemplateParams, Guide);
241 GuideTemplate->setImplicit(IsImplicit);
242 Guide->setDescribedFunctionTemplate(GuideTemplate);
248 return GuideTemplate;
255 bool EvaluateConstraint) {
271 NewTTP->setDefaultArgument(SemaRef.
Context, InstantiatedDefaultArg);
277template <
typename NonTypeTemplateOrTemplateTemplateParmDecl>
278NonTypeTemplateOrTemplateTemplateParmDecl *
280 NonTypeTemplateOrTemplateTemplateParmDecl *OldParam,
287 NewParam->setPosition(NewIndex);
288 NewParam->setDepth(NewDepth);
295 unsigned NewIndex,
unsigned NewDepth,
296 bool EvaluateConstraint =
true) {
297 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(
TemplateParam))
298 return transformTemplateTypeParam(
299 SemaRef, DC, TTP, Args, NewDepth, NewIndex,
301 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(
TemplateParam))
302 return transformTemplateParam(SemaRef, DC, TTP, Args, NewIndex, NewDepth);
303 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
TemplateParam))
304 return transformTemplateParam(SemaRef, DC, NTTP, Args, NewIndex, NewDepth);
305 llvm_unreachable(
"Unhandled template parameter types");
310struct ConvertConstructorToDeductionGuideTransform {
311 ConvertConstructorToDeductionGuideTransform(Sema &S,
312 ClassTemplateDecl *Template)
313 : SemaRef(S), Template(Template) {
316 ClassTemplateDecl *Pattern = Template;
318 if (Pattern->isMemberSpecialization())
320 Pattern = Pattern->getInstantiatedFromMemberTemplate();
321 NestedPattern = Pattern;
325 OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
329 ClassTemplateDecl *Template;
330 ClassTemplateDecl *NestedPattern =
nullptr;
332 DeclContext *DC = Template->getDeclContext();
333 CXXRecordDecl *Primary = Template->getTemplatedDecl();
334 DeclarationName DeductionGuideName =
335 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(Template);
337 QualType DeducedType = SemaRef.Context.getCanonicalTagType(Primary);
341 unsigned Depth1IndexAdjustment = Template->getTemplateParameters()->size();
345 MultiLevelTemplateArgumentList OuterInstantiationArgs;
348 NamedDecl *transformConstructor(FunctionTemplateDecl *FTD,
349 CXXConstructorDecl *CD) {
350 SmallVector<TemplateArgument, 16> SubstArgs;
352 LocalInstantiationScope Scope(SemaRef);
361 TemplateParameterList *TemplateParams =
362 SemaRef.GetTemplateParameterList(Template);
363 SmallVector<TemplateArgument, 16> Depth1Args;
367 SmallVector<NamedDecl *, 16> AllParams;
368 AllParams.reserve(TemplateParams->
size() + InnerParams->
size());
369 AllParams.insert(AllParams.begin(), TemplateParams->
begin(),
370 TemplateParams->
end());
371 SubstArgs.reserve(InnerParams->
size());
372 Depth1Args.reserve(InnerParams->
size());
376 for (NamedDecl *Param : *InnerParams) {
377 MultiLevelTemplateArgumentList Args;
378 Args.
setKind(TemplateSubstitutionKind::Rewrite);
388 NamedDecl *NewParam = transformTemplateParameter(
389 SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
390 Depth ? Depth - 1 : 0);
395 Depth1Args.push_back(SemaRef.Context.getInjectedTemplateArg(NewParam));
399 NewParam = transformTemplateParameter(
400 SemaRef, DC, NewParam, OuterInstantiationArgs, Index,
401 Depth - OuterInstantiationArgs.getNumSubstitutedLevels(),
406 "Unexpected template parameter depth");
408 AllParams.push_back(NewParam);
409 SubstArgs.push_back(SemaRef.Context.getInjectedTemplateArg(NewParam));
413 Expr *RequiresClause =
nullptr;
414 if (Expr *InnerRC = InnerParams->getRequiresClause()) {
415 MultiLevelTemplateArgumentList Args;
416 Args.
setKind(TemplateSubstitutionKind::Rewrite);
422 SemaRef.SubstConstraintExprWithoutSatisfaction(InnerRC, Args);
425 RequiresClause = E.
get();
428 TemplateParams = TemplateParameterList::Create(
429 SemaRef.Context, InnerParams->getTemplateLoc(),
430 InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
437 MultiLevelTemplateArgumentList Args;
438 Args.
setKind(TemplateSubstitutionKind::Rewrite);
447 assert(FPTL &&
"no prototype for constructor declaration");
453 SmallVector<ParmVarDecl *, 8> Params;
454 SmallVector<TypedefNameDecl *, 4> MaterializedTypedefs;
455 QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args,
456 MaterializedTypedefs);
464 AssociatedConstraint FunctionTrailingRC;
466 MultiLevelTemplateArgumentList Args;
467 Args.
setKind(TemplateSubstitutionKind::Rewrite);
472 ExprResult E = SemaRef.SubstConstraintExprWithoutSatisfaction(
473 const_cast<Expr *
>(RC.ConstraintExpr), Args);
476 FunctionTrailingRC = AssociatedConstraint(E.
get(), RC.ArgPackSubstIndex);
491 if (!FunctionTrailingRC)
492 FunctionTrailingRC = OuterRC;
494 FunctionTrailingRC = AssociatedConstraint(
497 const_cast<Expr *
>(OuterRC.ConstraintExpr),
504 return buildDeductionGuide(
507 true, MaterializedTypedefs, FunctionTrailingRC);
511 NamedDecl *buildSimpleDeductionGuide(MutableArrayRef<QualType> ParamTypes) {
512 SourceLocation Loc = Template->getLocation();
515 FunctionProtoType::ExtProtoInfo EPI;
517 QualType
Result = SemaRef.BuildFunctionType(DeducedType, ParamTypes, Loc,
518 DeductionGuideName, EPI);
519 TypeSourceInfo *TSI = SemaRef.Context.getTrivialTypeSourceInfo(
Result, Loc);
521 TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
527 FunctionProtoTypeLoc FPTL =
531 SmallVector<ParmVarDecl *, 4> Params;
532 for (
auto T : ParamTypes) {
533 auto *TSI = SemaRef.Context.getTrivialTypeSourceInfo(
T, Loc);
535 TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc,
540 ParmVarDecl *NewParam =
544 FPTL.
setParam(Params.size(), NewParam);
545 Params.push_back(NewParam);
548 return buildDeductionGuide(
549 SemaRef, Template, SemaRef.GetTemplateParameterList(Template),
nullptr,
550 ExplicitSpecifier(), TSI, Loc, Loc, Loc,
true);
554 QualType transformFunctionProtoType(
555 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL,
556 SmallVectorImpl<ParmVarDecl *> &Params,
557 MultiLevelTemplateArgumentList &Args,
558 SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs) {
559 SmallVector<QualType, 4> ParamTypes;
564 ParmVarDecl *NewParam = OldParam;
575 NewParam = transformFunctionTypeParam(
576 NewParam, OuterInstantiationArgs, MaterializedTypedefs,
585 transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs,
589 ParamTypes.push_back(NewParam->
getType());
590 Params.push_back(NewParam);
602 QualType ReturnType = DeducedType;
603 auto TTL = TLB.
push<TagTypeLoc>(ReturnType);
604 TTL.setElaboratedKeywordLoc(SourceLocation());
605 TTL.setQualifierLoc(NestedNameSpecifierLoc());
606 TTL.setNameLoc(Primary->getLocation());
610 FunctionProtoType::ExtProtoInfo EPI;
614 QualType
Result = SemaRef.BuildFunctionType(
615 ReturnType, ParamTypes, TL.
getBeginLoc(), DeductionGuideName, EPI);
619 FunctionProtoTypeLoc NewTL = TLB.
push<FunctionProtoTypeLoc>(
Result);
625 for (
unsigned I = 0, E = NewTL.
getNumParams(); I != E; ++I)
631 ParmVarDecl *transformFunctionTypeParam(
632 ParmVarDecl *OldParam, MultiLevelTemplateArgumentList &Args,
633 llvm::SmallVectorImpl<TypedefNameDecl *> &MaterializedTypedefs,
634 bool TransformingOuterPatterns) {
636 TypeSourceInfo *NewDI;
639 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, 0u);
641 SemaRef.SubstType(PackTL.getPatternLoc(), Args,
646 SemaRef.CheckPackExpansion(NewDI, PackTL.getEllipsisLoc(),
647 PackTL.getTypePtr()->getNumExpansions());
649 NewDI = SemaRef.SubstType(OldDI, Args, OldParam->
getLocation(),
658 NewDI = ExtractTypeForDeductionGuide(
659 SemaRef, MaterializedTypedefs, NestedPattern,
660 TransformingOuterPatterns ? &Args :
nullptr)
669 QualType ParamTy = NewDI->
getType();
670 NewDefArg =
new (SemaRef.Context)
678 auto NewType = NewDI->
getType();
680 NewType = SemaRef.Context.getDecayedType(NewType);
688 SemaRef.CurrentInstantiationScope->InstantiatedLocal(OldParam, NewParam);
699 llvm::SmallBitVector ReferencedTemplateParams(TemplateParamsList->
size());
701 DeducedArgs, TemplateParamsList->
getDepth(), ReferencedTemplateParams);
703 auto MarkDefaultArgs = [&](
auto *Param) {
704 if (!Param->hasDefaultArgument())
707 Param->getDefaultArgument().getArgument(),
708 TemplateParamsList->
getDepth(), ReferencedTemplateParams);
711 for (
unsigned Index = 0; Index < TemplateParamsList->
size(); ++Index) {
712 if (!ReferencedTemplateParams[Index])
714 auto *Param = TemplateParamsList->
getParam(Index);
715 if (
auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Param))
716 MarkDefaultArgs(TTPD);
717 else if (
auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(Param))
718 MarkDefaultArgs(NTTPD);
724 for (
unsigned Index = 0; Index < TemplateParamsList->
size(); ++Index) {
725 if (ReferencedTemplateParams[Index])
726 Results.push_back(Index);
736 "name must be a deduction guide name");
737 auto Existing = DC->
lookup(Name);
738 for (
auto *D : Existing)
746llvm::DenseSet<const NamedDecl *> getSourceDeductionGuides(
DeclarationName Name,
750 "name must be a deduction guide name");
751 llvm::DenseSet<const NamedDecl *> Result;
752 for (
auto *D : DC->
lookup(Name)) {
753 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
756 if (
const auto *GD = dyn_cast<CXXDeductionGuideDecl>(D)) {
757 assert(GD->getSourceDeductionGuide() &&
758 "deduction guide for alias template must have a source deduction "
760 Result.insert(GD->getSourceDeductionGuide());
778 unsigned FirstUndeducedParamIdx,
Expr *IsDeducible) {
803 unsigned AdjustDepth = 0;
804 if (
auto *PrimaryTemplate =
806 AdjustDepth = PrimaryTemplate->getTemplateDepth();
818 NamedDecl *NewParam = transformTemplateParameter(
820 AdjustedAliasTemplateArgs.size(),
824 Context.getInjectedTemplateArg(NewParam);
825 AdjustedAliasTemplateArgs.push_back(NewTemplateArgument);
836 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
837 const auto &D = DeduceResults[Index];
845 transformTemplateParameter(SemaRef, F->
getDeclContext(), TP, Args,
846 FirstUndeducedParamIdx,
848 FirstUndeducedParamIdx += 1;
849 assert(TemplateArgsForBuildingRC[Index].isNull());
850 TemplateArgsForBuildingRC[Index] =
851 Context.getInjectedTemplateArg(NewParam);
858 assert(TemplateArgsForBuildingRC[Index].isNull() &&
859 "InstantiatedArgs must be null before setting");
860 TemplateArgsForBuildingRC[Index] = Output.
getArgument();
900 clang::Decl::ClassTemplateSpecialization) {
907 for (
auto It : OuterLevelArgs)
917 BinaryOperatorKind::BO_LAnd, E.
get(), IsDeducible);
918 if (Conjunction.isInvalid())
926Expr *buildIsDeducibleConstraint(
Sema &SemaRef,
932 if (
auto *PrimaryTemplate =
934 PrimaryTemplate && TemplateParams.size() > 0) {
938 unsigned AdjustDepth = PrimaryTemplate->getTemplateDepth();
940 for (
auto *TP : TemplateParams) {
946 NamedDecl *NewParam = transformTemplateParameter(
948 TransformedTemplateArgs.size(),
952 Context.getInjectedTemplateArg(NewParam);
953 TransformedTemplateArgs.push_back(NewTemplateArgument);
961 Context.DeclarationNames.getCXXDeductionGuideName(
AliasTemplate));
965 Context.getTrivialTypeSourceInfo(
966 Context.getDeducedTemplateSpecializationType(
972 Context.getTrivialTypeSourceInfo(
977 Context, Context.getLogicalOperationType(),
AliasTemplate->getLocation(),
978 TypeTrait::BTT_IsDeducible, IsDeducibleTypeTraitArgs,
982std::pair<TemplateDecl *, llvm::ArrayRef<TemplateArgument>>
984 auto RhsType =
AliasTemplate->getTemplatedDecl()->getUnderlyingType();
987 if (
const auto *TST = RhsType->getAs<TemplateSpecializationType>()) {
991 Template = TST->getTemplateName().getAsTemplateDecl();
992 AliasRhsTemplateArgs =
993 TST->getAsNonAliasTemplateSpecializationType()->template_arguments();
994 }
else if (
const auto *RT = RhsType->getAs<RecordType>()) {
998 if (
const auto *CTSD =
999 dyn_cast<ClassTemplateSpecializationDecl>(RT->getOriginalDecl())) {
1000 Template = CTSD->getSpecializedTemplate();
1001 AliasRhsTemplateArgs = CTSD->getTemplateArgs().asArray();
1004 return {
Template, AliasRhsTemplateArgs};
1023BuildDeductionGuideForTypeAlias(
Sema &SemaRef,
1030 if (BuildingDeductionGuides.isInvalid())
1033 auto &Context = SemaRef.
Context;
1034 auto [
Template, AliasRhsTemplateArgs] =
1057 const TemplateSpecializationType *FReturnType =
1058 RType->
getAs<TemplateSpecializationType>();
1059 if (
const auto *ICNT = RType->getAsCanonical<InjectedClassNameType>())
1062 ICNT->getOriginalDecl()->getCanonicalTemplateSpecializationType(
1064 assert(FReturnType &&
"expected to see a return type");
1097 AliasRhsTemplateArgs, TDeduceInfo, DeduceResults,
1104 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
1105 const auto &D = DeduceResults[Index];
1106 if (!IsNonDeducedArgument(D))
1107 DeducedArgs.push_back(D);
1109 NonDeducedTemplateParamsInFIndex.push_back(Index);
1111 auto DeducedAliasTemplateParams =
1112 TemplateParamsReferencedInTemplateArgumentList(
1113 SemaRef,
AliasTemplate->getTemplateParameters(), DeducedArgs);
1135 for (
unsigned AliasTemplateParamIdx : DeducedAliasTemplateParams) {
1137 AliasTemplate->getTemplateParameters()->getParam(AliasTemplateParamIdx);
1143 NamedDecl *NewParam = transformTemplateParameter(
1146 FPrimeTemplateParams.push_back(NewParam);
1149 Context.getInjectedTemplateArg(NewParam);
1150 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
1152 unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
1172 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
1173 const auto &D = DeduceResults[Index];
1174 if (IsNonDeducedArgument(D)) {
1182 assert(TemplateArgsForBuildingFPrime[Index].isNull() &&
1183 "InstantiatedArgs must be null before setting");
1184 TemplateArgsForBuildingFPrime[Index] = Output.
getArgument();
1191 for (
unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
1198 NamedDecl *NewParam = transformTemplateParameter(
1199 SemaRef, F->
getDeclContext(), TP, Args, FPrimeTemplateParams.size(),
1201 FPrimeTemplateParams.push_back(NewParam);
1203 assert(TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull() &&
1204 "The argument must be null before setting");
1205 TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
1206 Context.getInjectedTemplateArg(NewParam);
1209 auto *TemplateArgListForBuildingFPrime =
1213 F, TemplateArgListForBuildingFPrime,
AliasTemplate->getLocation(),
1217 Expr *IsDeducible = buildIsDeducibleConstraint(
1218 SemaRef,
AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
1219 Expr *RequiresClause =
1220 buildAssociatedConstraints(SemaRef, F,
AliasTemplate, DeduceResults,
1221 FirstUndeducedParamIdx, IsDeducible);
1224 Context,
AliasTemplate->getTemplateParameters()->getTemplateLoc(),
1226 FPrimeTemplateParams,
1231 GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(),
1236 DGuide->setDeductionCandidateKind(GG->getDeductionCandidateKind());
1237 DGuide->setSourceDeductionGuide(
1239 DGuide->setSourceDeductionGuideKind(
1246void DeclareImplicitDeductionGuidesForTypeAlias(
1250 auto &Context = SemaRef.
Context;
1251 auto [
Template, AliasRhsTemplateArgs] =
1255 auto SourceDeductionGuides = getSourceDeductionGuides(
1256 Context.DeclarationNames.getCXXDeductionGuideName(
AliasTemplate),
1260 Context.DeclarationNames.getCXXDeductionGuideName(
Template), Loc);
1263 Guides.suppressDiagnostics();
1265 for (
auto *G : Guides) {
1266 if (
auto *DG = dyn_cast<CXXDeductionGuideDecl>(G)) {
1267 if (SourceDeductionGuides.contains(DG))
1276 for (
unsigned I = 0, N = DG->getNumParams(); I != N; ++I) {
1277 const auto *P = DG->getParamDecl(I);
1280 SemaRef.
Context, G->getDeclContext(),
1281 DG->getParamDecl(I)->getBeginLoc(), P->getLocation(),
nullptr,
1291 Transformed->setSourceDeductionGuide(DG);
1292 Transformed->setSourceDeductionGuideKind(
1303 BinaryOperatorKind::BO_LAnd,
const_cast<Expr *
>(RC.ConstraintExpr),
1304 const_cast<Expr *
>(Constraint.ConstraintExpr));
1305 if (!Conjunction.isInvalid()) {
1306 Constraint.ConstraintExpr = Conjunction.getAs<
Expr>();
1307 Constraint.ArgPackSubstIndex = RC.ArgPackSubstIndex;
1310 Transformed->setTrailingRequiresClause(Constraint);
1323 BuildDeductionGuideForTypeAlias(SemaRef,
AliasTemplate, F, Loc);
1338 ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
1343 NewParamTypes.push_back(
Type);
1347 RHSTemplate, NewParamTypes, Loc);
1348 if (!RHSDeductionGuide)
1354 return BuildDeductionGuideForTypeAlias(SemaRef,
AliasTemplate,
1355 RHSDeductionGuide, Loc);
1363 llvm::FoldingSetNodeID ID;
1365 for (
auto &
T : ParamTypes)
1366 T.getCanonicalType().Profile(ID);
1367 unsigned Hash = ID.ComputeHash();
1376 if (
auto *FTD = DeclareAggregateDeductionGuideForTypeAlias(
1388 DefRecord->getDescribedClassTemplate())
1396 ConvertConstructorToDeductionGuideTransform Transform(
1409 if (BuildingDeductionGuides.isInvalid())
1413 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
1417 Transform.buildSimpleDeductionGuide(ParamTypes));
1428 DeclareImplicitDeductionGuidesForTypeAlias(*
this,
AliasTemplate, Loc);
1434 DefRecord->getDescribedClassTemplate())
1442 ConvertConstructorToDeductionGuideTransform Transform(
1447 if (hasDeclaredDeductionGuides(Transform.DeductionGuideName, DC))
1458 if (BuildingDeductionGuides.isInvalid())
1466 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
1469 bool AddedAny =
false;
1471 D = D->getUnderlyingDecl();
1472 if (D->isInvalidDecl() || D->isImplicit())
1480 if (ProcessedCtors.count(D))
1483 auto *FTD = dyn_cast<FunctionTemplateDecl>(D);
1493 return !P || P->hasUnparsedDefaultArg();
1497 ProcessedCtors.insert(D);
1498 Transform.transformConstructor(FTD, CD);
1507 Transform.buildSimpleDeductionGuide({});
1513 Transform.buildSimpleDeductionGuide(Transform.DeducedType))
1514 ->getTemplatedDecl())
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
Defines enumerations for the type traits support.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
DeclarationNameTable DeclarationNames
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a C++ constructor within a class.
ExplicitSpecifier getExplicitSpecifier()
Represents a C++ deduction guide declaration.
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor=nullptr, DeductionCandidate Kind=DeductionCandidate::Normal, const AssociatedConstraint &TrailingRequiresClause={}, const CXXDeductionGuideDecl *SourceDG=nullptr, SourceDeductionGuideKind SK=SourceDeductionGuideKind::None)
Represents a C++ struct/union/class.
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
const TypeClass * getTypePtr() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
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.
void addDecl(Decl *D)
Add the declaration D into this context.
Decl::Kind getDeclKind() const
SourceLocation getEndLoc() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getLocation() const
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).
The name of a declaration.
NameKind getNameKind() const
Determine what kind of name this is.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getBeginLoc() const LLVM_READONLY
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
TypeSourceInfo * getTypeSourceInfo() const
SourceLocation getElaboratedKeywordLoc() const
SourceLocation getNameLoc() const
NestedNameSpecifierLoc getQualifierLoc() const
Store information needed for an explicit specifier.
This represents one expression.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isVariadic() const
Whether this function prototype is variadic.
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
unsigned getNumParams() const
SourceLocation getLocalRangeEnd() const
void setLocalRangeBegin(SourceLocation L)
void setLParenLoc(SourceLocation Loc)
void setParam(unsigned i, ParmVarDecl *VD)
ArrayRef< ParmVarDecl * > getParams() const
void setRParenLoc(SourceLocation Loc)
void setLocalRangeEnd(SourceLocation L)
void setExceptionSpecRange(SourceRange R)
SourceLocation getLocalRangeBegin() const
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
FunctionType - C99 6.7.5.3 - Function Declarators.
const TypeClass * getTypePtr() const
A stack-allocated class that identifies which local variable declaration instantiations are present i...
void InstantiatedLocal(const Decl *D, Decl *Inst)
Represents the results of name lookup.
Data structure that captures multiple levels of template argument lists for use in template instantia...
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args, bool Final)
Add a new outmost level to the multi-level template argument list.
void setKind(TemplateSubstitutionKind K)
void addOuterRetainedLevels(unsigned Num)
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
unsigned getFunctionScopeDepth() const
A (possibly-)qualified type.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Scope - A scope is a transient data structure that is used while parsing the program.
RAII object used to change the argument pack substitution index within a Sema object.
Sema - This implements semantic analysis and AST building for C.
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, const MultiLevelTemplateArgumentList &TemplateArgs, bool EvaluateConstraint)
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc, NamedDecl *TemplateParam=nullptr)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
Scope * getCurScope() const
Retrieve the parser's current scope.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
FunctionTemplateDecl * DeclareAggregateDeductionGuideFromInitList(TemplateDecl *Template, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc)
FunctionDecl * InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, const TemplateArgumentList *Args, SourceLocation Loc, CodeSynthesisContext::SynthesisKind CSC=CodeSynthesisContext::ExplicitTemplateArgumentSubstitution)
Instantiate (or find existing instantiation of) a function template with a given set of template argu...
ExprResult SubstExpr(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.
llvm::DenseMap< unsigned, CXXDeductionGuideDecl * > AggregateDeductionCandidates
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const DeclContext *DC=nullptr, bool Final=false, std::optional< ArrayRef< TemplateArgument > > Innermost=std::nullopt, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false, bool ForDefaultArgumentSubstitution=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
void DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc)
Declare implicit deduction guides for a class template if we've not already done so.
Decl * SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
bool isCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind=CompleteTypeKind::Default)
bool SubstTemplateArgument(const TemplateArgumentLoc &Input, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentLoc &Output, SourceLocation Loc={}, const DeclarationName &Entity={})
void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark which template parameters are used in a given expression.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
Encodes a location in the source.
SourceLocation getBegin() const
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
Represents a template argument.
bool isNull() const
Determine whether this template argument has no value.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Pack
The template argument is actually a parameter pack.
ArgKind getKind() const
Return the kind of stored template argument.
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.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getTemplateLoc() const
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
UnsignedOrNone getNumExpansionParameters() const
Whether this parameter is a template type parameter pack that has a known list of different type-cons...
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isParameterPack() const
Returns whether this is a parameter pack.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Declaration of an alias template.
SourceLocation getBeginLoc() const LLVM_READONLY
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
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.
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
The base class of the type hierarchy.
bool isRValueReferenceType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isLValueReferenceType() const
bool isFunctionType() const
const T * getAs() const
Member-template getAs<specific type>'.
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Base class for declarations which introduce a typedef-name.
TypeSourceInfo * getTypeSourceInfo() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Provides information about an attempted template argument deduction, whose success or failure was des...
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
@ OK_Ordinary
An ordinary object is located at an address in memory.
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ Keyword
The name has been typo-corrected to a keyword.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
U cast(CodeGen::Address addr)
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
@ None
No keyword precedes the qualified type name.
ActionResult< Expr * > ExprResult
const Expr * ConstraintExpr
UnsignedOrNone ArgPackSubstIndex
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
unsigned HasTrailingReturn
@ BuildingDeductionGuides
We are building deduction guides for a class.
A stack object to be created when performing template instantiation.