45#include "llvm/ADT/ArrayRef.h"
46#include "llvm/ADT/STLExtras.h"
47#include "llvm/ADT/SmallVector.h"
48#include "llvm/Support/Casting.h"
49#include "llvm/Support/ErrorHandling.h"
60class ExtractTypeForDeductionGuide
65 std::optional<TemplateDeclInstantiator> TypedefNameInstantiator;
69 ExtractTypeForDeductionGuide(
74 :
Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
75 NestedPattern(NestedPattern),
76 OuterInstantiationArgs(OuterInstantiationArgs) {
77 if (OuterInstantiationArgs)
78 TypedefNameInstantiator.emplace(
80 *OuterInstantiationArgs);
113 if (!OuterInstantiationArgs ||
119 auto *Pattern = TATD;
120 while (Pattern->getInstantiatedFromMemberTemplate())
121 Pattern = Pattern->getInstantiatedFromMemberTemplate();
122 if (!mightReferToOuterTemplateParameters(Pattern->getTemplatedDecl()))
127 TypedefNameInstantiator->InstantiateTypeAliasTemplateDecl(TATD);
131 auto *NewTATD = cast<TypeAliasTemplateDecl>(NewD);
132 MaterializedTypedefs.push_back(NewTATD->getTemplatedDecl());
158 if (OuterInstantiationArgs && InDependentContext &&
160 Decl = cast_if_present<TypedefNameDecl>(
161 TypedefNameInstantiator->InstantiateTypedefNameDecl(
162 OrigDecl, isa<TypeAliasDecl>(OrigDecl)));
165 MaterializedTypedefs.push_back(
Decl);
166 }
else if (InDependentContext) {
171 if (isa<TypeAliasDecl>(OrigDecl))
176 assert(isa<TypedefDecl>(OrigDecl) &&
"Not a Type alias or typedef");
181 MaterializedTypedefs.push_back(
Decl);
204 auto DeductionGuideName =
215 TInfo->
getType(), TInfo, LocEnd, Ctor);
216 Guide->setImplicit(IsImplicit);
217 Guide->setParams(Params);
219 for (
auto *Param : Params)
220 Param->setDeclContext(Guide);
221 for (
auto *TD : MaterializedTypedefs)
222 TD->setDeclContext(Guide);
223 if (isa<CXXRecordDecl>(DC))
226 if (!TemplateParams) {
232 SemaRef.
Context, DC,
Loc, DeductionGuideName, TemplateParams, Guide);
233 GuideTemplate->setImplicit(IsImplicit);
234 Guide->setDescribedFunctionTemplate(GuideTemplate);
236 if (isa<CXXRecordDecl>(DC))
240 return GuideTemplate;
247 bool EvaluateConstraint) {
265 NewTTP->setDefaultArgument(SemaRef.
Context, InstantiatedDefaultArg);
271template <
typename NonTypeTemplateOrTemplateTemplateParmDecl>
272NonTypeTemplateOrTemplateTemplateParmDecl *
274 NonTypeTemplateOrTemplateTemplateParmDecl *OldParam,
279 auto *NewParam = cast<NonTypeTemplateOrTemplateTemplateParmDecl>(
281 NewParam->setPosition(NewIndex);
282 NewParam->setDepth(NewDepth);
289 unsigned NewIndex,
unsigned NewDepth,
290 bool EvaluateConstraint =
true) {
291 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(
TemplateParam))
292 return transformTemplateTypeParam(
293 SemaRef, DC, TTP, Args, NewDepth, NewIndex,
295 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(
TemplateParam))
296 return transformTemplateParam(SemaRef, DC, TTP, Args, NewIndex, NewDepth);
297 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
TemplateParam))
298 return transformTemplateParam(SemaRef, DC, NTTP, Args, NewIndex, NewDepth);
299 llvm_unreachable(
"Unhandled template parameter types");
304struct ConvertConstructorToDeductionGuideTransform {
305 ConvertConstructorToDeductionGuideTransform(
Sema &S,
307 : SemaRef(S), Template(Template) {
315 NestedPattern = Pattern;
361 AllParams.reserve(TemplateParams->
size() + InnerParams->
size());
362 AllParams.insert(AllParams.begin(), TemplateParams->
begin(),
363 TemplateParams->
end());
364 SubstArgs.reserve(InnerParams->
size());
365 Depth1Args.reserve(InnerParams->
size());
371 Args.
setKind(TemplateSubstitutionKind::Rewrite);
377 NamedDecl *NewParam = transformTemplateParameter(
378 SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment, Depth - 1);
387 NewParam = transformTemplateParameter(
388 SemaRef, DC, NewParam, OuterInstantiationArgs, Index,
394 "Unexpected template parameter depth");
396 AllParams.push_back(NewParam);
401 Expr *RequiresClause =
nullptr;
402 if (
Expr *InnerRC = InnerParams->getRequiresClause()) {
404 Args.
setKind(TemplateSubstitutionKind::Rewrite);
412 RequiresClause =
E.getAs<
Expr>();
415 TemplateParams = TemplateParameterList::Create(
416 SemaRef.
Context, InnerParams->getTemplateLoc(),
417 InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
425 Args.
setKind(TemplateSubstitutionKind::Rewrite);
434 assert(FPTL &&
"no prototype for constructor declaration");
442 QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args,
443 MaterializedTypedefs);
448 return buildDeductionGuide(
451 true, MaterializedTypedefs);
462 DeductionGuideName, EPI);
465 TSI = SemaRef.
SubstType(TSI, OuterInstantiationArgs,
Loc,
476 for (
auto T : ParamTypes) {
479 TSI = SemaRef.
SubstType(TSI, OuterInstantiationArgs,
Loc,
488 FPTL.
setParam(Params.size(), NewParam);
489 Params.push_back(NewParam);
492 return buildDeductionGuide(
498 QualType transformFunctionProtoType(
519 NewParam = transformFunctionTypeParam(
520 NewParam, OuterInstantiationArgs, MaterializedTypedefs,
529 transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs,
533 ParamTypes.push_back(NewParam->
getType());
534 Params.push_back(NewParam);
556 ReturnType, ParamTypes, TL.
getBeginLoc(), DeductionGuideName, EPI);
575 bool TransformingOuterPatterns) {
582 SemaRef.
SubstType(PackTL.getPatternLoc(), Args,
588 PackTL.getTypePtr()->getNumExpansions());
599 NewDI = ExtractTypeForDeductionGuide(
600 SemaRef, MaterializedTypedefs, NestedPattern,
601 TransformingOuterPatterns ? &Args :
nullptr)
611 NewDefArg =
new (SemaRef.
Context)
619 auto NewType = NewDI->
getType();
641 llvm::BitVector ReferencedTemplateParams;
643 TemplateParamsReferencedFinder(
645 : TemplateParamList(TemplateParamList),
646 ReferencedTemplateParams(TemplateParamList->size()) {}
673 void Mark(
unsigned Depth,
unsigned Index) {
674 if (Index < TemplateParamList->size() &&
676 ReferencedTemplateParams.set(Index);
679 TemplateParamsReferencedFinder Finder(TemplateParamsList);
680 Finder.TraverseTemplateArguments(DeducedArgs);
683 for (
unsigned Index = 0; Index < TemplateParamsList->
size(); ++Index) {
684 if (Finder.ReferencedTemplateParams[Index])
685 Results.push_back(Index);
693 assert(Name.getNameKind() ==
694 DeclarationName::NameKind::CXXDeductionGuideName &&
695 "name must be a deduction guide name");
696 auto Existing = DC->
lookup(Name);
697 for (
auto *
D : Existing)
715 unsigned FirstUndeducedParamIdx,
Expr *IsDeducible) {
740 unsigned AdjustDepth = 0;
741 if (
auto *PrimaryTemplate =
743 AdjustDepth = PrimaryTemplate->getTemplateDepth();
753 Args.
setKind(TemplateSubstitutionKind::Rewrite);
755 NamedDecl *NewParam = transformTemplateParameter(
757 AdjustedAliasTemplateArgs.size(),
762 AdjustedAliasTemplateArgs.push_back(NewTemplateArgument);
770 Args.
setKind(TemplateSubstitutionKind::Rewrite);
773 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
774 const auto &
D = DeduceResults[Index];
778 Args.
setKind(TemplateSubstitutionKind::Rewrite);
782 transformTemplateParameter(SemaRef, F->
getDeclContext(), TP, Args,
783 FirstUndeducedParamIdx,
785 FirstUndeducedParamIdx += 1;
786 assert(TemplateArgsForBuildingRC[Index].isNull());
787 TemplateArgsForBuildingRC[Index] =
795 assert(TemplateArgsForBuildingRC[Index].isNull() &&
796 "InstantiatedArgs must be null before setting");
797 TemplateArgsForBuildingRC[Index] = Output.
getArgument();
837 clang::Decl::ClassTemplateSpecialization) {
844 for (
auto It : OuterLevelArgs)
854 BinaryOperatorKind::BO_LAnd,
E.get(), IsDeducible);
855 if (Conjunction.isInvalid())
863Expr *buildIsDeducibleConstraint(
Sema &SemaRef,
869 if (
auto *PrimaryTemplate =
871 PrimaryTemplate && TemplateParams.size() > 0) {
875 unsigned AdjustDepth = PrimaryTemplate->getTemplateDepth();
877 for (
auto *TP : TemplateParams) {
881 Args.
setKind(TemplateSubstitutionKind::Rewrite);
883 NamedDecl *NewParam = transformTemplateParameter(
885 TransformedTemplateArgs.size(),
890 TransformedTemplateArgs.push_back(NewTemplateArgument);
894 Args.
setKind(TemplateSubstitutionKind::Rewrite);
912 TypeTrait::BTT_IsDeducible, IsDeducibleTypeTraitArgs,
916std::pair<TemplateDecl *, llvm::ArrayRef<TemplateArgument>>
920 ->getUnderlyingType()
921 .getSingleStepDesugaredType(SemaRef.
Context);
928 Template = TST->getTemplateName().getAsTemplateDecl();
929 AliasRhsTemplateArgs = TST->template_arguments();
930 }
else if (
const auto *RT = RhsType->getAs<
RecordType>()) {
934 if (
const auto *CTSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(
935 RT->getAsCXXRecordDecl())) {
936 Template = CTSD->getSpecializedTemplate();
937 AliasRhsTemplateArgs = CTSD->getTemplateArgs().asArray();
940 assert(
false &&
"unhandled RHS type of the alias");
942 return {Template, AliasRhsTemplateArgs};
948BuildDeductionGuideForTypeAlias(
Sema &SemaRef,
955 if (BuildingDeductionGuides.isInvalid())
958 auto &Context = SemaRef.
Context;
959 auto [Template, AliasRhsTemplateArgs] =
968 FReturnType = InjectedCNT->getInjectedTST();
972 assert(FReturnType &&
"expected to see a return type");
1005 AliasRhsTemplateArgs, TDeduceInfo, DeduceResults,
1012 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
1013 if (
const auto &
D = DeduceResults[Index]; !
D.isNull())
1014 DeducedArgs.push_back(
D);
1016 NonDeducedTemplateParamsInFIndex.push_back(Index);
1018 auto DeducedAliasTemplateParams =
1019 TemplateParamsReferencedInTemplateArgumentList(
1038 for (
unsigned AliasTemplateParamIdx : DeducedAliasTemplateParams) {
1040 AliasTemplate->getTemplateParameters()->getParam(AliasTemplateParamIdx);
1044 Args.
setKind(TemplateSubstitutionKind::Rewrite);
1046 NamedDecl *NewParam = transformTemplateParameter(
1049 FPrimeTemplateParams.push_back(NewParam);
1053 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
1055 unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
1058 for (
unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
1061 Args.
setKind(TemplateSubstitutionKind::Rewrite);
1065 NamedDecl *NewParam = transformTemplateParameter(
1066 SemaRef, F->
getDeclContext(), TP, Args, FPrimeTemplateParams.size(),
1068 FPrimeTemplateParams.push_back(NewParam);
1070 assert(TemplateArgsForBuildingFPrime[FTemplateParamIdx].isNull() &&
1071 "The argument must be null before setting");
1072 TemplateArgsForBuildingFPrime[FTemplateParamIdx] =
1092 Args.
setKind(TemplateSubstitutionKind::Rewrite);
1094 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
1095 const auto &
D = DeduceResults[Index];
1098 assert(!TemplateArgsForBuildingFPrime[Index].isNull() &&
1099 "template arguments for non-deduced template parameters should "
1107 assert(TemplateArgsForBuildingFPrime[Index].isNull() &&
1108 "InstantiatedArgs must be null before setting");
1109 TemplateArgsForBuildingFPrime[Index] = Output.
getArgument();
1113 auto *TemplateArgListForBuildingFPrime =
1117 F, TemplateArgListForBuildingFPrime,
AliasTemplate->getLocation(),
1119 auto *GG = cast<CXXDeductionGuideDecl>(FPrime);
1121 Expr *IsDeducible = buildIsDeducibleConstraint(
1122 SemaRef,
AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
1123 Expr *RequiresClause =
1124 buildAssociatedConstraints(SemaRef, F,
AliasTemplate, DeduceResults,
1125 FirstUndeducedParamIdx, IsDeducible);
1127 auto *FPrimeTemplateParamList = TemplateParameterList::Create(
1128 Context,
AliasTemplate->getTemplateParameters()->getTemplateLoc(),
1130 FPrimeTemplateParams,
1133 auto *Result = cast<FunctionTemplateDecl>(buildDeductionGuide(
1135 GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(),
1139 cast<CXXDeductionGuideDecl>(Result->getTemplatedDecl())
1140 ->setDeductionCandidateKind(GG->getDeductionCandidateKind());
1146void DeclareImplicitDeductionGuidesForTypeAlias(
1150 auto &Context = SemaRef.
Context;
1154 if (hasDeclaredDeductionGuides(
1158 auto [Template, AliasRhsTemplateArgs] =
1166 Guides.suppressDiagnostics();
1168 for (
auto *G : Guides) {
1169 if (
auto *DG = dyn_cast<CXXDeductionGuideDecl>(G)) {
1177 for (
unsigned I = 0, N = DG->getNumParams(); I != N; ++I) {
1178 const auto *
P = DG->getParamDecl(I);
1181 SemaRef.
Context, G->getDeclContext(),
1182 DG->getParamDecl(I)->getBeginLoc(),
P->getLocation(),
nullptr,
1187 auto *Transformed = cast<FunctionDecl>(buildDeductionGuide(
1196 auto *Constraint = buildIsDeducibleConstraint(
1198 if (
auto *RC = DG->getTrailingRequiresClause()) {
1201 BinaryOperatorKind::BO_LAnd, RC, Constraint);
1202 if (!Conjunction.isInvalid())
1205 Transformed->setTrailingRequiresClause(Constraint);
1214 ->getDeductionCandidateKind() == DeductionCandidate::Aggregate)
1232 ExtractTypeForDeductionGuide TypeAliasTransformer(SemaRef, TypedefDecls);
1237 NewParamTypes.push_back(
Type);
1241 RHSTemplate, NewParamTypes,
Loc);
1242 if (!RHSDeductionGuide)
1248 return BuildDeductionGuideForTypeAlias(SemaRef,
AliasTemplate,
1249 RHSDeductionGuide,
Loc);
1257 llvm::FoldingSetNodeID ID;
1258 ID.AddPointer(Template);
1259 for (
auto &
T : ParamTypes)
1261 unsigned Hash = ID.ComputeHash();
1269 if (
auto *
AliasTemplate = llvm::dyn_cast<TypeAliasTemplateDecl>(Template)) {
1270 if (
auto *FTD = DeclareAggregateDeductionGuideForTypeAlias(
1282 DefRecord->getDescribedClassTemplate())
1283 Template = DescribedTemplate;
1290 ConvertConstructorToDeductionGuideTransform Transform(
1291 *
this, cast<ClassTemplateDecl>(Template));
1302 *
this,
Loc, Template,
1304 if (BuildingDeductionGuides.isInvalid())
1308 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
1311 auto *FTD = cast<FunctionTemplateDecl>(
1312 Transform.buildSimpleDeductionGuide(ParamTypes));
1322 if (
auto *
AliasTemplate = llvm::dyn_cast<TypeAliasTemplateDecl>(Template)) {
1329 DefRecord->getDescribedClassTemplate())
1330 Template = DescribedTemplate;
1337 ConvertConstructorToDeductionGuideTransform Transform(
1338 *
this, cast<ClassTemplateDecl>(Template));
1342 if (hasDeclaredDeductionGuides(Transform.DeductionGuideName, DC))
1351 *
this,
Loc, Template,
1353 if (BuildingDeductionGuides.isInvalid())
1361 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
1364 bool AddedAny =
false;
1366 D =
D->getUnderlyingDecl();
1375 if (ProcessedCtors.count(
D))
1378 auto *FTD = dyn_cast<FunctionTemplateDecl>(
D);
1388 return !P || P->hasUnparsedDefaultArg();
1392 ProcessedCtors.insert(
D);
1393 Transform.transformConstructor(FTD, CD);
1402 Transform.buildSimpleDeductionGuide({});
1406 cast<CXXDeductionGuideDecl>(
1407 cast<FunctionTemplateDecl>(
1408 Transform.buildSimpleDeductionGuide(Transform.DeducedType))
1409 ->getTemplatedDecl())
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
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
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl) const
QualType getLogicalOperationType() const
The result type of logical operations, '<', '>', '!=', etc.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
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, Expr *TrailingRequiresClause=nullptr)
Represents a C++ struct/union/class.
CXXRecordDecl * getDefinition() const
Declaration of a class template.
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplateDecl * getInstantiatedFromMemberTemplate() 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
A reference to a declared variable, function, enum, etc.
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndLoc() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
bool isInvalidDecl() const
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).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool TraverseTemplateName(TemplateName Template)
Recursively visit a template name and dispatch to the appropriate method.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
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
Represents a prototype with parameter type info, e.g.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
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
The injected class name of a C++ class template or class template partial specialization.
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)
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
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.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
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.
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.
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...
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
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.
TemplateParameterList * GetTemplateParameterList(TemplateDecl *TD)
Returns the template parameter list with all default template argument information.
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={})
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
A convenient class for passing around template argument information.
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.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Represents a type template specialization; the template must be a class template, a type alias templa...
ArrayRef< TemplateArgument > template_arguments() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
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).
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, std::optional< unsigned > NumExpanded=std::nullopt)
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isExpandedParameterPack() const
Whether this parameter is a template type parameter pack that has a known list of different type-cons...
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getNumExpansionParameters() const
Retrieves the number of parameters in an expanded parameter pack.
unsigned getIndex() const
unsigned getDepth() const
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.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Pushes space for a typespec TypeLoc.
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.
SourceLocation getNameLoc() const
void setNameLoc(SourceLocation Loc)
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
Wrapper for source info for typedefs.
TypedefNameDecl * getTypedefNameDecl() 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...
The JSON file list parser is used to communicate input to InstallAPI.
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
std::pair< unsigned, unsigned > getDepthAndIndex(const 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_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.
const FunctionProtoType * T
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Extra information about a function prototype.
unsigned HasTrailingReturn
@ BuildingDeductionGuides
We are building deduction guides for a class.
A stack object to be created when performing template instantiation.