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
64 std::optional<TemplateDeclInstantiator> TypedefNameInstantiator;
68 ExtractTypeForDeductionGuide(
73 :
Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs),
74 NestedPattern(NestedPattern),
75 OuterInstantiationArgs(OuterInstantiationArgs) {
76 if (OuterInstantiationArgs)
77 TypedefNameInstantiator.emplace(
79 *OuterInstantiationArgs);
111 if (!OuterInstantiationArgs ||
112 !isa_and_present<TypeAliasTemplateDecl>(
Template.getAsTemplateDecl()))
116 auto *TATD = cast<TypeAliasTemplateDecl>(
Template.getAsTemplateDecl());
117 auto *Pattern = TATD;
118 while (Pattern->getInstantiatedFromMemberTemplate())
119 Pattern = Pattern->getInstantiatedFromMemberTemplate();
120 if (!mightReferToOuterTemplateParameters(Pattern->getTemplatedDecl()))
125 TypedefNameInstantiator->InstantiateTypeAliasTemplateDecl(TATD);
129 auto *NewTATD = cast<TypeAliasTemplateDecl>(NewD);
130 MaterializedTypedefs.push_back(NewTATD->getTemplatedDecl());
157 if (OuterInstantiationArgs && InDependentContext &&
159 Decl = cast_if_present<TypedefNameDecl>(
160 TypedefNameInstantiator->InstantiateTypedefNameDecl(
161 OrigDecl, isa<TypeAliasDecl>(OrigDecl)));
164 MaterializedTypedefs.push_back(
Decl);
165 }
else if (InDependentContext) {
170 if (isa<TypeAliasDecl>(OrigDecl))
175 assert(isa<TypedefDecl>(OrigDecl) &&
"Not a Type alias or typedef");
180 MaterializedTypedefs.push_back(
Decl);
185 QualifierLoc =
getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
212 auto DeductionGuideName =
222 SemaRef.
Context, DC, LocStart, ES, Name, TInfo->
getType(), TInfo, LocEnd,
223 Ctor, DeductionCandidate::Normal, FunctionTrailingRC);
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);
231 if (isa<CXXRecordDecl>(DC))
234 if (!TemplateParams) {
240 SemaRef.
Context, DC,
Loc, DeductionGuideName, TemplateParams, Guide);
241 GuideTemplate->setImplicit(IsImplicit);
242 Guide->setDescribedFunctionTemplate(GuideTemplate);
244 if (isa<CXXRecordDecl>(DC))
248 return GuideTemplate;
255 bool EvaluateConstraint) {
271 NewTTP->setDefaultArgument(SemaRef.
Context, InstantiatedDefaultArg);
277template <
typename NonTypeTemplateOrTemplateTemplateParmDecl>
278NonTypeTemplateOrTemplateTemplateParmDecl *
280 NonTypeTemplateOrTemplateTemplateParmDecl *OldParam,
285 auto *NewParam = cast<NonTypeTemplateOrTemplateTemplateParmDecl>(
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,
321 NestedPattern = Pattern;
341 unsigned Depth1IndexAdjustment =
Template->getTemplateParameters()->size();
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());
378 Args.
setKind(TemplateSubstitutionKind::Rewrite);
388 NamedDecl *NewParam = transformTemplateParameter(
389 SemaRef, DC, Param, Args, Index + Depth1IndexAdjustment,
390 Depth ? Depth - 1 : 0);
399 NewParam = transformTemplateParameter(
400 SemaRef, DC, NewParam, OuterInstantiationArgs, Index,
406 "Unexpected template parameter depth");
408 AllParams.push_back(NewParam);
413 Expr *RequiresClause =
nullptr;
414 if (
Expr *InnerRC = InnerParams->getRequiresClause()) {
416 Args.
setKind(TemplateSubstitutionKind::Rewrite);
425 RequiresClause =
E.get();
428 TemplateParams = TemplateParameterList::Create(
429 SemaRef.
Context, InnerParams->getTemplateLoc(),
430 InnerParams->getLAngleLoc(), AllParams, InnerParams->getRAngleLoc(),
438 Args.
setKind(TemplateSubstitutionKind::Rewrite);
447 assert(FPTL &&
"no prototype for constructor declaration");
455 QualType NewType = transformFunctionProtoType(TLB, FPTL, Params, Args,
456 MaterializedTypedefs);
467 Args.
setKind(TemplateSubstitutionKind::Rewrite);
473 const_cast<Expr *
>(RC.ConstraintExpr), Args);
491 if (!FunctionTrailingRC)
492 FunctionTrailingRC = OuterRC;
497 const_cast<Expr *
>(OuterRC.ConstraintExpr),
504 return buildDeductionGuide(
507 true, MaterializedTypedefs, FunctionTrailingRC);
518 DeductionGuideName, EPI);
521 TSI = SemaRef.
SubstType(TSI, OuterInstantiationArgs,
Loc,
532 for (
auto T : ParamTypes) {
535 TSI = SemaRef.
SubstType(TSI, OuterInstantiationArgs,
Loc,
544 FPTL.
setParam(Params.size(), NewParam);
545 Params.push_back(NewParam);
548 return buildDeductionGuide(
554 QualType transformFunctionProtoType(
575 NewParam = transformFunctionTypeParam(
576 NewParam, OuterInstantiationArgs, MaterializedTypedefs,
585 transformFunctionTypeParam(NewParam, Args, MaterializedTypedefs,
589 ParamTypes.push_back(NewParam->
getType());
590 Params.push_back(NewParam);
615 ReturnType, ParamTypes, TL.
getBeginLoc(), DeductionGuideName, EPI);
634 bool TransformingOuterPatterns) {
641 SemaRef.
SubstType(PackTL.getPatternLoc(), Args,
647 PackTL.getTypePtr()->getNumExpansions());
658 NewDI = ExtractTypeForDeductionGuide(
659 SemaRef, MaterializedTypedefs, NestedPattern,
660 TransformingOuterPatterns ? &Args :
nullptr)
670 NewDefArg =
new (SemaRef.
Context)
678 auto NewType = NewDI->
getType();
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);
720 MarkDefaultArgs(cast<TemplateTemplateParmDecl>(Param));
724 for (
unsigned Index = 0; Index < TemplateParamsList->
size(); ++Index) {
725 if (ReferencedTemplateParams[Index])
726 Results.push_back(Index);
734 assert(Name.getNameKind() ==
735 DeclarationName::NameKind::CXXDeductionGuideName &&
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,
748 assert(Name.getNameKind() ==
749 DeclarationName::NameKind::CXXDeductionGuideName &&
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();
816 Args.
setKind(TemplateSubstitutionKind::Rewrite);
818 NamedDecl *NewParam = transformTemplateParameter(
820 AdjustedAliasTemplateArgs.size(),
825 AdjustedAliasTemplateArgs.push_back(NewTemplateArgument);
833 Args.
setKind(TemplateSubstitutionKind::Rewrite);
836 for (
unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
837 const auto &
D = DeduceResults[Index];
841 Args.
setKind(TemplateSubstitutionKind::Rewrite);
845 transformTemplateParameter(SemaRef, F->
getDeclContext(), TP, Args,
846 FirstUndeducedParamIdx,
848 FirstUndeducedParamIdx += 1;
849 assert(TemplateArgsForBuildingRC[Index].isNull());
850 TemplateArgsForBuildingRC[Index] =
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) {
944 Args.
setKind(TemplateSubstitutionKind::Rewrite);
946 NamedDecl *NewParam = transformTemplateParameter(
948 TransformedTemplateArgs.size(),
953 TransformedTemplateArgs.push_back(NewTemplateArgument);
957 Args.
setKind(TemplateSubstitutionKind::Rewrite);
978 TypeTrait::BTT_IsDeducible, IsDeducibleTypeTraitArgs,
982std::pair<TemplateDecl *, llvm::ArrayRef<TemplateArgument>>
984 auto RhsType =
AliasTemplate->getTemplatedDecl()->getUnderlyingType();
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] =
1061 FReturnType = cast<TemplateSpecializationType>(
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);
1141 Args.
setKind(TemplateSubstitutionKind::Rewrite);
1143 NamedDecl *NewParam = transformTemplateParameter(
1146 FPrimeTemplateParams.push_back(NewParam);
1150 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
1152 unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
1170 Args.
setKind(TemplateSubstitutionKind::Rewrite);
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) {
1194 Args.
setKind(TemplateSubstitutionKind::Rewrite);
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] =
1209 auto *TemplateArgListForBuildingFPrime =
1213 F, TemplateArgListForBuildingFPrime,
AliasTemplate->getLocation(),
1215 auto *GG = cast<CXXDeductionGuideDecl>(FPrime);
1217 Expr *IsDeducible = buildIsDeducibleConstraint(
1218 SemaRef,
AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
1219 Expr *RequiresClause =
1220 buildAssociatedConstraints(SemaRef, F,
AliasTemplate, DeduceResults,
1221 FirstUndeducedParamIdx, IsDeducible);
1223 auto *FPrimeTemplateParamList = TemplateParameterList::Create(
1224 Context,
AliasTemplate->getTemplateParameters()->getTemplateLoc(),
1226 FPrimeTemplateParams,
1229 auto *Result = cast<FunctionTemplateDecl>(buildDeductionGuide(
1231 GG->getCorrespondingConstructor(), GG->getExplicitSpecifier(),
1235 auto *DGuide = cast<CXXDeductionGuideDecl>(Result->getTemplatedDecl());
1236 DGuide->setDeductionCandidateKind(GG->getDeductionCandidateKind());
1237 DGuide->setSourceDeductionGuide(
1239 DGuide->setSourceDeductionGuideKind(
1240 CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias);
1246void DeclareImplicitDeductionGuidesForTypeAlias(
1250 auto &Context = SemaRef.
Context;
1251 auto [
Template, AliasRhsTemplateArgs] =
1255 auto SourceDeductionGuides = getSourceDeductionGuides(
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,
1286 auto *Transformed = cast<CXXDeductionGuideDecl>(buildDeductionGuide(
1291 Transformed->setSourceDeductionGuide(DG);
1292 Transformed->setSourceDeductionGuideKind(
1293 CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias);
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);
1320 ->getDeductionCandidateKind() == DeductionCandidate::Aggregate)
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)
1367 unsigned Hash = ID.ComputeHash();
1376 if (
auto *FTD = DeclareAggregateDeductionGuideForTypeAlias(
1388 DefRecord->getDescribedClassTemplate())
1396 ConvertConstructorToDeductionGuideTransform Transform(
1397 *
this, cast<ClassTemplateDecl>(
Template));
1409 if (BuildingDeductionGuides.isInvalid())
1413 Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
1416 auto *FTD = cast<FunctionTemplateDecl>(
1417 Transform.buildSimpleDeductionGuide(ParamTypes));
1434 DefRecord->getDescribedClassTemplate())
1442 ConvertConstructorToDeductionGuideTransform Transform(
1443 *
this, cast<ClassTemplateDecl>(
Template));
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();
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({});
1511 cast<CXXDeductionGuideDecl>(
1512 cast<FunctionTemplateDecl>(
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....
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
CanQualType getLogicalOperationType() const
The result type of logical operations, '<', '>', '!=', etc.
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given 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 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.
QualType getDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
CanQualType getCanonicalTagType(const TagDecl *TD) const
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a 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.
CXXRecordDecl * getDefinition() const
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
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
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
TypeSourceInfo * getTypeSourceInfo() const
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
SourceLocation getElaboratedKeywordLoc() const
SourceLocation getNameLoc() const
NestedNameSpecifierLoc getQualifierLoc() const
Store information needed for an explicit specifier.
This represents one expression.
Represents difference between two FPOptions values.
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.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
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)
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.
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={})
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.
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
void setElaboratedKeywordLoc(SourceLocation Loc)
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.
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.
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getTemplateLoc() const
Represents a type template specialization; the template must be a class template, a type alias templa...
ArrayRef< TemplateArgument > template_arguments() 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
Wrapper for source info for typedefs.
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...
@ OK_Ordinary
An ordinary object is located at an address in memory.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
@ 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.
const FunctionProtoType * T
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
const Expr * ConstraintExpr
UnsignedOrNone ArgPackSubstIndex
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.