clang 20.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::TemplateArgument Class Reference

Represents a template argument. More...

#include "clang/AST/TemplateBase.h"

Inheritance diagram for clang::TemplateArgument:
Inheritance graph
[legend]

Public Types

enum  ArgKind {
  Null = 0 , Type , Declaration , NullPtr ,
  Integral , StructuralValue , Template , TemplateExpansion ,
  Expression , Pack
}
 The kind of template argument we're storing. More...
 
using pack_iterator = const TemplateArgument *
 Iterator that traverses the elements of a template argument pack.
 

Public Member Functions

constexpr TemplateArgument ()
 Construct an empty, invalid template argument.
 
 TemplateArgument (QualType T, bool isNullPtr=false, bool IsDefaulted=false)
 Construct a template type argument.
 
 TemplateArgument (ValueDecl *D, QualType QT, bool IsDefaulted=false)
 Construct a template argument that refers to a (non-dependent) declaration.
 
 TemplateArgument (const ASTContext &Ctx, const llvm::APSInt &Value, QualType Type, bool IsDefaulted=false)
 Construct an integral constant template argument.
 
 TemplateArgument (const ASTContext &Ctx, QualType Type, const APValue &Value, bool IsDefaulted=false)
 Construct a template argument from an arbitrary constant value.
 
 TemplateArgument (const TemplateArgument &Other, QualType Type)
 Construct an integral constant template argument with the same value as Other but a different type.
 
 TemplateArgument (TemplateName Name, bool IsDefaulted=false)
 Construct a template argument that is a template.
 
 TemplateArgument (TemplateName Name, std::optional< unsigned > NumExpansions, bool IsDefaulted=false)
 Construct a template argument that is a template pack expansion.
 
 TemplateArgument (Expr *E, bool IsDefaulted=false)
 Construct a template argument that is an expression.
 
 TemplateArgument (ArrayRef< TemplateArgument > Args)
 Construct a template argument that is a template argument pack.
 
ArgKind getKind () const
 Return the kind of stored template argument.
 
bool isNull () const
 Determine whether this template argument has no value.
 
TemplateArgumentDependence getDependence () const
 
bool isDependent () const
 Whether this template argument is dependent on a template parameter such that its result can change from one instantiation to another.
 
bool isInstantiationDependent () const
 Whether this template argument is dependent on a template parameter.
 
bool containsUnexpandedParameterPack () const
 Whether this template argument contains an unexpanded parameter pack.
 
bool isPackExpansion () const
 Determine whether this template argument is a pack expansion.
 
QualType getAsType () const
 Retrieve the type for a type template argument.
 
ValueDeclgetAsDecl () const
 Retrieve the declaration for a declaration non-type template argument.
 
QualType getParamTypeForDecl () const
 
QualType getNullPtrType () const
 Retrieve the type for null non-type template argument.
 
TemplateName getAsTemplate () const
 Retrieve the template name for a template name argument.
 
TemplateName getAsTemplateOrTemplatePattern () const
 Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
 
std::optional< unsignedgetNumTemplateExpansions () const
 Retrieve the number of expansions that a template template argument expansion will produce, if known.
 
llvm::APSInt getAsIntegral () const
 Retrieve the template argument as an integral value.
 
QualType getIntegralType () const
 Retrieve the type of the integral value.
 
void setIntegralType (QualType T)
 
void setIsDefaulted (bool v)
 Set to 'true' if this TemplateArgument corresponds to a default template parameter.
 
bool getIsDefaulted () const
 If returns 'true', this TemplateArgument corresponds to a default template parameter.
 
const APValuegetAsStructuralValue () const
 Get the value of a StructuralValue.
 
QualType getStructuralValueType () const
 Get the type of a StructuralValue.
 
QualType getNonTypeTemplateArgumentType () const
 If this is a non-type template argument, get its type.
 
ExprgetAsExpr () const
 Retrieve the template argument as an expression.
 
pack_iterator pack_begin () const
 Iterator referencing the first argument of a template argument pack.
 
pack_iterator pack_end () const
 Iterator referencing one past the last argument of a template argument pack.
 
ArrayRef< TemplateArgumentpack_elements () const
 Iterator range referencing all of the elements of a template argument pack.
 
unsigned pack_size () const
 The number of template arguments in the given template argument pack.
 
ArrayRef< TemplateArgumentgetPackAsArray () const
 Return the array of arguments in this template argument pack.
 
bool structurallyEquals (const TemplateArgument &Other) const
 Determines whether two template arguments are superficially the same.
 
TemplateArgument getPackExpansionPattern () const
 When the template argument is a pack expansion, returns the pattern of the pack expansion.
 
void print (const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
 Print this template argument to the given output stream.
 
void dump (raw_ostream &Out, const ASTContext &Context) const
 Debugging aid that dumps the template argument.
 
void dump () const
 Debugging aid that dumps the template argument to standard error.
 
void Profile (llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
 Used to insert TemplateArguments into FoldingSets.
 

Static Public Member Functions

static TemplateArgument getEmptyPack ()
 
static TemplateArgument CreatePackCopy (ASTContext &Context, ArrayRef< TemplateArgument > Args)
 Create a new template argument pack by copying the given set of template arguments.
 

Detailed Description

Represents a template argument.

Definition at line 61 of file TemplateBase.h.

Member Typedef Documentation

◆ pack_iterator

Iterator that traverses the elements of a template argument pack.

Definition at line 414 of file TemplateBase.h.

Member Enumeration Documentation

◆ ArgKind

The kind of template argument we're storing.

Enumerator
Null 

Represents an empty template argument, e.g., one that has not been deduced.

Type 

The template argument is a type.

Declaration 

The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.

NullPtr 

The template argument is a null pointer or null pointer to member that was provided for a non-type template parameter.

Integral 

The template argument is an integral value stored in an llvm::APSInt that was provided for an integral non-type template parameter.

StructuralValue 

The template argument is a non-type template argument that can't be represented by the special-case Declaration, NullPtr, or Integral forms.

These values are only ever produced by constant evaluation, so cannot be dependent. TODO: merge Declaration, NullPtr and Integral into this?

Template 

The template argument is a template name that was provided for a template template parameter.

TemplateExpansion 

The template argument is a pack expansion of a template name that was provided for a template template parameter.

Expression 

The template argument is an expression, and we've not resolved it to one of the other forms yet, either because it's dependent or because we're representing a non-canonical template argument (for instance, in a TemplateSpecializationType).

Pack 

The template argument is actually a parameter pack.

Arguments are stored in the Args struct.

Definition at line 64 of file TemplateBase.h.

Constructor & Destructor Documentation

◆ TemplateArgument() [1/10]

constexpr clang::TemplateArgument::TemplateArgument ( )
inlineconstexpr

Construct an empty, invalid template argument.

Definition at line 190 of file TemplateBase.h.

References Null.

Referenced by CreatePackCopy(), getEmptyPack(), and getPackExpansionPattern().

◆ TemplateArgument() [2/10]

clang::TemplateArgument::TemplateArgument ( QualType  T,
bool  isNullPtr = false,
bool  IsDefaulted = false 
)
inline

Construct a template type argument.

Definition at line 193 of file TemplateBase.h.

References clang::T.

◆ TemplateArgument() [3/10]

clang::TemplateArgument::TemplateArgument ( ValueDecl D,
QualType  QT,
bool  IsDefaulted = false 
)
inline

Construct a template argument that refers to a (non-dependent) declaration.

Definition at line 200 of file TemplateBase.h.

References D.

◆ TemplateArgument() [4/10]

TemplateArgument::TemplateArgument ( const ASTContext Ctx,
const llvm::APSInt &  Value,
QualType  Type,
bool  IsDefaulted = false 
)

Construct an integral constant template argument.

The memory to store the value is allocated with Ctx.

Definition at line 210 of file TemplateBase.cpp.

◆ TemplateArgument() [5/10]

TemplateArgument::TemplateArgument ( const ASTContext Ctx,
QualType  Type,
const APValue Value,
bool  IsDefaulted = false 
)

Construct a template argument from an arbitrary constant value.

Definition at line 242 of file TemplateBase.cpp.

References getAsSimpleValueDeclRef(), clang::Type::isIntegralOrEnumerationType(), and V.

◆ TemplateArgument() [6/10]

clang::TemplateArgument::TemplateArgument ( const TemplateArgument Other,
QualType  Type 
)
inline

Construct an integral constant template argument with the same value as Other but a different type.

Definition at line 215 of file TemplateBase.h.

References Integer, and clang::Other.

◆ TemplateArgument() [7/10]

clang::TemplateArgument::TemplateArgument ( TemplateName  Name,
bool  IsDefaulted = false 
)
inline

Construct a template argument that is a template.

This form of template argument is generally used for template template parameters. However, the template name could be a dependent template name that ends up being instantiated to a function template whose address is taken.

Parameters
NameThe template name.
IsDefaultedIf 'true', implies that this TemplateArgument corresponds to a default template parameter

Definition at line 231 of file TemplateBase.h.

References Template, and TemplateArg.

◆ TemplateArgument() [8/10]

clang::TemplateArgument::TemplateArgument ( TemplateName  Name,
std::optional< unsigned NumExpansions,
bool  IsDefaulted = false 
)
inline

Construct a template argument that is a template pack expansion.

This form of template argument is generally used for template template parameters. However, the template name could be a dependent template name that ends up being instantiated to a function template whose address is taken.

Parameters
NameThe template name.
NumExpansionsThe number of expansions that will be generated by instantiating
IsDefaultedIf 'true', implies that this TemplateArgument corresponds to a default template parameter

Definition at line 252 of file TemplateBase.h.

References TemplateArg, and TemplateExpansion.

◆ TemplateArgument() [9/10]

clang::TemplateArgument::TemplateArgument ( Expr E,
bool  IsDefaulted = false 
)
inline

Construct a template argument that is an expression.

This form of template argument only occurs in template argument lists used for dependent types and for expression; it will not occur in a non-dependent, canonical template argument list.

Definition at line 268 of file TemplateBase.h.

References E, Expression, and TypeOrValue.

◆ TemplateArgument() [10/10]

clang::TemplateArgument::TemplateArgument ( ArrayRef< TemplateArgument Args)
inlineexplicit

Construct a template argument that is a template argument pack.

We assume that storage for the template arguments provided outlives the TemplateArgument itself.

Definition at line 278 of file TemplateBase.h.

References Args, and Pack.

Member Function Documentation

◆ containsUnexpandedParameterPack()

bool TemplateArgument::containsUnexpandedParameterPack ( ) const

Whether this template argument contains an unexpanded parameter pack.

Definition at line 346 of file TemplateBase.cpp.

References getDependence().

Referenced by clang::Sema::DiagnoseUnexpandedParameterPack(), and clang::Sema::getFullyPackExpandedSize().

◆ CreatePackCopy()

TemplateArgument TemplateArgument::CreatePackCopy ( ASTContext Context,
ArrayRef< TemplateArgument Args 
)
static

◆ dump() [1/2]

LLVM_DUMP_METHOD void TemplateArgument::dump ( ) const

Debugging aid that dumps the template argument to standard error.

Definition at line 386 of file ASTDumper.cpp.

References clang::ASTNodeTraverser< Derived, NodeDelegateType >::Visit().

◆ dump() [2/2]

void clang::TemplateArgument::dump ( raw_ostream &  Out,
const ASTContext Context 
) const

Debugging aid that dumps the template argument.

◆ getAsDecl()

ValueDecl * clang::TemplateArgument::getAsDecl ( ) const
inline

◆ getAsExpr()

Expr * clang::TemplateArgument::getAsExpr ( ) const
inline

◆ getAsIntegral()

llvm::APSInt clang::TemplateArgument::getAsIntegral ( ) const
inline

◆ getAsStructuralValue()

const APValue & clang::TemplateArgument::getAsStructuralValue ( ) const
inline

◆ getAsTemplate()

TemplateName clang::TemplateArgument::getAsTemplate ( ) const
inline

◆ getAsTemplateOrTemplatePattern()

TemplateName clang::TemplateArgument::getAsTemplateOrTemplatePattern ( ) const
inline

◆ getAsType()

QualType clang::TemplateArgument::getAsType ( ) const
inline

◆ getDependence()

TemplateArgumentDependence TemplateArgument::getDependence ( ) const

◆ getEmptyPack()

static TemplateArgument clang::TemplateArgument::getEmptyPack ( )
inlinestatic

Definition at line 285 of file TemplateBase.h.

References TemplateArgument().

Referenced by CreatePackCopy().

◆ getIntegralType()

QualType clang::TemplateArgument::getIntegralType ( ) const
inline

◆ getIsDefaulted()

bool clang::TemplateArgument::getIsDefaulted ( ) const
inline

If returns 'true', this TemplateArgument corresponds to a default template parameter.

Definition at line 393 of file TemplateBase.h.

References TypeOrValue.

Referenced by clang::ASTContext::getCanonicalTemplateArgument(), clang::ASTNodeImporter::import(), and printTo().

◆ getKind()

ArgKind clang::TemplateArgument::getKind ( ) const
inline

Return the kind of stored template argument.

Definition at line 295 of file TemplateBase.h.

References TypeOrValue.

Referenced by addAssociatedClassesAndNamespaces(), addInstanceOfTransition(), clang::ODRHash::AddTemplateArgument(), clang::ASTRecordWriter::AddTemplateArgumentLoc(), clang::Sema::BuildExpressionFromDeclTemplateArgument(), clang::Sema::BuildExpressionFromNonTypeTemplateArgument(), checkDeducedTemplateArguments(), clang::Sema::CheckTemplateArgument(), clang::Sema::CheckTemplateTypeArgument(), ConvertDeducedTemplateArgument(), DeduceTemplateArguments(), describeTemplateParameter(), DiagnoseBadDeduction(), DiagTemplateArg(), CXXNameMangler::TemplateArgManglingInfo::getArgInfo(), getAsDecl(), getAsExpr(), getAsIntegral(), getAsTemplate(), getAsTemplateOrTemplatePattern(), getAsType(), clang::ASTContext::getCanonicalTemplateArgument(), getCommonTemplateArgument(), getDependence(), clang::Sema::getFullyPackExpandedSize(), clang::TypeName::getFullyQualifiedTemplateArgument(), clang::comments::getFunctionTypeLoc(), getIntegralType(), clang::TemplateArgumentLoc::getLocation(), getMoreSpecialized(), clang::Sema::getMoreSpecializedTemplate(), getNonTypeTemplateArgumentType(), getNullPtrType(), getNumTemplateExpansions(), getPackAsArray(), getPackExpansionPattern(), getParamTypeForDecl(), clang::TemplateArgumentLoc::getSourceDeclExpression(), clang::TemplateArgumentLoc::getSourceExpression(), clang::TemplateArgumentLoc::getSourceIntegralExpression(), clang::TemplateArgumentLoc::getSourceNullPtrExpression(), clang::TemplateArgumentLoc::getSourceRange(), clang::TemplateArgumentLoc::getSourceStructuralValueExpression(), clang::Sema::getTemplateArgumentPackExpansionPattern(), clang::TemplateArgumentLoc::getTemplateEllipsisLoc(), clang::TemplateArgumentLoc::getTemplateNameLoc(), clang::TemplateArgumentLoc::getTemplateQualifierLoc(), clang::Sema::getTrivialTemplateArgumentLoc(), clang::TemplateArgumentLoc::getTypeSourceInfo(), hasTemplateArgumentForDeduction(), clang::ASTNodeImporter::import(), isEnableIf(), isNull(), isPackExpansion(), isSameAsPrimaryTemplate(), isSameTemplateArg(), IsStructurallyEquivalent(), clang::isSubstitutedDefaultArgument(), isSubstitutedTemplateArgument(), isTemplateArgumentTemplateParameter(), clang::Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(), CXXNameMangler::TemplateArgManglingInfo::needToMangleTemplateParam(), pack_begin(), pack_end(), pack_size(), print(), printArgument(), printTo(), Profile(), clang::ASTRecordReader::readTemplateArgumentLoc(), clang::TreeTransform< Derived >::RebuildPackExpansion(), ReferencesAnonymousEntity(), setIntegralType(), structurallyEquals(), clang::Sema::SubstituteExplicitTemplateArguments(), templateArgumentExpressionsEqual(), clang::TemplateArgumentLoc::TemplateArgumentLoc(), clang::TreeTransform< Derived >::TransformTemplateArgument(), clang::RecursiveASTVisitor< Derived >::TraverseTemplateArgument(), clang::RecursiveASTVisitor< Derived >::TraverseTemplateArgumentLoc(), TryDeconstructFunctionLike(), clang::templateargumentvisitor::Base< Ref, ImplClass, RetTy, ParamTys >::Visit(), and clang::ASTDeclWriter::VisitCXXMethodDecl().

◆ getNonTypeTemplateArgumentType()

QualType TemplateArgument::getNonTypeTemplateArgumentType ( ) const

◆ getNullPtrType()

QualType clang::TemplateArgument::getNullPtrType ( ) const
inline

◆ getNumTemplateExpansions()

std::optional< unsigned > TemplateArgument::getNumTemplateExpansions ( ) const

Retrieve the number of expansions that a template template argument expansion will produce, if known.

Definition at line 350 of file TemplateBase.cpp.

References getKind(), TemplateArg, and TemplateExpansion.

Referenced by clang::ASTContext::getCanonicalTemplateArgument(), getCommonTemplateArgument(), clang::Sema::getTemplateArgumentPackExpansionPattern(), and clang::ASTNodeImporter::import().

◆ getPackAsArray()

ArrayRef< TemplateArgument > clang::TemplateArgument::getPackAsArray ( ) const
inline

Return the array of arguments in this template argument pack.

Definition at line 444 of file TemplateBase.h.

References Args, getKind(), and Pack.

Referenced by describeTemplateParameter(), and printTo().

◆ getPackExpansionPattern()

TemplateArgument TemplateArgument::getPackExpansionPattern ( ) const

◆ getParamTypeForDecl()

QualType clang::TemplateArgument::getParamTypeForDecl ( ) const
inline

◆ getStructuralValueType()

QualType clang::TemplateArgument::getStructuralValueType ( ) const
inline

◆ isDependent()

bool TemplateArgument::isDependent ( ) const

Whether this template argument is dependent on a template parameter such that its result can change from one instantiation to another.

Definition at line 314 of file TemplateBase.cpp.

References getDependence().

Referenced by checkBuiltinTemplateIdType().

◆ isInstantiationDependent()

bool TemplateArgument::isInstantiationDependent ( ) const

Whether this template argument is dependent on a template parameter.

Definition at line 318 of file TemplateBase.cpp.

References getDependence().

Referenced by clang::MultiLevelTemplateArgumentList::isAnyArgInstantiationDependent(), and SubstDefaultTemplateArgument().

◆ isNull()

bool clang::TemplateArgument::isNull ( ) const
inline

◆ isPackExpansion()

bool TemplateArgument::isPackExpansion ( ) const

◆ pack_begin()

pack_iterator clang::TemplateArgument::pack_begin ( ) const
inline

◆ pack_elements()

ArrayRef< TemplateArgument > clang::TemplateArgument::pack_elements ( ) const
inline

◆ pack_end()

pack_iterator clang::TemplateArgument::pack_end ( ) const
inline

Iterator referencing one past the last argument of a template argument pack.

Definition at line 425 of file TemplateBase.h.

References Args, getKind(), and Pack.

Referenced by checkDeducedTemplateArguments(), and pack_elements().

◆ pack_size()

unsigned clang::TemplateArgument::pack_size ( ) const
inline

◆ print()

void TemplateArgument::print ( const PrintingPolicy Policy,
raw_ostream &  Out,
bool  IncludeType 
) const

◆ Profile()

void TemplateArgument::Profile ( llvm::FoldingSetNodeID &  ID,
const ASTContext Context 
) const

◆ setIntegralType()

void clang::TemplateArgument::setIntegralType ( QualType  T)
inline

Definition at line 382 of file TemplateBase.h.

References getKind(), Integer, Integral, and clang::T.

◆ setIsDefaulted()

void clang::TemplateArgument::setIsDefaulted ( bool  v)
inline

Set to 'true' if this TemplateArgument corresponds to a default template parameter.

Definition at line 389 of file TemplateBase.h.

References TypeOrValue, and v.

◆ structurallyEquals()

bool TemplateArgument::structurallyEquals ( const TemplateArgument Other) const

Member Data Documentation

◆ Args

struct A clang::TemplateArgument::Args

◆ DeclArg

struct DA clang::TemplateArgument::DeclArg

Definition at line 173 of file TemplateBase.h.

Referenced by getAsDecl(), and getParamTypeForDecl().

◆ Integer

struct I clang::TemplateArgument::Integer

Definition at line 174 of file TemplateBase.h.

Referenced by getAsIntegral(), getIntegralType(), setIntegralType(), and TemplateArgument().

◆ TemplateArg

struct TA clang::TemplateArgument::TemplateArg

◆ TypeOrValue

struct TV clang::TemplateArgument::TypeOrValue

◆ Value

struct V clang::TemplateArgument::Value

Definition at line 175 of file TemplateBase.h.


The documentation for this class was generated from the following files: