clang 20.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
clang::VarDecl Class Reference

Represents a variable declaration or definition. More...

#include "clang/AST/Decl.h"

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

Classes

class  NonParmVarDeclBitfields
 
class  ParmVarDeclBitfields
 

Public Types

enum  InitializationStyle { CInit , CallInit , ListInit , ParenListInit }
 Initialization styles. More...
 
enum  TLSKind { TLS_None , TLS_Static , TLS_Dynamic }
 Kinds of thread-local storage. More...
 
enum  DefinitionKind { DeclarationOnly , TentativeDefinition , Definition }
 
using redecl_range = redeclarable_base::redecl_range
 
using redecl_iterator = redeclarable_base::redecl_iterator
 
- Public Types inherited from clang::NamedDecl
enum  ExplicitVisibilityKind { VisibilityForType , VisibilityForValue }
 Kinds of explicit visibility. More...
 
- Public Types inherited from clang::Decl
enum  Kind
 Lists the kind of concrete classes of Decl. More...
 
enum  IdentifierNamespace {
  IDNS_Label = 0x0001 , IDNS_Tag = 0x0002 , IDNS_Type = 0x0004 , IDNS_Member = 0x0008 ,
  IDNS_Namespace = 0x0010 , IDNS_Ordinary = 0x0020 , IDNS_ObjCProtocol = 0x0040 , IDNS_OrdinaryFriend = 0x0080 ,
  IDNS_TagFriend = 0x0100 , IDNS_Using = 0x0200 , IDNS_NonMemberOperator = 0x0400 , IDNS_LocalExtern = 0x0800 ,
  IDNS_OMPReduction = 0x1000 , IDNS_OMPMapper = 0x2000
}
 IdentifierNamespace - The different namespaces in which declarations may appear. More...
 
enum  ObjCDeclQualifier {
  OBJC_TQ_None = 0x0 , OBJC_TQ_In = 0x1 , OBJC_TQ_Inout = 0x2 , OBJC_TQ_Out = 0x4 ,
  OBJC_TQ_Bycopy = 0x8 , OBJC_TQ_Byref = 0x10 , OBJC_TQ_Oneway = 0x20 , OBJC_TQ_CSNullability = 0x40
}
 ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declarations. More...
 
enum class  ModuleOwnershipKind : unsigned char {
  Unowned , Visible , VisibleWhenImported , ReachableWhenImported ,
  ModulePrivate
}
 The kind of ownership a declaration has, for visibility purposes. More...
 
enum  FriendObjectKind { FOK_None , FOK_Declared , FOK_Undeclared }
 
using attr_iterator = AttrVec::const_iterator
 
using attr_range = llvm::iterator_range< attr_iterator >
 
using redecl_range = llvm::iterator_range< redecl_iterator >
 
- Public Types inherited from clang::Redeclarable< VarDecl >
using redecl_range = llvm::iterator_range< redecl_iterator >
 

Public Member Functions

SourceRange getSourceRange () const override LLVM_READONLY
 Source range that this declaration covers.
 
StorageClass getStorageClass () const
 Returns the storage class as written in the source.
 
void setStorageClass (StorageClass SC)
 
void setTSCSpec (ThreadStorageClassSpecifier TSC)
 
ThreadStorageClassSpecifier getTSCSpec () const
 
TLSKind getTLSKind () const
 
bool hasLocalStorage () const
 Returns true if a variable with function scope is a non-static local variable.
 
bool isStaticLocal () const
 Returns true if a variable with function scope is a static local variable.
 
bool hasExternalStorage () const
 Returns true if a variable has extern or private_extern storage.
 
bool hasGlobalStorage () const
 Returns true for all variables that do not have local storage.
 
StorageDuration getStorageDuration () const
 Get the storage duration of this variable, per C++ [basic.stc].
 
LanguageLinkage getLanguageLinkage () const
 Compute the language linkage.
 
bool isExternC () const
 Determines whether this variable is a variable with external, C linkage.
 
bool isInExternCContext () const
 Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.
 
bool isInExternCXXContext () const
 Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.
 
bool isLocalVarDecl () const
 Returns true for local variable declarations other than parameters.
 
bool isLocalVarDeclOrParm () const
 Similar to isLocalVarDecl but also includes parameters.
 
bool isFunctionOrMethodVarDecl () const
 Similar to isLocalVarDecl, but excludes variables declared in blocks.
 
bool isStaticDataMember () const
 Determines whether this is a static data member.
 
VarDeclgetCanonicalDecl () override
 Retrieves the "canonical" declaration of the given declaration.
 
const VarDeclgetCanonicalDecl () const
 
DefinitionKind isThisDeclarationADefinition (ASTContext &) const
 Check whether this declaration is a definition.
 
DefinitionKind isThisDeclarationADefinition () const
 
DefinitionKind hasDefinition (ASTContext &) const
 Check whether this variable is defined in this translation unit.
 
DefinitionKind hasDefinition () const
 
VarDeclgetActingDefinition ()
 Get the tentative definition that acts as the real definition in a TU.
 
const VarDeclgetActingDefinition () const
 
VarDeclgetDefinition (ASTContext &)
 Get the real (not just tentative) definition for this declaration.
 
const VarDeclgetDefinition (ASTContext &C) const
 
VarDeclgetDefinition ()
 
const VarDeclgetDefinition () const
 
bool isOutOfLine () const override
 Determine whether this is or was instantiated from an out-of-line definition of a static data member.
 
bool isFileVarDecl () const
 Returns true for file scoped variable declaration.
 
const ExprgetAnyInitializer () const
 Get the initializer for this variable, no matter which declaration it is attached to.
 
const ExprgetAnyInitializer (const VarDecl *&D) const
 Get the initializer for this variable, no matter which declaration it is attached to.
 
bool hasInit () const
 
const ExprgetInit () const
 
ExprgetInit ()
 
Stmt ** getInitAddress ()
 Retrieve the address of the initializer expression.
 
void setInit (Expr *I)
 
VarDeclgetInitializingDeclaration ()
 Get the initializing declaration of this variable, if any.
 
const VarDeclgetInitializingDeclaration () const
 
bool mightBeUsableInConstantExpressions (const ASTContext &C) const
 Determine whether this variable's value might be usable in a constant expression, according to the relevant language standard.
 
bool isUsableInConstantExpressions (const ASTContext &C) const
 Determine whether this variable's value can be used in a constant expression, according to the relevant language standard, including checking whether it was initialized by a constant expression.
 
EvaluatedStmtensureEvaluatedStmt () const
 Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.
 
EvaluatedStmtgetEvaluatedStmt () const
 
APValueevaluateValue () const
 Attempt to evaluate the value of the initializer attached to this declaration, and produce notes explaining why it cannot be evaluated.
 
APValuegetEvaluatedValue () const
 Return the already-evaluated value of this variable's initializer, or NULL if the value is not yet known.
 
bool evaluateDestruction (SmallVectorImpl< PartialDiagnosticAt > &Notes) const
 Evaluate the destruction of this variable to determine if it constitutes constant destruction.
 
bool hasConstantInitialization () const
 Determine whether this variable has constant initialization.
 
bool hasICEInitializer (const ASTContext &Context) const
 Determine whether the initializer of this variable is an integer constant expression.
 
bool checkForConstantInitialization (SmallVectorImpl< PartialDiagnosticAt > &Notes) const
 Evaluate the initializer of this variable to determine whether it's a constant initializer.
 
void setInitStyle (InitializationStyle Style)
 
InitializationStyle getInitStyle () const
 The style of initialization for this declaration.
 
bool isDirectInit () const
 Whether the initializer is a direct-initializer (list or call).
 
bool isThisDeclarationADemotedDefinition () const
 If this definition should pretend to be a declaration.
 
void demoteThisDefinitionToDeclaration ()
 This is a definition which should be demoted to a declaration.
 
bool isExceptionVariable () const
 Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C @catch statement.
 
void setExceptionVariable (bool EV)
 
bool isNRVOVariable () const
 Determine whether this local variable can be used with the named return value optimization (NRVO).
 
void setNRVOVariable (bool NRVO)
 
bool isCXXForRangeDecl () const
 Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
 
void setCXXForRangeDecl (bool FRD)
 
bool isObjCForDecl () const
 Determine whether this variable is a for-loop declaration for a for-in statement in Objective-C.
 
void setObjCForDecl (bool FRD)
 
bool isARCPseudoStrong () const
 Determine whether this variable is an ARC pseudo-__strong variable.
 
void setARCPseudoStrong (bool PS)
 
bool isInline () const
 Whether this variable is (C++1z) inline.
 
bool isInlineSpecified () const
 
void setInlineSpecified ()
 
void setImplicitlyInline ()
 
bool isConstexpr () const
 Whether this variable is (C++11) constexpr.
 
void setConstexpr (bool IC)
 
bool isInitCapture () const
 Whether this variable is the implicit variable for a lambda init-capture.
 
void setInitCapture (bool IC)
 
bool isParameterPack () const
 Determine whether this variable is actually a function parameter pack or init-capture pack.
 
bool isPreviousDeclInSameBlockScope () const
 Whether this local extern variable declaration's previous declaration was declared in the same block scope.
 
void setPreviousDeclInSameBlockScope (bool Same)
 
bool isEscapingByref () const
 Indicates the capture is a __block variable that is captured by a block that can potentially escape (a block for which BlockDecl::doesNotEscape returns false).
 
bool isNonEscapingByref () const
 Indicates the capture is a __block variable that is never captured by an escaping block.
 
void setEscapingByref ()
 
bool isCXXCondDecl () const
 
void setCXXCondDecl ()
 
bool hasDependentAlignment () const
 Determines if this variable's alignment is dependent.
 
VarDeclgetTemplateInstantiationPattern () const
 Retrieve the variable declaration from which this variable could be instantiated, if it is an instantiation (rather than a non-template).
 
VarDeclgetInstantiatedFromStaticDataMember () const
 If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.
 
TemplateSpecializationKind getTemplateSpecializationKind () const
 If this variable is an instantiation of a variable template or a static data member of a class template, determine what kind of template specialization or instantiation this is.
 
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation () const
 Get the template specialization kind of this variable for the purposes of template instantiation.
 
SourceLocation getPointOfInstantiation () const
 If this variable is an instantiation of a variable template or a static data member of a class template, determine its point of instantiation.
 
MemberSpecializationInfogetMemberSpecializationInfo () const
 If this variable is an instantiation of a static data member of a class template specialization, retrieves the member specialization information.
 
void setTemplateSpecializationKind (TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
 For a static data member that was instantiated from a static data member of a class template, set the template specialiation kind.
 
void setInstantiationOfStaticDataMember (VarDecl *VD, TemplateSpecializationKind TSK)
 Specify that this variable is an instantiation of the static data member VD.
 
VarTemplateDeclgetDescribedVarTemplate () const
 Retrieves the variable template that is described by this variable declaration.
 
void setDescribedVarTemplate (VarTemplateDecl *Template)
 
bool isKnownToBeDefined () const
 
bool isNoDestroy (const ASTContext &) const
 Is destruction of this variable entirely suppressed? If so, the variable need not have a usable destructor at all.
 
QualType::DestructionKind needsDestruction (const ASTContext &Ctx) const
 Would the destruction of this variable have any effect, and if so, what kind?
 
bool hasFlexibleArrayInit (const ASTContext &Ctx) const
 Whether this variable has a flexible array member initialized with one or more elements.
 
CharUnits getFlexibleArrayInitChars (const ASTContext &Ctx) const
 If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elements.
 
- Public Member Functions inherited from clang::DeclaratorDecl
TypeSourceInfogetTypeSourceInfo () const
 
void setTypeSourceInfo (TypeSourceInfo *TI)
 
SourceLocation getInnerLocStart () const
 Return start of source range ignoring outer template declarations.
 
void setInnerLocStart (SourceLocation L)
 
SourceLocation getOuterLocStart () const
 Return start of source range taking into account any outer template declarations.
 
SourceRange getSourceRange () const override LLVM_READONLY
 Source range that this declaration covers.
 
SourceLocation getBeginLoc () const LLVM_READONLY
 
NestedNameSpecifiergetQualifier () const
 Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in the source.
 
NestedNameSpecifierLoc getQualifierLoc () const
 Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this declaration, if it was present in the source.
 
void setQualifierInfo (NestedNameSpecifierLoc QualifierLoc)
 
ExprgetTrailingRequiresClause ()
 Get the constraint-expression introduced by the trailing requires-clause in the function/member declaration, or null if no requires-clause was provided.
 
const ExprgetTrailingRequiresClause () const
 
void setTrailingRequiresClause (Expr *TrailingRequiresClause)
 
unsigned getNumTemplateParameterLists () const
 
TemplateParameterListgetTemplateParameterList (unsigned index) const
 
void setTemplateParameterListsInfo (ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
 
SourceLocation getTypeSpecStartLoc () const
 
SourceLocation getTypeSpecEndLoc () const
 
- Public Member Functions inherited from clang::ValueDecl
QualType getType () const
 
void setType (QualType newType)
 
bool isWeak () const
 Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
 
bool isInitCapture () const
 Whether this variable is the implicit variable for a lambda init-capture.
 
VarDeclgetPotentiallyDecomposedVarDecl ()
 
const VarDeclgetPotentiallyDecomposedVarDecl () const
 
- Public Member Functions inherited from clang::NamedDecl
IdentifierInfogetIdentifier () const
 Get the identifier that names this declaration, if there is one.
 
StringRef getName () const
 Get the name of identifier for this declaration as a StringRef.
 
std::string getNameAsString () const
 Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ constructor, Objective-C selector, etc).
 
virtual void printName (raw_ostream &OS, const PrintingPolicy &Policy) const
 Pretty-print the unqualified name of this declaration.
 
void printName (raw_ostream &OS) const
 Calls printName() with the ASTContext printing policy from the decl.
 
DeclarationName getDeclName () const
 Get the actual, stored name of the declaration, which may be a special name.
 
void setDeclName (DeclarationName N)
 Set the name of this declaration.
 
void printQualifiedName (raw_ostream &OS) const
 Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of namespace A::B.
 
void printQualifiedName (raw_ostream &OS, const PrintingPolicy &Policy) const
 
void printNestedNameSpecifier (raw_ostream &OS) const
 Print only the nested name specifier part of a fully-qualified name, including the '::' at the end.
 
void printNestedNameSpecifier (raw_ostream &OS, const PrintingPolicy &Policy) const
 
std::string getQualifiedNameAsString () const
 
virtual void getNameForDiagnostic (raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
 Appends a human-readable name for this declaration into the given stream.
 
bool declarationReplaces (const NamedDecl *OldD, bool IsKnownNewer=true) const
 Determine whether this declaration, if known to be well-formed within its context, will replace the declaration OldD if introduced into scope.
 
bool hasLinkage () const
 Determine whether this declaration has linkage.
 
bool isCXXClassMember () const
 Determine whether this declaration is a C++ class member.
 
bool isCXXInstanceMember () const
 Determine whether the given declaration is an instance member of a C++ class.
 
ReservedIdentifierStatus isReserved (const LangOptions &LangOpts) const
 Determine if the declaration obeys the reserved identifier rules of the given language.
 
Linkage getLinkageInternal () const
 Determine what kind of linkage this entity has.
 
Linkage getFormalLinkage () const
 Get the linkage from a semantic point of view.
 
bool hasExternalFormalLinkage () const
 True if this decl has external linkage.
 
bool isExternallyVisible () const
 
bool isExternallyDeclarable () const
 Determine whether this declaration can be redeclared in a different translation unit.
 
Visibility getVisibility () const
 Determines the visibility of this entity.
 
LinkageInfo getLinkageAndVisibility () const
 Determines the linkage and visibility of this entity.
 
std::optional< VisibilitygetExplicitVisibility (ExplicitVisibilityKind kind) const
 If visibility was explicitly specified for this declaration, return that visibility.
 
bool isLinkageValid () const
 True if the computed linkage is valid.
 
bool hasLinkageBeenComputed () const
 True if something has required us to compute the linkage of this declaration.
 
bool isPlaceholderVar (const LangOptions &LangOpts) const
 
NamedDeclgetUnderlyingDecl ()
 Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
 
const NamedDeclgetUnderlyingDecl () const
 
NamedDeclgetMostRecentDecl ()
 
const NamedDeclgetMostRecentDecl () const
 
ObjCStringFormatFamily getObjCFStringFormattingFamily () const
 
bool isModulePrivate () const
 Whether this declaration was marked as being private to the module in which it was defined.
 
void setModulePrivate ()
 Specify that this declaration was marked as being private to the module in which it was defined.
 
- Public Member Functions inherited from clang::Decl
 Decl ()=delete
 
 Decl (const Decl &)=delete
 
 Decl (Decl &&)=delete
 
Decloperator= (const Decl &)=delete
 
Decloperator= (Decl &&)=delete
 
virtual SourceRange getSourceRange () const LLVM_READONLY
 Source range that this declaration covers.
 
SourceLocation getBeginLoc () const LLVM_READONLY
 
SourceLocation getEndLoc () const LLVM_READONLY
 
SourceLocation getLocation () const
 
void setLocation (SourceLocation L)
 
Kind getKind () const
 
const char * getDeclKindName () const
 
DeclgetNextDeclInContext ()
 
const DeclgetNextDeclInContext () const
 
DeclContextgetDeclContext ()
 
const DeclContextgetDeclContext () const
 
DeclContextgetNonTransparentDeclContext ()
 Return the non transparent context.
 
const DeclContextgetNonTransparentDeclContext () const
 
DeclgetNonClosureContext ()
 Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
 
const DeclgetNonClosureContext () const
 
TranslationUnitDeclgetTranslationUnitDecl ()
 
const TranslationUnitDeclgetTranslationUnitDecl () const
 
bool isInAnonymousNamespace () const
 
bool isInStdNamespace () const
 
bool isFileContextDecl () const
 
ASTContextgetASTContext () const LLVM_READONLY
 
const LangOptionsgetLangOpts () const LLVM_READONLY
 Helper to get the language options from the ASTContext.
 
void setAccess (AccessSpecifier AS)
 
AccessSpecifier getAccess () const
 
AccessSpecifier getAccessUnsafe () const
 Retrieve the access specifier for this declaration, even though it may not yet have been properly set.
 
bool hasAttrs () const
 
void setAttrs (const AttrVec &Attrs)
 
AttrVecgetAttrs ()
 
const AttrVecgetAttrs () const
 
void dropAttrs ()
 
void addAttr (Attr *A)
 
attr_range attrs () const
 
attr_iterator attr_begin () const
 
attr_iterator attr_end () const
 
template<typename... Ts>
void dropAttrs ()
 
template<typename T >
void dropAttr ()
 
template<typename T >
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs () const
 
template<typename T >
specific_attr_iterator< Tspecific_attr_begin () const
 
template<typename T >
specific_attr_iterator< Tspecific_attr_end () const
 
template<typename T >
TgetAttr () const
 
template<typename T >
bool hasAttr () const
 
unsigned getMaxAlignment () const
 getMaxAlignment - return the maximum alignment specified by attributes on this decl, 0 if there are none.
 
void setInvalidDecl (bool Invalid=true)
 setInvalidDecl - Indicates the Decl had a semantic error.
 
bool isInvalidDecl () const
 
bool isImplicit () const
 isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
 
void setImplicit (bool I=true)
 
bool isUsed (bool CheckUsedAttr=true) const
 Whether any (re-)declaration of the entity was used, meaning that a definition is required.
 
void setIsUsed ()
 Set whether the declaration is used, in the sense of odr-use.
 
void markUsed (ASTContext &C)
 Mark the declaration used, in the sense of odr-use.
 
bool isReferenced () const
 Whether any declaration of this entity was referenced.
 
bool isThisDeclarationReferenced () const
 Whether this declaration was referenced.
 
void setReferenced (bool R=true)
 
bool isTopLevelDeclInObjCContainer () const
 Whether this declaration is a top-level declaration (function, global variable, etc.) that is lexically inside an objc container definition.
 
void setTopLevelDeclInObjCContainer (bool V=true)
 
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr () const
 Looks on this and related declarations for an applicable external source symbol attribute.
 
bool isModulePrivate () const
 Whether this declaration was marked as being private to the module in which it was defined.
 
bool isInExportDeclContext () const
 Whether this declaration was exported in a lexical context.
 
bool isInvisibleOutsideTheOwningModule () const
 
bool isInAnotherModuleUnit () const
 Whether this declaration comes from another module unit.
 
bool isInCurrentModuleUnit () const
 Whether this declaration comes from the same module unit being compiled.
 
bool shouldEmitInExternalSource () const
 Whether the definition of the declaration should be emitted in external sources.
 
bool isFromExplicitGlobalModule () const
 Whether this declaration comes from explicit global module.
 
bool isFromGlobalModule () const
 Whether this declaration comes from global module.
 
bool isInNamedModule () const
 Whether this declaration comes from a named module.
 
bool isFromHeaderUnit () const
 Whether this declaration comes from a header unit.
 
bool hasDefiningAttr () const
 Return true if this declaration has an attribute which acts as definition of the entity, such as 'alias' or 'ifunc'.
 
const AttrgetDefiningAttr () const
 Return this declaration's defining attribute if it has one.
 
void setFromASTFile ()
 Set the FromASTFile flag.
 
void setOwningModuleID (unsigned ID)
 Set the owning module ID.
 
AvailabilityResult getAvailability (std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
 Determine the availability of the given declaration.
 
VersionTuple getVersionIntroduced () const
 Retrieve the version of the target platform in which this declaration was introduced.
 
bool isDeprecated (std::string *Message=nullptr) const
 Determine whether this declaration is marked 'deprecated'.
 
bool isUnavailable (std::string *Message=nullptr) const
 Determine whether this declaration is marked 'unavailable'.
 
bool isWeakImported () const
 Determine whether this is a weak-imported symbol.
 
bool canBeWeakImported (bool &IsDefinition) const
 Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the weak_import attribute.
 
bool isFromASTFile () const
 Determine whether this declaration came from an AST file (such as a precompiled header or module) rather than having been parsed.
 
GlobalDeclID getGlobalID () const
 Retrieve the global declaration ID associated with this declaration, which specifies where this Decl was loaded from.
 
unsigned getOwningModuleID () const
 Retrieve the global ID of the module that owns this particular declaration.
 
ModulegetImportedOwningModule () const
 Get the imported owning module, if this decl is from an imported (non-local) module.
 
ModulegetLocalOwningModule () const
 Get the local owning module, if known.
 
void setLocalOwningModule (Module *M)
 
bool hasOwningModule () const
 Is this declaration owned by some module?
 
ModulegetOwningModule () const
 Get the module that owns this declaration (for visibility purposes).
 
ModulegetOwningModuleForLinkage () const
 Get the module that owns this declaration for linkage purposes.
 
bool isUnconditionallyVisible () const
 Determine whether this declaration is definitely visible to name lookup, independent of whether the owning module is visible.
 
bool isReachable () const
 
void setVisibleDespiteOwningModule ()
 Set that this declaration is globally visible, even if it came from a module that is not visible.
 
ModuleOwnershipKind getModuleOwnershipKind () const
 Get the kind of module ownership for this declaration.
 
void setModuleOwnershipKind (ModuleOwnershipKind MOK)
 Set whether this declaration is hidden from name lookup.
 
unsigned getIdentifierNamespace () const
 
bool isInIdentifierNamespace (unsigned NS) const
 
bool hasTagIdentifierNamespace () const
 
DeclContextgetLexicalDeclContext ()
 getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
 
const DeclContextgetLexicalDeclContext () const
 
virtual bool isOutOfLine () const
 Determine whether this declaration is declared out of line (outside its semantic context).
 
void setDeclContext (DeclContext *DC)
 setDeclContext - Set both the semantic and lexical DeclContext to DC.
 
void setLexicalDeclContext (DeclContext *DC)
 
bool isTemplated () const
 Determine whether this declaration is a templated entity (whether it is.
 
unsigned getTemplateDepth () const
 Determine the number of levels of template parameter surrounding this declaration.
 
bool isDefinedOutsideFunctionOrMethod () const
 isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside the current function or method.
 
bool isInLocalScopeForInstantiation () const
 Determine whether a substitution into this declaration would occur as part of a substitution into a dependent local scope.
 
const DeclContextgetParentFunctionOrMethod (bool LexicalParent=false) const
 If this decl is defined inside a function/method/block it returns the corresponding DeclContext, otherwise it returns null.
 
DeclContextgetParentFunctionOrMethod (bool LexicalParent=false)
 
virtual DeclgetCanonicalDecl ()
 Retrieves the "canonical" declaration of the given declaration.
 
const DeclgetCanonicalDecl () const
 
bool isCanonicalDecl () const
 Whether this particular Decl is a canonical one.
 
redecl_range redecls () const
 Returns an iterator range for all the redeclarations of the same decl.
 
redecl_iterator redecls_begin () const
 
redecl_iterator redecls_end () const
 
DeclgetPreviousDecl ()
 Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
 
const DeclgetPreviousDecl () const
 Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
 
bool isFirstDecl () const
 True if this is the first declaration in its redeclaration chain.
 
DeclgetMostRecentDecl ()
 Retrieve the most recent declaration that declares the same entity as this declaration (which may be this declaration).
 
const DeclgetMostRecentDecl () const
 Retrieve the most recent declaration that declares the same entity as this declaration (which may be this declaration).
 
virtual StmtgetBody () const
 getBody - If this Decl represents a declaration for a body of code, such as a function or method definition, this method returns the top-level Stmt* of that body.
 
virtual bool hasBody () const
 Returns true if this Decl represents a declaration for a body of code, such as a function or method definition.
 
SourceLocation getBodyRBrace () const
 getBodyRBrace - Gets the right brace of the body, if a body exists.
 
bool isTemplateParameter () const
 isTemplateParameter - Determines whether this declaration is a template parameter.
 
bool isTemplateParameterPack () const
 isTemplateParameter - Determines whether this declaration is a template parameter pack.
 
bool isParameterPack () const
 Whether this declaration is a parameter pack.
 
bool isTemplateDecl () const
 returns true if this declaration is a template
 
bool isFunctionOrFunctionTemplate () const
 Whether this declaration is a function or function template.
 
TemplateDeclgetDescribedTemplate () const
 If this is a declaration that describes some template, this method returns that template declaration.
 
const TemplateParameterListgetDescribedTemplateParams () const
 If this is a declaration that describes some template or partial specialization, this returns the corresponding template parameter list.
 
FunctionDeclgetAsFunction () LLVM_READONLY
 Returns the function itself, or the templated function if this is a function template.
 
const FunctionDeclgetAsFunction () const
 
void setLocalExternDecl ()
 Changes the namespace of this declaration to reflect that it's a function-local extern declaration.
 
bool isLocalExternDecl () const
 Determine whether this is a block-scope declaration with linkage.
 
void setObjectOfFriendDecl (bool PerformFriendInjection=false)
 Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
 
void clearIdentifierNamespace ()
 Clears the namespace of this declaration.
 
FriendObjectKind getFriendObjectKind () const
 Determines whether this declaration is the object of a friend declaration and, if so, what kind.
 
void setNonMemberOperator ()
 Specifies that this declaration is a C++ overloaded non-member.
 
void print (raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
 
void print (raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0, bool PrintInstantiation=false) const
 
void dump () const
 
void dumpColor () const
 
void dump (raw_ostream &Out, bool Deserialize=false, ASTDumpOutputFormat OutputFormat=ADOF_Default) const
 
int64_t getID () const
 
const FunctionTypegetFunctionType (bool BlocksToo=true) const
 Looks through the Decl's underlying type to extract a FunctionType when possible.
 
bool isFunctionPointerType () const
 
- Public Member Functions inherited from clang::Redeclarable< VarDecl >
 Redeclarable (const ASTContext &Ctx)
 
VarDeclgetPreviousDecl ()
 Return the previous declaration of this declaration or NULL if this is the first declaration.
 
const VarDeclgetPreviousDecl () const
 
VarDeclgetFirstDecl ()
 Return the first declaration of this declaration or itself if this is the only declaration.
 
const VarDeclgetFirstDecl () const
 Return the first declaration of this declaration or itself if this is the only declaration.
 
bool isFirstDecl () const
 True if this is the first declaration in its redeclaration chain.
 
VarDeclgetMostRecentDecl ()
 Returns the most recent (re)declaration of this declaration.
 
const VarDeclgetMostRecentDecl () const
 Returns the most recent (re)declaration of this declaration.
 
void setPreviousDecl (VarDecl *PrevDecl)
 Set the previous declaration.
 
redecl_range redecls () const
 Returns an iterator range for all the redeclarations of the same decl.
 
redecl_iterator redecls_begin () const
 
redecl_iterator redecls_end () const
 

Static Public Member Functions

static const char * getStorageClassSpecifierString (StorageClass SC)
 Return the string used to specify the storage class SC.
 
static VarDeclCreate (ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
 
static VarDeclCreateDeserialized (ASTContext &C, GlobalDeclID ID)
 
static bool classof (const Decl *D)
 
static bool classofKind (Kind K)
 
- Static Public Member Functions inherited from clang::DeclaratorDecl
static bool classof (const Decl *D)
 
static bool classofKind (Kind K)
 
- Static Public Member Functions inherited from clang::ValueDecl
static bool classof (const Decl *D)
 
static bool classofKind (Kind K)
 
- Static Public Member Functions inherited from clang::NamedDecl
static bool classof (const Decl *D)
 
static bool classofKind (Kind K)
 
- Static Public Member Functions inherited from clang::Decl
static bool isFlexibleArrayMemberLike (ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
 Whether it resembles a flexible array member.
 
static unsigned getIdentifierNamespaceForKind (Kind DK)
 
static bool isTagIdentifierNamespace (unsigned NS)
 
static void add (Kind k)
 
static void EnableStatistics ()
 
static void PrintStats ()
 
static bool classofKind (Kind K)
 
static DeclContextcastToDeclContext (const Decl *)
 
static DeclcastFromDeclContext (const DeclContext *)
 
static void printGroup (Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
 

Protected Types

enum  { NumParameterIndexBits = 8 }
 
enum  DefaultArgKind { DAK_None , DAK_Unparsed , DAK_Uninstantiated , DAK_Normal }
 
enum  { NumScopeDepthOrObjCQualsBits = 7 }
 
using InitType = llvm::PointerUnion< Stmt *, EvaluatedStmt * >
 
using redeclarable_base = Redeclarable< VarDecl >
 

Protected Member Functions

 VarDecl (Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
 
VarDeclgetNextRedeclarationImpl () override
 Returns the next redeclaration or itself if this is the only decl.
 
VarDeclgetPreviousDeclImpl () override
 Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
 
VarDeclgetMostRecentDeclImpl () override
 Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chain.
 
- Protected Member Functions inherited from clang::DeclaratorDecl
 DeclaratorDecl (Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL)
 
- Protected Member Functions inherited from clang::ValueDecl
 ValueDecl (Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T)
 
- Protected Member Functions inherited from clang::NamedDecl
 NamedDecl (Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
 
- Protected Member Functions inherited from clang::Decl
void * operator new (std::size_t Size, const ASTContext &Ctx, GlobalDeclID ID, std::size_t Extra=0)
 Allocate memory for a deserialized declaration.
 
void * operator new (std::size_t Size, const ASTContext &Ctx, DeclContext *Parent, std::size_t Extra=0)
 Allocate memory for a non-deserialized declaration.
 
 Decl (Kind DK, DeclContext *DC, SourceLocation L)
 
 Decl (Kind DK, EmptyShell Empty)
 
virtual ~Decl ()
 
void updateOutOfDate (IdentifierInfo &II) const
 Update a potentially out-of-date declaration.
 
Linkage getCachedLinkage () const
 
void setCachedLinkage (Linkage L) const
 
bool hasCachedLinkage () const
 
void setModulePrivate ()
 Specify that this declaration was marked as being private to the module in which it was defined.
 
bool hasLocalOwningModuleStorage () const
 
virtual DeclgetNextRedeclarationImpl ()
 Returns the next redeclaration or itself if this is the only decl.
 
virtual DeclgetPreviousDeclImpl ()
 Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
 
virtual DeclgetMostRecentDeclImpl ()
 Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chain.
 
ASTMutationListenergetASTMutationListener () const
 
- Protected Member Functions inherited from clang::Redeclarable< VarDecl >
VarDeclgetNextRedeclaration () const
 

Protected Attributes

InitType Init
 The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
 
union {
   unsigned   AllBits
 
   VarDeclBitfields   VarDeclBits
 
   ParmVarDeclBitfields   ParmVarDeclBits
 
   NonParmVarDeclBitfields   NonParmVarDeclBits
 
}; 
 
- Protected Attributes inherited from clang::Decl
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKindNextInContextAndBits
 The next declaration within the same lexical DeclContext.
 
unsigned Access: 2
 Access - Used by C++ decls for the access specifier.
 
unsigned FromASTFile: 1
 Whether this declaration was loaded from an AST file.
 
unsigned IdentifierNamespace: 14
 IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
 
unsigned CacheValidAndLinkage: 3
 If 0, we have not computed the linkage of this declaration.
 
- Protected Attributes inherited from clang::Redeclarable< VarDecl >
DeclLink RedeclLink
 Points to the next redeclaration in the chain.
 
VarDeclFirst
 

Friends

class ASTDeclReader
 
class ASTNodeImporter
 
class StmtIteratorBase
 

Additional Inherited Members

- Static Protected Member Functions inherited from clang::Redeclarable< VarDecl >
static DeclLink PreviousDeclLink (VarDecl *D)
 
static DeclLink LatestDeclLink (const ASTContext &Ctx)
 

Detailed Description

Represents a variable declaration or definition.

Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 882 of file Decl.h.

Member Typedef Documentation

◆ InitType

using clang::VarDecl::InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>
protected

Definition at line 924 of file Decl.h.

◆ redecl_iterator

using clang::VarDecl::redecl_iterator = redeclarable_base::redecl_iterator

Definition at line 1099 of file Decl.h.

◆ redecl_range

Definition at line 1098 of file Decl.h.

◆ redeclarable_base

Definition at line 1083 of file Decl.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
NumParameterIndexBits 

Definition at line 954 of file Decl.h.

◆ anonymous enum

anonymous enum
protected
Enumerator
NumScopeDepthOrObjCQualsBits 

Definition at line 963 of file Decl.h.

◆ DefaultArgKind

Enumerator
DAK_None 
DAK_Unparsed 
DAK_Uninstantiated 
DAK_Normal 

Definition at line 956 of file Decl.h.

◆ DefinitionKind

Enumerator
DeclarationOnly 

This declaration is only a declaration.

TentativeDefinition 

This declaration is a tentative definition.

Definition 

This declaration is definitely a definition.

Definition at line 1244 of file Decl.h.

◆ InitializationStyle

Initialization styles.

Enumerator
CInit 

C-style initialization with assignment.

CallInit 

Call-style initialization (C++98)

ListInit 

Direct list-initialization (C++11)

ParenListInit 

Parenthesized list-initialization (C++20)

Definition at line 885 of file Decl.h.

◆ TLSKind

Kinds of thread-local storage.

Enumerator
TLS_None 

Not a TLS variable.

TLS_Static 

TLS with a known-constant initializer.

TLS_Dynamic 

TLS with a dynamic initializer.

Definition at line 900 of file Decl.h.

Constructor & Destructor Documentation

◆ VarDecl()

VarDecl::VarDecl ( Kind  DK,
ASTContext C,
DeclContext DC,
SourceLocation  StartLoc,
SourceLocation  IdLoc,
const IdentifierInfo Id,
QualType  T,
TypeSourceInfo TInfo,
StorageClass  SC 
)
protected

Definition at line 2123 of file Decl.cpp.

References AllBits, and VarDeclBits.

Member Function Documentation

◆ checkForConstantInitialization()

bool VarDecl::checkForConstantInitialization ( SmallVectorImpl< PartialDiagnosticAt > &  Notes) const

Evaluate the initializer of this variable to determine whether it's a constant initializer.

Should only be called once, after completing the definition of the variable.

Definition at line 2636 of file Decl.cpp.

References clang::C23, clang::CPlusPlus, ensureEvaluatedStmt(), clang::Decl::getASTContext(), getInit(), clang::Decl::getLangOpts(), clang::EvaluatedStmt::HasConstantInitialization, and clang::EvaluatedStmt::WasEvaluated.

◆ classof()

static bool clang::VarDecl::classof ( const Decl D)
inlinestatic

Definition at line 1654 of file Decl.h.

References classofKind(), and D.

◆ classofKind()

static bool clang::VarDecl::classofKind ( Kind  K)
inlinestatic

Definition at line 1655 of file Decl.h.

Referenced by classof().

◆ Create()

VarDecl * VarDecl::Create ( ASTContext C,
DeclContext DC,
SourceLocation  StartLoc,
SourceLocation  IdLoc,
const IdentifierInfo Id,
QualType  T,
TypeSourceInfo TInfo,
StorageClass  S 
)
static

◆ CreateDeserialized()

VarDecl * VarDecl::CreateDeserialized ( ASTContext C,
GlobalDeclID  ID 
)
static

Definition at line 2146 of file Decl.cpp.

References clang::C, and clang::SC_None.

◆ demoteThisDefinitionToDeclaration()

void clang::VarDecl::demoteThisDefinitionToDeclaration ( )
inline

This is a definition which should be demoted to a declaration.

In some cases (mostly module merging) we can end up with two visible definitions one of which needs to be demoted to a declaration to keep the AST invariants.

Definition at line 1430 of file Decl.h.

References isThisDeclarationADefinition(), and NonParmVarDeclBits.

Referenced by clang::Sema::checkVarDeclRedefinition().

◆ ensureEvaluatedStmt()

EvaluatedStmt * VarDecl::ensureEvaluatedStmt ( ) const

Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.

Definition at line 2529 of file Decl.cpp.

References clang::Decl::getASTContext(), Init, and clang::EvaluatedStmt::Value.

Referenced by checkForConstantInitialization(), hasICEInitializer(), clang::ASTNodeImporter::ImportInitializer(), and clang::ASTDeclReader::ReadVarDeclInit().

◆ evaluateDestruction()

bool VarDecl::evaluateDestruction ( SmallVectorImpl< PartialDiagnosticAt > &  Notes) const

Evaluate the destruction of this variable to determine if it constitutes constant destruction.

Precondition
hasConstantInitialization()
Returns
true if this variable has constant destruction, false if not.

Definition at line 16869 of file ExprConstant.cpp.

References clang::Expr::EvalStatus::Diag, EvaluateDestruction(), handleDefaultInitValue(), and clang::Expr::EvalStatus::HasSideEffects.

Referenced by clang::Sema::FinalizeVarWithDestructor().

◆ evaluateValue()

APValue * VarDecl::evaluateValue ( ) const

Attempt to evaluate the value of the initializer attached to this declaration, and produce notes explaining why it cannot be evaluated.

Returns a pointer to the value if evaluation succeeded, 0 otherwise.

Definition at line 2547 of file Decl.cpp.

References hasConstantInitialization().

Referenced by evaluateVarDeclInit(), clang::Sema::FinalizeVarWithDestructor(), and clang::CodeGen::CGCXXABI::isEmittedWithConstantInitializer().

◆ getActingDefinition() [1/2]

VarDecl * VarDecl::getActingDefinition ( )

Get the tentative definition that acts as the real definition in a TU.

Returns null if there is a proper definition available.

Definition at line 2334 of file Decl.cpp.

References Definition, clang::Redeclarable< VarDecl >::getMostRecentDecl(), clang::Decl::getPreviousDecl(), isThisDeclarationADefinition(), and TentativeDefinition.

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), getActingDefinition(), and getDefinition().

◆ getActingDefinition() [2/2]

const VarDecl * clang::VarDecl::getActingDefinition ( ) const
inline

Definition at line 1272 of file Decl.h.

References getActingDefinition().

◆ getAnyInitializer() [1/2]

const Expr * clang::VarDecl::getAnyInitializer ( ) const
inline

◆ getAnyInitializer() [2/2]

const Expr * VarDecl::getAnyInitializer ( const VarDecl *&  D) const

Get the initializer for this variable, no matter which declaration it is attached to.

Also get that declaration.

Definition at line 2377 of file Decl.cpp.

References D, and clang::Redeclarable< VarDecl >::redecls().

◆ getCanonicalDecl() [1/2]

const VarDecl * clang::VarDecl::getCanonicalDecl ( ) const
inline

Definition at line 1240 of file Decl.h.

References getCanonicalDecl().

◆ getCanonicalDecl() [2/2]

VarDecl * VarDecl::getCanonicalDecl ( )
overridevirtual

◆ getDefinition() [1/4]

VarDecl * clang::VarDecl::getDefinition ( )
inline

Definition at line 1281 of file Decl.h.

References clang::Decl::getASTContext(), and getDefinition().

Referenced by getDefinition().

◆ getDefinition() [2/4]

const VarDecl * clang::VarDecl::getDefinition ( ) const
inline

Definition at line 1284 of file Decl.h.

References getDefinition().

◆ getDefinition() [3/4]

VarDecl * VarDecl::getDefinition ( ASTContext C)

◆ getDefinition() [4/4]

const VarDecl * clang::VarDecl::getDefinition ( ASTContext C) const
inline

Definition at line 1278 of file Decl.h.

References clang::C, and getDefinition().

◆ getDescribedVarTemplate()

VarTemplateDecl * VarDecl::getDescribedVarTemplate ( ) const

Retrieves the variable template that is described by this variable declaration.

Every variable template is represented as a VarTemplateDecl and a VarDecl. The former contains template properties (such as the template parameter lists) while the latter contains the actual description of the template's contents. VarTemplateDecl::getTemplatedDecl() retrieves the VarDecl that from a VarTemplateDecl, while getDescribedVarTemplate() retrieves the VarTemplateDecl from a VarDecl.

Definition at line 2786 of file Decl.cpp.

References clang::Decl::getASTContext(), and clang::ASTContext::getTemplateOrSpecializationInfo().

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), clang::Sema::ActOnReenterTemplateScope(), clang::Sema::ActOnVariableDeclarator(), basicGVALinkageForVariable(), clang::Sema::BuildVariableInstantiation(), clang::Sema::BuildVarTemplateInstantiation(), clang::Sema::checkVarDeclRedefinition(), getTemplateInstantiationPattern(), isMainVar(), and clang::Sema::MergeVarDecl().

◆ getEvaluatedStmt()

EvaluatedStmt * VarDecl::getEvaluatedStmt ( ) const

◆ getEvaluatedValue()

APValue * VarDecl::getEvaluatedValue ( ) const

Return the already-evaluated value of this variable's initializer, or NULL if the value is not yet known.

Returns pointer to untyped APValue if the value could not be evaluated.

Definition at line 2600 of file Decl.cpp.

References clang::EvaluatedStmt::Evaluated, getEvaluatedStmt(), and clang::EvaluatedStmt::WasEvaluated.

Referenced by clang::ASTRecordWriter::AddVarDeclInit(), and evaluateVarDeclInit().

◆ getFlexibleArrayInitChars()

CharUnits VarDecl::getFlexibleArrayInitChars ( const ASTContext Ctx) const

◆ getInit() [1/2]

Expr * VarDecl::getInit ( )

Definition at line 2398 of file Decl.cpp.

References clang::Decl::getASTContext(), getEvaluatedStmt(), hasInit(), and Init.

◆ getInit() [2/2]

const Expr * clang::VarDecl::getInit ( ) const
inline

Definition at line 1319 of file Decl.h.

References getInit().

Referenced by actOnOMPReductionKindClause(), clang::SemaOpenMP::ActOnOpenMPDeclareReductionInitializerEnd(), clang::Sema::AddInitializerToDecl(), clang::ASTRecordWriter::AddVarDeclInit(), clang::Sema::BuildCXXDefaultArgExpr(), clang::Sema::BuildCXXForRangeStmt(), clang::Sema::BuildDeclaratorGroup(), clang::canVarDeclThrow(), clang::SemaCUDA::checkAllowedInitializer(), clang::Sema::CheckCXXDefaultArgExpr(), checkElementNonNil(), checkForConstantInitialization(), GlobalDeclRefChecker::declareTargetInitializer(), DiagnoseForRangeConstVariableCopies(), DiagnoseForRangeReferenceVariableCopies(), DiagnoseForRangeVariableCopies(), clang::ODRDiagsEmitter::diagnoseMismatch(), DiagnoseUninitializedUse(), EvaluateVarDecl(), clang::Sema::FinalizeDeclaration(), clang::Sema::FinalizeVarWithDestructor(), clang::ParmVarDecl::getDefaultArg(), clang::ParmVarDecl::getDefaultArgRange(), getFlexibleArrayInitChars(), getInit(), clang::Sema::getNamedReturnInfo(), clang::CXXForRangeStmt::getRangeInit(), getSelfInitExpr(), getSourceRange(), clang::OMPCapturedExprDecl::getSourceRange(), hasFlexibleArrayInit(), hasICEInitializer(), clang::ASTNodeImporter::ImportInitializer(), InitCatchParam(), clang::Sema::InstantiateVariableInitializer(), isCapturedBy(), isCapturingReferenceToHostVarInCUDADeviceLambda(), IsDecomposedVarDecl(), IsStructurallyEquivalent(), maybeRecoverWithZeroInitialization(), clang::Sema::MergeCXXFunctionDecl(), SuggestInitializationFixit(), clang::ento::ExprEngine::VisitDeclStmt(), clang::ento::ExprEngine::VisitObjCForCollectionStmt(), clang::consumed::ConsumedStmtVisitor::VisitVarDecl(), and clang::interp::Compiler< Emitter >::visitVarDecl().

◆ getInitAddress()

Stmt ** VarDecl::getInitAddress ( )

Retrieve the address of the initializer expression.

Definition at line 2411 of file Decl.cpp.

References clang::Decl::getASTContext(), and Init.

Referenced by clang::StmtIteratorBase::GetDeclExpr().

◆ getInitializingDeclaration() [1/2]

VarDecl * VarDecl::getInitializingDeclaration ( )

Get the initializing declaration of this variable, if any.

This is usually the definition, except that for a static data member it can be the in-class declaration.

Definition at line 2418 of file Decl.cpp.

References isStaticDataMember(), and clang::Redeclarable< VarDecl >::redecls().

Referenced by getInitializingDeclaration(), clang::CodeGen::CGCXXABI::isEmittedWithConstantInitializer(), and clang::Sema::mergeDeclAttributes().

◆ getInitializingDeclaration() [2/2]

const VarDecl * clang::VarDecl::getInitializingDeclaration ( ) const
inline

Definition at line 1333 of file Decl.h.

References getInitializingDeclaration().

◆ getInitStyle()

InitializationStyle clang::VarDecl::getInitStyle ( ) const
inline

The style of initialization for this declaration.

C-style initialization is "int x = 1;". Call-style initialization is a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be the expression inside the parens or a "ClassType(a,b,c)" class constructor expression for class types. List-style initialization is C++11 syntax, e.g. "int x{1};". Clients can distinguish between different forms of initialization by checking this value. In particular, "int x = {1};" is C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the Init expression in all three cases is an InitListExpr.

Definition at line 1410 of file Decl.h.

References VarDeclBits.

Referenced by actOnOMPReductionKindClause(), clang::Sema::BuildVariableInstantiation(), clang::Sema::InstantiateVariableInitializer(), isDirectInit(), and clang::JSONNodeDumper::VisitVarDecl().

◆ getInstantiatedFromStaticDataMember()

VarDecl * VarDecl::getInstantiatedFromStaticDataMember ( ) const

If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.

Definition at line 2748 of file Decl.cpp.

References getMemberSpecializationInfo().

Referenced by clang::Sema::ActOnExplicitInstantiation(), clang::Sema::AddInitializerToDecl(), adjustDeclToTemplate(), clang::Sema::CheckMemberSpecialization(), getExplicitVisibilityAux(), getTemplateInstantiationPattern(), clang::Sema::InstantiateClassMembers(), and isOutOfLine().

◆ getLanguageLinkage()

LanguageLinkage VarDecl::getLanguageLinkage ( ) const

Compute the language linkage.

Definition at line 2230 of file Decl.cpp.

References getDeclLanguageLinkage().

◆ getMemberSpecializationInfo()

MemberSpecializationInfo * VarDecl::getMemberSpecializationInfo ( ) const

◆ getMostRecentDeclImpl()

VarDecl * clang::VarDecl::getMostRecentDeclImpl ( )
inlineoverrideprotectedvirtual

Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chain.

Reimplemented from clang::Decl.

Definition at line 1093 of file Decl.h.

References clang::Redeclarable< VarDecl >::getMostRecentDecl().

◆ getNextRedeclarationImpl()

VarDecl * clang::VarDecl::getNextRedeclarationImpl ( )
inlineoverrideprotectedvirtual

Returns the next redeclaration or itself if this is the only decl.

Decl subclasses that can be redeclared should override this method so that Decl::redecl_iterator can iterate over them.

Reimplemented from clang::Decl.

Definition at line 1085 of file Decl.h.

References clang::Redeclarable< VarDecl >::getNextRedeclaration().

◆ getPointOfInstantiation()

SourceLocation VarDecl::getPointOfInstantiation ( ) const

If this variable is an instantiation of a variable template or a static data member of a class template, determine its point of instantiation.

Definition at line 2776 of file Decl.cpp.

References getMemberSpecializationInfo().

Referenced by clang::Sema::ActOnExplicitInstantiation(), DoMarkVarDeclReferenced(), and clang::Sema::InstantiateVariableDefinition().

◆ getPreviousDeclImpl()

VarDecl * clang::VarDecl::getPreviousDeclImpl ( )
inlineoverrideprotectedvirtual

Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.

Reimplemented from clang::Decl.

Definition at line 1089 of file Decl.h.

References clang::Redeclarable< VarDecl >::getPreviousDecl().

◆ getSourceRange()

SourceRange VarDecl::getSourceRange ( ) const
overridevirtual

◆ getStorageClass()

StorageClass clang::VarDecl::getStorageClass ( ) const
inline

◆ getStorageClassSpecifierString()

const char * VarDecl::getStorageClassSpecifierString ( StorageClass  SC)
static

◆ getStorageDuration()

StorageDuration clang::VarDecl::getStorageDuration ( ) const
inline

Get the storage duration of this variable, per C++ [basic.stc].

Definition at line 1180 of file Decl.h.

References getTSCSpec(), hasLocalStorage(), clang::SD_Automatic, clang::SD_Static, and clang::SD_Thread.

Referenced by clang::NamedDecl::isPlaceholderVar().

◆ getTemplateInstantiationPattern()

VarDecl * VarDecl::getTemplateInstantiationPattern ( ) const

Retrieve the variable declaration from which this variable could be instantiated, if it is an instantiation (rather than a non-template).

Definition at line 2690 of file Decl.cpp.

References getDefinitionOrSelf(), getDescribedVarTemplate(), getInstantiatedFromStaticDataMember(), getMemberSpecializationInfo(), and clang::isTemplateInstantiation().

Referenced by getDefiningModule(), and clang::Sema::InstantiateVariableDefinition().

◆ getTemplateSpecializationKind()

TemplateSpecializationKind VarDecl::getTemplateSpecializationKind ( ) const

◆ getTemplateSpecializationKindForInstantiation()

TemplateSpecializationKind VarDecl::getTemplateSpecializationKindForInstantiation ( ) const

Get the template specialization kind of this variable for the purposes of template instantiation.

This differs from getTemplateSpecializationKind() for an instantiation of a class-scope explicit specialization.

Definition at line 2766 of file Decl.cpp.

References getMemberSpecializationInfo(), and clang::TSK_Undeclared.

Referenced by clang::Sema::InstantiateVariableDefinition(), and clang::Sema::PerformPendingInstantiations().

◆ getTLSKind()

VarDecl::TLSKind VarDecl::getTLSKind ( ) const

◆ getTSCSpec()

ThreadStorageClassSpecifier clang::VarDecl::getTSCSpec ( ) const
inline

◆ hasConstantInitialization()

bool VarDecl::hasConstantInitialization ( ) const

Determine whether this variable has constant initialization.

This is only set in two cases: when the language semantics require constant initialization (globals in C and some globals in C++), and when the variable is usable in constant expressions (constexpr, const int, and reference variables in C++).

Definition at line 2620 of file Decl.cpp.

References clang::CPlusPlus, clang::Decl::getASTContext(), getEvaluatedStmt(), clang::Decl::getLangOpts(), clang::EvaluatedStmt::HasConstantInitialization, hasGlobalStorage(), and isConstexpr().

Referenced by clang::Sema::ActOnCXXExitDeclInitializer(), evaluateValue(), evaluateVarDeclInit(), hasUnsupportedSpecifiers(), clang::CodeGen::CGCXXABI::isEmittedWithConstantInitializer(), and isUsableInConstantExpressions().

◆ hasDefinition() [1/2]

DefinitionKind clang::VarDecl::hasDefinition ( ) const
inline

Definition at line 1265 of file Decl.h.

References clang::Decl::getASTContext(), and hasDefinition().

Referenced by hasDefinition(), and isKnownToBeDefined().

◆ hasDefinition() [2/2]

VarDecl::DefinitionKind VarDecl::hasDefinition ( ASTContext C) const

◆ hasDependentAlignment()

bool VarDecl::hasDependentAlignment ( ) const

Determines if this variable's alignment is dependent.

Definition at line 2682 of file Decl.cpp.

References clang::ValueDecl::getType(), clang::Type::isDependentType(), clang::Type::isUndeducedType(), and clang::T.

Referenced by clang::Sema::CheckThreadLocalForLargeAlignment(), and clang::Sema::getNamedReturnInfo().

◆ hasExternalStorage()

bool clang::VarDecl::hasExternalStorage ( ) const
inline

◆ hasFlexibleArrayInit()

bool VarDecl::hasFlexibleArrayInit ( const ASTContext Ctx) const

Whether this variable has a flexible array member initialized with one or more elements.

This can only be called for declarations where hasInit() is true.

(The standard doesn't allow initializing flexible array members; this is a gcc/msvc extension.)

Definition at line 2838 of file Decl.cpp.

References clang::Type::getAs(), clang::ASTContext::getAsConstantArrayType(), getInit(), clang::ValueDecl::getType(), clang::Expr::getType(), hasInit(), and clang::ConstantArrayType::isZeroSize().

◆ hasGlobalStorage()

bool clang::VarDecl::hasGlobalStorage ( ) const
inline

◆ hasICEInitializer()

bool VarDecl::hasICEInitializer ( const ASTContext Context) const

Determine whether the initializer of this variable is an integer constant expression.

For use in C++98, where this affects whether the variable is usable in constant expressions.

Definition at line 2608 of file Decl.cpp.

References clang::EvaluatedStmt::CheckedForICEInit, ensureEvaluatedStmt(), getInit(), clang::EvaluatedStmt::HasICEInit, and Init.

Referenced by evaluateVarDeclInit(), and isUsableInConstantExpressions().

◆ hasInit()

bool VarDecl::hasInit ( ) const

◆ hasLocalStorage()

bool clang::VarDecl::hasLocalStorage ( ) const
inline

◆ isARCPseudoStrong()

bool clang::VarDecl::isARCPseudoStrong ( ) const
inline

Determine whether this variable is an ARC pseudo-__strong variable.

A pseudo-__strong variable has a __strong-qualified type but does not actually retain the object written into it. Generally such variables are also 'const' for safety. There are 3 cases where this will be set, 1) if the variable is annotated with the objc_externally_retained attribute, 2) if its 'self' in a non-init method, or 3) if its the variable in an for-in loop.

Definition at line 1491 of file Decl.h.

References VarDeclBits.

◆ isConstexpr()

bool clang::VarDecl::isConstexpr ( ) const
inline

◆ isCXXCondDecl()

bool clang::VarDecl::isCXXCondDecl ( ) const
inline

Definition at line 1559 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::Sema::DiagnoseUnusedButSetDecl().

◆ isCXXForRangeDecl()

bool clang::VarDecl::isCXXForRangeDecl ( ) const
inline

Determine whether this variable is the for-range-declaration in a C++0x for-range statement.

Definition at line 1466 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::Sema::BuildVariableInstantiation(), and clang::Sema::InstantiateVariableInitializer().

◆ isDirectInit()

bool clang::VarDecl::isDirectInit ( ) const
inline

Whether the initializer is a direct-initializer (list or call).

Definition at line 1415 of file Decl.h.

References CInit, and getInitStyle().

Referenced by clang::SemaOpenMP::ActOnOpenMPDeclareReductionInitializerEnd(), and clang::Sema::InstantiateVariableInitializer().

◆ isEscapingByref()

bool VarDecl::isEscapingByref ( ) const

Indicates the capture is a __block variable that is captured by a block that can potentially escape (a block for which BlockDecl::doesNotEscape returns false).

Definition at line 2674 of file Decl.cpp.

References NonParmVarDeclBits.

Referenced by clang::BlockDecl::Capture::isEscapingByref(), and markEscapingByrefs().

◆ isExceptionVariable()

bool clang::VarDecl::isExceptionVariable ( ) const
inline

Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C @catch statement.

Definition at line 1438 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::Sema::getNamedReturnInfo(), and isTrackedVar().

◆ isExternC()

bool VarDecl::isExternC ( ) const

Determines whether this variable is a variable with external, C linkage.

Definition at line 2234 of file Decl.cpp.

References isDeclExternC().

Referenced by clang::Sema::ActOnVariableDeclarator(), clang::Sema::AddInitializerToDecl(), isMainVar(), and clang::NamedDecl::isReserved().

◆ isFileVarDecl()

bool clang::VarDecl::isFileVarDecl ( ) const
inline

◆ isFunctionOrMethodVarDecl()

bool clang::VarDecl::isFunctionOrMethodVarDecl ( ) const
inline

Similar to isLocalVarDecl, but excludes variables declared in blocks.

Definition at line 1218 of file Decl.h.

References clang::DeclContext::getDeclKind(), clang::Decl::getKind(), clang::Decl::getLexicalDeclContext(), clang::DeclContext::getRedeclContext(), and clang::DeclContext::isFunctionOrMethod().

◆ isInExternCContext()

bool VarDecl::isInExternCContext ( ) const

Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.

Definition at line 2238 of file Decl.cpp.

References clang::Decl::getLexicalDeclContext(), and clang::DeclContext::isExternCContext().

◆ isInExternCXXContext()

bool VarDecl::isInExternCXXContext ( ) const

Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.

Definition at line 2242 of file Decl.cpp.

References clang::Decl::getLexicalDeclContext(), and clang::DeclContext::isExternCXXContext().

◆ isInitCapture()

bool clang::VarDecl::isInitCapture ( ) const
inline

◆ isInline()

bool clang::VarDecl::isInline ( ) const
inline

◆ isInlineSpecified()

bool clang::VarDecl::isInlineSpecified ( ) const
inline

◆ isKnownToBeDefined()

bool VarDecl::isKnownToBeDefined ( ) const

◆ isLocalVarDecl()

bool clang::VarDecl::isLocalVarDecl ( ) const
inline

◆ isLocalVarDeclOrParm()

bool clang::VarDecl::isLocalVarDeclOrParm ( ) const
inline

Similar to isLocalVarDecl but also includes parameters.

Definition at line 1213 of file Decl.h.

References clang::Decl::getKind(), and isLocalVarDecl().

Referenced by DoMarkVarDeclReferenced(), hasLocalStorage(), clang::CodeGen::CodeGenFunction::OMPPrivateScope::isGlobalVarCaptured(), and clang::Sema::MergeVarDecl().

◆ isNoDestroy()

bool VarDecl::isNoDestroy ( const ASTContext Ctx) const

Is destruction of this variable entirely suppressed? If so, the variable need not have a usable destructor at all.

Definition at line 2812 of file Decl.cpp.

References clang::ASTContext::getLangOpts(), getTLSKind(), hasGlobalStorage(), and TLS_None.

Referenced by clang::Sema::FinalizeVarWithDestructor(), and needsDestruction().

◆ isNonEscapingByref()

bool VarDecl::isNonEscapingByref ( ) const

Indicates the capture is a __block variable that is never captured by an escaping block.

Definition at line 2678 of file Decl.cpp.

References NonParmVarDeclBits.

Referenced by getCaptureFieldType(), and clang::BlockDecl::Capture::isNonEscapingByref().

◆ isNRVOVariable()

bool clang::VarDecl::isNRVOVariable ( ) const
inline

Determine whether this local variable can be used with the named return value optimization (NRVO).

The named return value optimization (NRVO) works by marking certain non-volatile local variables of class type as NRVO objects. These locals can be allocated within the return slot of their containing function, in which case there is no need to copy the object to the return slot when returning from the function. Within the function body, each return that returns the NRVO object will have this variable as its NRVO candidate.

Definition at line 1456 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::JSONNodeDumper::VisitVarDecl().

◆ isObjCForDecl()

bool clang::VarDecl::isObjCForDecl ( ) const
inline

Determine whether this variable is a for-loop declaration for a for-in statement in Objective-C.

Definition at line 1476 of file Decl.h.

References NonParmVarDeclBits.

Referenced by clang::Sema::BuildVariableInstantiation(), and clang::Sema::InstantiateVariableInitializer().

◆ isOutOfLine()

bool VarDecl::isOutOfLine ( ) const
overridevirtual

◆ isParameterPack()

bool VarDecl::isParameterPack ( ) const

◆ isPreviousDeclInSameBlockScope()

bool clang::VarDecl::isPreviousDeclInSameBlockScope ( ) const
inline

Whether this local extern variable declaration's previous declaration was declared in the same block scope.

Only correct in C++.

Definition at line 1536 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::Sema::BuildVariableInstantiation(), and mergeTypeWithPrevious().

◆ isStaticDataMember()

bool clang::VarDecl::isStaticDataMember ( ) const
inline

◆ isStaticLocal()

bool clang::VarDecl::isStaticLocal ( ) const
inline

◆ isThisDeclarationADefinition() [1/2]

DefinitionKind clang::VarDecl::isThisDeclarationADefinition ( ) const
inline

◆ isThisDeclarationADefinition() [2/2]

VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition ( ASTContext C) const

◆ isThisDeclarationADemotedDefinition()

bool clang::VarDecl::isThisDeclarationADemotedDefinition ( ) const
inline

If this definition should pretend to be a declaration.

Definition at line 1420 of file Decl.h.

References false, and NonParmVarDeclBits.

Referenced by clang::Sema::AddInitializerToDecl(), and isThisDeclarationADefinition().

◆ isUsableInConstantExpressions()

bool VarDecl::isUsableInConstantExpressions ( const ASTContext C) const

◆ mightBeUsableInConstantExpressions()

bool VarDecl::mightBeUsableInConstantExpressions ( const ASTContext C) const

Determine whether this variable's value might be usable in a constant expression, according to the relevant language standard.

This only checks properties of the declaration, and does not check whether the initializer is in fact a constant expression.

This corresponds to C++20 [expr.const]p3's notion of a "potentially-constant" variable.

Definition at line 2458 of file Decl.cpp.

References clang::C, clang::ValueDecl::getType(), isConstexpr(), and clang::ValueDecl::isWeak().

Referenced by DoMarkVarDeclReferenced(), evaluateVarDeclInit(), clang::Sema::InstantiateVariableDefinition(), and isUsableInConstantExpressions().

◆ needsDestruction()

QualType::DestructionKind VarDecl::needsDestruction ( const ASTContext Ctx) const

◆ setARCPseudoStrong()

void clang::VarDecl::setARCPseudoStrong ( bool  PS)
inline

Definition at line 1492 of file Decl.h.

References VarDeclBits.

Referenced by clang::tryMakeVariablePseudoStrong().

◆ setConstexpr()

void clang::VarDecl::setConstexpr ( bool  IC)
inline

◆ setCXXCondDecl()

void clang::VarDecl::setCXXCondDecl ( )
inline

Definition at line 1563 of file Decl.h.

References NonParmVarDeclBits.

Referenced by clang::Sema::ActOnCXXConditionDeclaration().

◆ setCXXForRangeDecl()

void clang::VarDecl::setCXXForRangeDecl ( bool  FRD)
inline

◆ setDescribedVarTemplate()

void VarDecl::setDescribedVarTemplate ( VarTemplateDecl Template)

◆ setEscapingByref()

void clang::VarDecl::setEscapingByref ( )
inline

Definition at line 1555 of file Decl.h.

References NonParmVarDeclBits.

Referenced by markEscapingByrefs().

◆ setExceptionVariable()

void clang::VarDecl::setExceptionVariable ( bool  EV)
inline

◆ setImplicitlyInline()

void clang::VarDecl::setImplicitlyInline ( )
inline

◆ setInit()

void VarDecl::setInit ( Expr I)

◆ setInitCapture()

void clang::VarDecl::setInitCapture ( bool  IC)
inline

◆ setInitStyle()

void clang::VarDecl::setInitStyle ( InitializationStyle  Style)
inline

◆ setInlineSpecified()

void clang::VarDecl::setInlineSpecified ( )
inline

◆ setInstantiationOfStaticDataMember()

void VarDecl::setInstantiationOfStaticDataMember ( VarDecl VD,
TemplateSpecializationKind  TSK 
)

Specify that this variable is an instantiation of the static data member VD.

Definition at line 2911 of file Decl.cpp.

References clang::Decl::getASTContext(), and clang::ASTContext::setInstantiatedFromStaticDataMember().

Referenced by clang::Sema::BuildVariableInstantiation(), and clang::ASTNodeImporter::VisitVarDecl().

◆ setNRVOVariable()

void clang::VarDecl::setNRVOVariable ( bool  NRVO)
inline

Definition at line 1459 of file Decl.h.

References NonParmVarDeclBits.

◆ setObjCForDecl()

void clang::VarDecl::setObjCForDecl ( bool  FRD)
inline

Definition at line 1480 of file Decl.h.

References NonParmVarDeclBits.

Referenced by clang::Sema::BuildVariableInstantiation().

◆ setPreviousDeclInSameBlockScope()

void clang::VarDecl::setPreviousDeclInSameBlockScope ( bool  Same)
inline

◆ setStorageClass()

void VarDecl::setStorageClass ( StorageClass  SC)

◆ setTemplateSpecializationKind()

void VarDecl::setTemplateSpecializationKind ( TemplateSpecializationKind  TSK,
SourceLocation  PointOfInstantiation = SourceLocation() 
)

◆ setTSCSpec()

void clang::VarDecl::setTSCSpec ( ThreadStorageClassSpecifier  TSC)
inline

Friends And Related Function Documentation

◆ ASTDeclReader

friend class ASTDeclReader
friend

Definition at line 931 of file Decl.h.

◆ ASTNodeImporter

friend class ASTNodeImporter
friend

Definition at line 932 of file Decl.h.

◆ StmtIteratorBase

friend class StmtIteratorBase
friend

Definition at line 933 of file Decl.h.

Member Data Documentation

◆ 

union { ... } clang::VarDecl::@22

◆ AllBits

unsigned clang::VarDecl::AllBits

Definition at line 1073 of file Decl.h.

Referenced by VarDecl().

◆ Init

InitType clang::VarDecl::Init
mutableprotected

◆ NonParmVarDeclBits

NonParmVarDeclBitfields clang::VarDecl::NonParmVarDeclBits

◆ ParmVarDeclBits

ParmVarDeclBitfields clang::VarDecl::ParmVarDeclBits

◆ VarDeclBits

VarDeclBitfields clang::VarDecl::VarDeclBits

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