clang  17.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]
Collaboration diagram for clang::TemplateArgument:
Collaboration graph
[legend]

Public Types

enum  ArgKind {
  Null = 0, Type, Declaration, NullPtr,
  Integral, 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. More...
 

Public Member Functions

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

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. More...
 

Detailed Description

Represents a template argument.

Definition at line 60 of file TemplateBase.h.

Member Typedef Documentation

◆ pack_iterator

Iterator that traverses the elements of a template argument pack.

Definition at line 374 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.

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 63 of file TemplateBase.h.

Constructor & Destructor Documentation

◆ TemplateArgument() [1/9]

constexpr clang::TemplateArgument::TemplateArgument ( )
inlineconstexpr

Construct an empty, invalid template argument.

Definition at line 155 of file TemplateBase.h.

References Null.

Referenced by getEmptyPack(), and getPackExpansionPattern().

◆ TemplateArgument() [2/9]

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

Construct a template type argument.

Definition at line 158 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr(), NullPtr, Type, and TypeOrValue.

◆ TemplateArgument() [3/9]

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

Construct a template argument that refers to a declaration, which is either an external declaration or a template declaration.

Definition at line 168 of file TemplateBase.h.

References Declaration, DeclArg, and clang::QualType::getAsOpaquePtr().

◆ TemplateArgument() [4/9]

TemplateArgument::TemplateArgument ( 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 163 of file TemplateBase.cpp.

References clang::ASTContext::Allocate(), Integer, Integral, and memcpy().

◆ TemplateArgument() [5/9]

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 183 of file TemplateBase.h.

References Integer.

◆ TemplateArgument() [6/9]

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 199 of file TemplateBase.h.

◆ TemplateArgument() [7/9]

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 220 of file TemplateBase.h.

◆ TemplateArgument() [8/9]

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 236 of file TemplateBase.h.

References Expression, and TypeOrValue.

◆ TemplateArgument() [9/9]

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 246 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 271 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

Create a new template argument pack by copying the given set of template arguments.

Definition at line 184 of file TemplateBase.cpp.

Referenced by checkDeducedTemplateArguments(), clang::Sema::CheckTemplateArgumentList(), clang::ASTContext::getCanonicalTemplateArgument(), and clang::ASTContext::getInjectedTemplateArg().

◆ dump() [1/2]

LLVM_DUMP_METHOD void TemplateArgument::dump ( ) const

Debugging aid that dumps the template argument to standard error.

Definition at line 487 of file TemplateBase.cpp.

◆ dump() [2/2]

void TemplateArgument::dump ( raw_ostream &  Out) const

Debugging aid that dumps the template argument.

Definition at line 480 of file TemplateBase.cpp.

◆ getAsDecl()

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

◆ getAsExpr()

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

◆ getAsIntegral()

llvm::APSInt clang::TemplateArgument::getAsIntegral ( ) 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 253 of file TemplateBase.h.

References TemplateArgument().

◆ 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 361 of file TemplateBase.h.

References TypeOrValue.

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

◆ getKind()

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

Return the kind of stored template argument.

Definition at line 263 of file TemplateBase.h.

References TypeOrValue.

Referenced by addAssociatedClassesAndNamespaces(), addInstanceOfTransition(), clang::ODRHash::AddTemplateArgument(), clang::ASTRecordWriter::AddTemplateArgumentLoc(), clang::Sema::BuildExpressionFromDeclTemplateArgument(), clang::Sema::BuildExpressionFromIntegralTemplateArgument(), checkDeducedTemplateArguments(), clang::Sema::CheckTemplateArgument(), clang::Sema::CheckTemplateTypeArgument(), DiagTemplateArg(), getAsDecl(), getAsExpr(), getAsIntegral(), getAsTemplate(), getAsTemplateOrTemplatePattern(), getAsType(), clang::ASTContext::getCanonicalTemplateArgument(), getCommonTemplateArgument(), getDependence(), clang::Sema::getFullyPackExpandedSize(), clang::TypeName::getFullyQualifiedTemplateArgument(), clang::comments::getFunctionTypeLoc(), getIntegralType(), clang::TemplateArgumentLoc::getLocation(), 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::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(), clang::Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(), pack_begin(), pack_end(), pack_size(), printTo(), clang::ASTRecordReader::readTemplateArgumentLoc(), clang::TreeTransform< EnsureImmediateInvocationInDefaultArgs >::RebuildPackExpansion(), ReferencesAnonymousEntity(), setIntegralType(), structurallyEquals(), clang::TemplateArgumentLoc::TemplateArgumentLoc(), clang::TreeTransform< EnsureImmediateInvocationInDefaultArgs >::TransformTemplateArgument(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgument(), clang::RecursiveASTVisitor< CallGraph >::TraverseTemplateArgumentLoc(), TryDeconstructFunctionLike(), and clang::templateargumentvisitor::Base< llvm::make_const_ref, TextNodeDumper, void, ParamTys... >::Visit().

◆ 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 275 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 404 of file TemplateBase.h.

References Args, getKind(), and Pack.

Referenced by printTo().

◆ getPackExpansionPattern()

TemplateArgument TemplateArgument::getPackExpansionPattern ( ) const

◆ getParamTypeForDecl()

QualType clang::TemplateArgument::getParamTypeForDecl ( ) 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 240 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 244 of file TemplateBase.cpp.

References getDependence().

Referenced by clang::MultiLevelTemplateArgumentList::isAnyArgInstantiationDependent().

◆ isNull()

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

Determine whether this template argument has no value.

Definition at line 266 of file TemplateBase.h.

References getKind(), and Null.

Referenced by checkDeducedTemplateArguments(), clang::Sema::CheckTemplateArgument(), clang::Sema::DiagnoseUnexpandedParameterPack(), and clang::TemplateTemplateParmDecl::setDefaultArgument().

◆ isPackExpansion()

bool TemplateArgument::isPackExpansion ( ) const

◆ pack_begin()

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

Iterator referencing the first argument of a template argument pack.

Definition at line 378 of file TemplateBase.h.

References Args, getKind(), and Pack.

Referenced by checkDeducedTemplateArguments(), isSameAsPrimaryTemplate(), clang::Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(), and pack_elements().

◆ 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 385 of file TemplateBase.h.

References Args, getKind(), and Pack.

Referenced by pack_elements().

◆ pack_size()

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

◆ print()

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

Print this template argument to the given output stream.

Definition at line 410 of file TemplateBase.cpp.

◆ Profile()

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

Used to insert TemplateArguments into FoldingSets.

Definition at line 308 of file TemplateBase.cpp.

◆ setIntegralType()

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

Definition at line 350 of file TemplateBase.h.

References clang::QualType::getAsOpaquePtr(), getKind(), Integer, and Integral.

◆ setIsDefaulted()

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

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

Definition at line 357 of file TemplateBase.h.

References TypeOrValue, and v.

◆ structurallyEquals()

bool TemplateArgument::structurallyEquals ( const TemplateArgument Other) const

Determines whether two template arguments are superficially the same.

Definition at line 351 of file TemplateBase.cpp.

References Args, Declaration, Expression, getAsDecl(), getAsIntegral(), getIntegralType(), getKind(), getParamTypeForDecl(), Integral, Null, NullPtr, Pack, Template, TemplateArg, TemplateExpansion, Type, and TypeOrValue.

Referenced by isSubstitutedTemplateArgument().

Member Data Documentation

◆ Args

struct A clang::TemplateArgument::Args

◆ DeclArg

struct DA clang::TemplateArgument::DeclArg

Definition at line 146 of file TemplateBase.h.

Referenced by getAsDecl(), getParamTypeForDecl(), and TemplateArgument().

◆ Integer

struct I clang::TemplateArgument::Integer

Definition at line 147 of file TemplateBase.h.

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

◆ TemplateArg

struct TA clang::TemplateArgument::TemplateArg

◆ TypeOrValue

struct TV clang::TemplateArgument::TypeOrValue

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