CodeQL library for C/C++
codeql/cpp-all 2.1.1 (changelog, source)
Search

Class Variable

A C/C++ variable. For example, in the following code there are four variables, a, b, c and d:

extern int a;
int a;

void myFunction(int b) {
  int c;
}

namespace N {
  extern int d;
  int d = 1;
}

For local variables, there is a one-to-one correspondence between Variable and VariableDeclarationEntry.

For other types of variable, there is a one-to-many relationship between Variable and VariableDeclarationEntry. For example, a Parameter can have multiple declarations.

Import path

import cpp

Direct supertypes

Indirect supertypes

Known direct subtypes

Predicates

declaredUsingAutoType

Holds if the type of this variable is declared using the C++ auto keyword.

getADeclarationEntry

Gets a declaration entry corresponding to this declaration. See the comment above this class for an explanation of the relationship between Declaration and DeclarationEntry.

getADeclarationLocation

Gets the location of a declaration entry corresponding to this declaration.

getAPrimaryQlClass

Gets the name of a primary CodeQL class to which this element belongs.

getASpecifier

Gets a specifier of this variable. This includes extern, static, auto, private, protected, public. Specifiers of the type of this variable, such as const and volatile, are instead accessed through this.getType().getASpecifier().

getAnAccess

Gets an access to this variable.

getAnAssignedValue

Gets an expression that is assigned to this variable somewhere in the program.

getAnAssignment

Gets an assignment expression that assigns to this variable. For example: x=... or x+=....

getAnAttribute

Gets an attribute of this variable.

getDefinition

Gets the declaration entry corresponding to this declaration that is a definition, if any.

getDefinitionLocation

Gets the location of the definition, if any.

getInitializer

Gets the initializer of this variable, if any.

getLocation

Gets the preferred location of this declaration, if any.

getName

Gets the name of this variable.

getType

Gets the type of this variable.

getTypeWithAuto

Gets the type of this variable prior to deduction caused by the C++11 auto keyword.

getUnderlyingType

Gets the type of this variable, after typedefs have been resolved.

getUnspecifiedType

Gets the type of this variable, after specifiers have been deeply stripped and typedefs have been resolved.

hasInitializer

Holds if this variable has an initializer.

isCompilerGenerated

Holds if this is a compiler-generated variable. For example, a range-based for loop typically has three compiler-generated variables, named __range, __begin, and __end:

isConst

Holds if this variable is const.

isConstexpr

Holds if this variable is constexpr.

isConstinit

Holds if this variable is declared constinit.

isConstructedFrom

Holds if this variable is constructed from v as a result of template instantiation. If so, it originates either from a template variable or from a variable nested in a template class.

isStructuredBinding

Holds if this variable is declared as part of a structured binding declaration. For example, x in auto [x, y] = ....

isThreadLocal

Holds if this variable is thread_local.

isVolatile

Holds if this variable is volatile.

Inherited predicates

findRootCause

Gets the source of this element: either itself or a macro that expanded to this element.

from Element
fromSource

Holds if this element may be from source. This predicate holds for all elements, except for those in the dummy file, whose name is the empty string. The dummy file contains declarations that are built directly into the compiler.

from Element
getAFile

Gets a file where this element occurs.

from Declaration
getATemplateArgument

Gets a template argument used to instantiate this declaration from a template. When called on a template, this will return a template parameter type for both typed and non-typed parameters.

from Declaration
getATemplateArgumentKind

Gets a template argument used to instantiate this declaration from a template. When called on a template, this will return a non-typed template parameter value.

from Declaration
getDeclaringType

Gets the class where this member is declared, if it is a member. For templates, both the template itself and all instantiations of the template are considered to have the same declaring class.

from Declaration
getDescription

Gets a description of this Declaration for display purposes.

from Declaration
getEnclosingElement

Gets the closest Element enclosing this one.

from Element
getFile

Gets the primary file where this element occurs.

from Element
getNamespace

Gets the innermost namespace which contains this declaration.

from Declaration
getNumberOfTemplateArguments

Gets the number of template arguments for this declaration.

from Declaration
getParentScope

Gets the parent scope of this Element, if any. A scope is a Type (Class / Enum), a Namespace, a BlockStmt, a Function, or certain kinds of Statement.

from Element
getPrimaryQlClasses

Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.

from ElementBase
getQualifiedName

Gets the name of the declaration, fully qualified with its namespace and declaring type.

from Declaration
getTemplateArgument

Gets the ith template argument used to instantiate this declaration from a template.

from Declaration
getTemplateArgumentKind

Gets the ith template argument value used to instantiate this declaration from a template. When called on a template, this will return the ith template parameter value if it exists.

from Declaration
hasDeclaringType

Holds if this declaration is a member of a class/struct/union.

from Declaration
hasDefinition

Holds if the declaration has a definition.

from Declaration
hasGlobalName

Holds if this declaration has the given name in the global namespace.

from Declaration
hasGlobalOrStdName

Holds if this declaration has the given name in the global namespace or the std namespace.

from Declaration
hasGlobalOrStdOrBslName

Holds if this declaration has the given name in the global namespace, the std namespace or the bsl namespace. We treat std and bsl as the same in some of our models.

from Declaration
hasName

Holds if this declaration has the given name.

from Declaration
hasQualifiedName

Holds if this declaration has a fully-qualified name with a name-space component of namespaceQualifier, no declaring type, and a base name of baseName.

from Declaration
hasQualifiedName

Holds if this declaration has a fully-qualified name with a name-space component of namespaceQualifier, a declaring type of typeQualifier, and a base name of baseName. Template parameters and arguments are stripped from all components. Missing components are "".

from Declaration
hasSpecifier

Holds if this declaration has a specifier with the given name.

from Declaration
isAffectedByMacro

Holds if this element is affected in any way by a macro. All elements that are totally or partially generated by a macro are included, so this is a super-set of isInMacroExpansion.

from Element
isFromTemplateInstantiation

Holds if this Element is a part of a template instantiation (but not the template itself).

from Element
isFromUninstantiatedTemplate

Holds if this Element is part of a template template (not if it is part of an instantiation of template). This means it is represented in the database purely as syntax and without guarantees on the presence or correctness of type-based operations such as implicit conversions.

from Element
isInMacroExpansion

Holds if this element comes from a macro expansion. Only elements that are entirely generated by a macro are included - for elements that partially come from a macro, see isAffectedByMacro.

from Element
isMember

Holds if this declaration is a member of a class/struct/union.

from Declaration
isStatic

Holds if this declaration is static.

from Declaration
isTopLevel

Holds if this declaration is a top-level declaration.

from Declaration
toString

Gets a textual representation of this element.

from Declaration

Charpred