CodeQL library for C/C++
Search

Class PreprocessorBranch

A C/C++ preprocessor branching directive: #if, #ifdef, #ifndef, or #elif.

A branching directive has a condition and that condition may be evaluated at compile-time. As a result, the preprocessor will either take the branch, or not take the branch.

However, there are also situations in which a branch’s condition isn’t evaluated. The obvious case of this is when the directive is contained within a branch which wasn’t taken. There is also a much more subtle case involving header guard branches: suitably clever compilers can notice that a branch is a header guard, and can then subsequently ignore a #include for the file being guarded. It is for this reason that wasTaken() always holds on header guard branches, but wasNotToken() rarely holds on header guard branches.

Import path

import cpp

Direct supertypes

Indirect supertypes

Known direct subtypes

Predicates

wasNotTaken

Holds if at least one translation unit evaluated this directive’s condition but then didn’t take the branch.

wasPredictable

Holds if this directive was either taken by all translation units which evaluated it, or was not taken by any translation unit which evaluated it.

wasTaken

Holds if at least one translation unit evaluated this directive’s condition and subsequently took the branch.

Inherited predicates

findRootCause

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

from Element
fromLibrary

Holds if this element may be from a library.

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
getAGuard

Gets a preprocessor branching directive whose condition affects whether this directive is performed.

from PreprocessorDirective
getAPrimaryQlClass

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

from ElementBase
getCanonicalQLClass

DEPRECATED: use getAPrimaryQlClass instead.

from ElementBase
getEnclosingElement

Gets the closest Element enclosing this one.

from Element
getEndIf

Gets the #endif directive which matches this branching directive.

from PreprocessorBranchDirective
getFile

Gets the primary file where this element occurs.

from Element
getHeadfrom PreprocessorDirective
getIf

Gets the #if, #ifdef or #ifndef directive which matches this branching directive.

from PreprocessorBranchDirective
getLocation

Gets the primary location of this element.

from PreprocessorDirective
getNext

Gets the next #elif, #else or #endif matching this branching directive.

from PreprocessorBranchDirective
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
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
toString

Gets a textual representation of this element.

from PreprocessorDirective