class VarDecl

Declaration

class VarDecl : public DeclaratorDecl, public Redeclarable { /* full declaration omitted */ };

Description

Represents a variable declaration or definition.

Declared at: clang/include/clang/AST/Decl.h:874

Inherits from: DeclaratorDecl, Redeclarable

Member Variables

protected clang::VarDecl::InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
protected anonymous struct / union

Inherited from Decl:

protected NextInContextAndBits
protected Access
protected FromASTFile
protected IdentifierNamespace
protected CacheValidAndLinkage

Method Overview

Inherited from DeclaratorDecl:

Inherited from ValueDecl:

Inherited from NamedDecl:

Inherited from Decl:

Methods

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

Declared at: clang/include/clang/AST/Decl.h:1072

Parameters

clang::ASTContext& C
clang::DeclContext* DC
clang::SourceLocation StartLoc
clang::SourceLocation IdLoc
const clang::IdentifierInfo* Id
clang::QualType T
clang::TypeSourceInfo* TInfo
clang::StorageClass S

static clang::VarDecl* CreateDeserialized(
    clang::ASTContext& C,
    unsigned int ID)

Declared at: clang/include/clang/AST/Decl.h:1077

Parameters

clang::ASTContext& C
unsigned int ID

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

Declared at: clang/include/clang/AST/Decl.h:1043

Parameters

clang::Decl::Kind DK
clang::ASTContext& C
clang::DeclContext* DC
clang::SourceLocation StartLoc
clang::SourceLocation IdLoc
const clang::IdentifierInfo* Id
clang::QualType T
clang::TypeSourceInfo* TInfo
clang::StorageClass SC

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

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1357

Parameters

SmallVectorImpl<clang::PartialDiagnosticAt>& Notes

static bool classof(const clang::Decl* D)

Declared at: clang/include/clang/AST/Decl.h:1609

Parameters

const clang::Decl* D

static bool classofKind(clang::Decl::Kind K)

Declared at: clang/include/clang/AST/Decl.h:1610

Parameters

clang::Decl::Kind K

void demoteThisDefinitionToDeclaration()

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1394

clang::EvaluatedStmt* ensureEvaluatedStmt() const

Declared at: clang/include/clang/AST/Decl.h:1315

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

Description

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

Declared at: clang/include/clang/AST/Decl.h:1339

Parameters

SmallVectorImpl<clang::PartialDiagnosticAt>& Notes

Returns

\c true if this variable has constant destruction, \c false if not.

clang::APValue* evaluateValue() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1321

clang::APValue* evaluateValueImpl(
    SmallVectorImpl<clang::PartialDiagnosticAt>&
        Notes,
    bool IsConstantInitialization) const

Declared at: clang/include/clang/AST/Decl.h:1324

Parameters

SmallVectorImpl<clang::PartialDiagnosticAt>& Notes
bool IsConstantInitialization

const clang::VarDecl* getActingDefinition() const

Declared at: clang/include/clang/AST/Decl.h:1236

clang::VarDecl* getActingDefinition()

Description

Get the tentative definition that acts as the real definition in a TU. Returns null if there is a proper definition available.

Declared at: clang/include/clang/AST/Decl.h:1235

const clang::Expr* getAnyInitializer() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1273

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

Description

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

Declared at: clang/include/clang/AST/Decl.h:1280

Parameters

const clang::VarDecl*& D

const clang::VarDecl* getCanonicalDecl() const

Declared at: clang/include/clang/AST/Decl.h:1204

clang::VarDecl* getCanonicalDecl()

Description

Retrieves the "canonical" declaration of the given declaration.

Declared at: clang/include/clang/AST/Decl.h:1203

const clang::VarDecl* getDefinition() const

Declared at: clang/include/clang/AST/Decl.h:1248

clang::VarDecl* getDefinition()

Declared at: clang/include/clang/AST/Decl.h:1245

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

Declared at: clang/include/clang/AST/Decl.h:1242

Parameters

clang::ASTContext& C

clang::VarDecl* getDefinition(clang::ASTContext&)

Description

Get the real (not just tentative) definition for this declaration.

Declared at: clang/include/clang/AST/Decl.h:1241

Parameters

clang::ASTContext&

clang::VarTemplateDecl* getDescribedVarTemplate()
    const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1577

clang::EvaluatedStmt* getEvaluatedStmt() const

Declared at: clang/include/clang/AST/Decl.h:1316

clang::APValue* getEvaluatedValue() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1331

clang::CharUnits getFlexibleArrayInitChars(
    const clang::ASTContext& Ctx) const

Description

If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elements. Otherwise, returns zero. This can only be called for declarations where hasInit() is true.

Declared at: clang/include/clang/AST/Decl.h:1606

Parameters

const clang::ASTContext& Ctx

clang::Expr* getInit()

Declared at: clang/include/clang/AST/Decl.h:1286

const clang::Expr* getInit() const

Declared at: clang/include/clang/AST/Decl.h:1283

clang::Stmt** getInitAddress()

Description

Retrieve the address of the initializer expression.

Declared at: clang/include/clang/AST/Decl.h:1289

clang::VarDecl::InitializationStyle getInitStyle()
    const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1374

const clang::VarDecl* getInitializingDeclaration()
    const

Declared at: clang/include/clang/AST/Decl.h:1297

clang::VarDecl* getInitializingDeclaration()

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1296

clang::VarDecl*
getInstantiatedFromStaticDataMember() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1533

clang::LanguageLinkage getLanguageLinkage() const

Description

Compute the language linkage.

Declared at: clang/include/clang/AST/Decl.h:1150

clang::MemberSpecializationInfo*
getMemberSpecializationInfo() const

Description

If this variable is an instantiation of a static data member of a class template specialization, retrieves the member specialization information.

Declared at: clang/include/clang/AST/Decl.h:1554

clang::VarDecl* getMostRecentDeclImpl()

Description

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

Declared at: clang/include/clang/AST/Decl.h:1057

clang::VarDecl* getNextRedeclarationImpl()

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1049

clang::SourceLocation getPointOfInstantiation()
    const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1549

clang::VarDecl* getPreviousDeclImpl()

Description

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

Declared at: clang/include/clang/AST/Decl.h:1053

clang::SourceRange getSourceRange() const

Description

Source range that this declaration covers.

Declared at: clang/include/clang/AST/Decl.h:1079

clang::StorageClass getStorageClass() const

Description

Returns the storage class as written in the source. For the computed linkage of symbol, see getLinkage.

Declared at: clang/include/clang/AST/Decl.h:1083

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

Description

Return the string used to specify the storage class \p SC. It is illegal to call this function with SC == None.

Declared at: clang/include/clang/AST/Decl.h:903

Parameters

clang::StorageClass SC

clang::StorageDuration getStorageDuration() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1144

clang::VarDecl::TLSKind getTLSKind() const

Declared at: clang/include/clang/AST/Decl.h:1095

clang::ThreadStorageClassSpecifier getTSCSpec()
    const

Declared at: clang/include/clang/AST/Decl.h:1092

clang::VarDecl* getTemplateInstantiationPattern()
    const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1528

clang::TemplateSpecializationKind
getTemplateSpecializationKind() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1538

clang::TemplateSpecializationKind
getTemplateSpecializationKindForInstantiation()
    const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1544

bool hasConstantInitialization() const

Description

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++).

Declared at: clang/include/clang/AST/Decl.h:1347

clang::VarDecl::DefinitionKind hasDefinition(
    clang::ASTContext&) const

Description

Check whether this variable is defined in this translation unit.

Declared at: clang/include/clang/AST/Decl.h:1228

Parameters

clang::ASTContext&

clang::VarDecl::DefinitionKind hasDefinition()
    const

Declared at: clang/include/clang/AST/Decl.h:1229

bool hasDependentAlignment() const

Description

Determines if this variable's alignment is dependent.

Declared at: clang/include/clang/AST/Decl.h:1524

bool hasExternalStorage() const

Description

Returns true if a variable has extern or __private_extern__ storage.

Declared at: clang/include/clang/AST/Decl.h:1132

bool hasFlexibleArrayInit(
    const clang::ASTContext& Ctx) const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1600

Parameters

const clang::ASTContext& Ctx

bool hasGlobalStorage() const

Description

Returns true for all variables that do not have local storage. This includes all global variables as well as static variables declared within a function.

Declared at: clang/include/clang/AST/Decl.h:1141

bool hasICEInitializer(
    const clang::ASTContext& Context) const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1352

Parameters

const clang::ASTContext& Context

bool hasInit() const

Declared at: clang/include/clang/AST/Decl.h:1282

bool hasLocalStorage() const

Description

Returns true if a variable with function scope is a non-static local variable.

Declared at: clang/include/clang/AST/Decl.h:1099

bool isARCPseudoStrong() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1455

bool isCXXForRangeDecl() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1430

bool isConstexpr() const

Description

Whether this variable is (C++11) constexpr.

Declared at: clang/include/clang/AST/Decl.h:1477

bool isDirectInit() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1379

bool isEscapingByref() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1513

bool isExceptionVariable() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1402

bool isExternC() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1153

bool isFileVarDecl() const

Description

Returns true for file scoped variable declaration.

Declared at: clang/include/clang/AST/Decl.h:1257

bool isFunctionOrMethodVarDecl() const

Description

Similar to isLocalVarDecl, but excludes variables declared in blocks.

Declared at: clang/include/clang/AST/Decl.h:1182

bool isInExternCContext() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1157

bool isInExternCXXContext() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1161

bool isInitCapture() const

Description

Whether this variable is the implicit variable for a lambda init-capture.

Declared at: clang/include/clang/AST/Decl.h:1486

bool isInline() const

Description

Whether this variable is (C++1z) inline.

Declared at: clang/include/clang/AST/Decl.h:1459

bool isInlineSpecified() const

Declared at: clang/include/clang/AST/Decl.h:1462

bool isKnownToBeDefined() const

Declared at: clang/include/clang/AST/Decl.h:1584

bool isLocalVarDecl() const

Description

Returns true for local variable declarations other than parameters. Note that this includes static variables inside of functions. It also includes variables inside blocks. void foo() { int x; static int y; extern int z; }

Declared at: clang/include/clang/AST/Decl.h:1168

bool isLocalVarDeclOrParm() const

Description

Similar to isLocalVarDecl but also includes parameters.

Declared at: clang/include/clang/AST/Decl.h:1177

bool isNRVOVariable() const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1420

bool isNoDestroy(const clang::ASTContext&) const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1588

Parameters

const clang::ASTContext&

bool isNonEscapingByref() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1517

bool isObjCForDecl() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1440

bool isOutOfLine() const

Description

Determine whether this is or was instantiated from an out-of-line definition of a static data member.

Declared at: clang/include/clang/AST/Decl.h:1254

bool isParameterPack() const

Description

Determine whether this variable is actually a function parameter pack or init-capture pack.

Declared at: clang/include/clang/AST/Decl.h:1496

bool isPreviousDeclInSameBlockScope() const

Description

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

Declared at: clang/include/clang/AST/Decl.h:1500

bool isStaticDataMember() const

Description

Determines whether this is a static data member. This will only be true in C++, and applies to, e.g., the variable 'x' in:

Declared at: clang/include/clang/AST/Decl.h:1198

bool isStaticLocal() const

Description

Returns true if a variable with function scope is a static local variable.

Declared at: clang/include/clang/AST/Decl.h:1123

clang::VarDecl::DefinitionKind
isThisDeclarationADefinition() const

Declared at: clang/include/clang/AST/Decl.h:1223

clang::VarDecl::DefinitionKind
isThisDeclarationADefinition(
    clang::ASTContext&) const

Description

Check whether this declaration is a definition. If this could be a tentative definition (in C), don't check whether there's an overriding definition.

Declared at: clang/include/clang/AST/Decl.h:1222

Parameters

clang::ASTContext&

bool isThisDeclarationADemotedDefinition() const

Description

If this definition should pretend to be a declaration.

Declared at: clang/include/clang/AST/Decl.h:1384

bool isUsableInConstantExpressions(
    const clang::ASTContext& C) const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1313

Parameters

const clang::ASTContext& C

bool mightBeUsableInConstantExpressions(
    const clang::ASTContext& C) const

Description

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.

Declared at: clang/include/clang/AST/Decl.h:1308

Parameters

const clang::ASTContext& C

QualType::DestructionKind needsDestruction(
    const clang::ASTContext& Ctx) const

Description

Would the destruction of this variable have any effect, and if so, what kind?

Declared at: clang/include/clang/AST/Decl.h:1592

Parameters

const clang::ASTContext& Ctx

void setARCPseudoStrong(bool PS)

Declared at: clang/include/clang/AST/Decl.h:1456

Parameters

bool PS

void setCXXForRangeDecl(bool FRD)

Declared at: clang/include/clang/AST/Decl.h:1433

Parameters

bool FRD

void setConstexpr(bool IC)

Declared at: clang/include/clang/AST/Decl.h:1480

Parameters

bool IC

void setDescribedVarTemplate(
    clang::VarTemplateDecl* Template)

Declared at: clang/include/clang/AST/Decl.h:1579

Parameters

clang::VarTemplateDecl* Template

void setEscapingByref()

Declared at: clang/include/clang/AST/Decl.h:1519

void setExceptionVariable(bool EV)

Declared at: clang/include/clang/AST/Decl.h:1405

Parameters

bool EV

void setImplicitlyInline()

Declared at: clang/include/clang/AST/Decl.h:1471

void setInit(clang::Expr* I)

Declared at: clang/include/clang/AST/Decl.h:1291

Parameters

clang::Expr* I

void setInitCapture(bool IC)

Declared at: clang/include/clang/AST/Decl.h:1489

Parameters

bool IC

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

Declared at: clang/include/clang/AST/Decl.h:1360

Parameters

clang::VarDecl::InitializationStyle Style

void setInlineSpecified()

Declared at: clang/include/clang/AST/Decl.h:1466

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

Description

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

Declared at: clang/include/clang/AST/Decl.h:1563

Parameters

clang::VarDecl* VD
clang::TemplateSpecializationKind TSK

void setNRVOVariable(bool NRVO)

Declared at: clang/include/clang/AST/Decl.h:1423

Parameters

bool NRVO

void setObjCForDecl(bool FRD)

Declared at: clang/include/clang/AST/Decl.h:1444

Parameters

bool FRD

void setPreviousDeclInSameBlockScope(bool Same)

Declared at: clang/include/clang/AST/Decl.h:1505

Parameters

bool Same

void setStorageClass(clang::StorageClass SC)

Declared at: clang/include/clang/AST/Decl.h:1086

Parameters

clang::StorageClass SC

void setTSCSpec(
    clang::ThreadStorageClassSpecifier TSC)

Declared at: clang/include/clang/AST/Decl.h:1088

Parameters

clang::ThreadStorageClassSpecifier TSC

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

Description

For a static data member that was instantiated from a static data member of a class template, set the template specialiation kind.

Declared at: clang/include/clang/AST/Decl.h:1558

Parameters

clang::TemplateSpecializationKind TSK
clang::SourceLocation PointOfInstantiation = clang::SourceLocation()