CodeQL library for C/C++

Class MacroAssert

A macro assert that expands to an if statement; the head is taken to be “Assert(x, y)”, but further alternatives could be added.

Import path

import semmle.code.cpp.commons.Assertions

Direct supertypes

Indirect supertypes



Gets the expression whose truth is being asserted.

Inherited predicates


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

from Element

Holds if this element may be from a library.

from Element

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

Gets an element that is either completely in the macro expansion, or (if it is a statement) ‘almost’ in the macro expansion (for instance up to a trailing semicolon). Useful for common patterns in which macros are almost syntactically complete elements but not quite.

from MacroInvocation

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

from MacroInvocation

Gets the location of this macro access. For a nested access, where exists(this.getParentInvocation()), this yields a location either inside a #define directive or inside an argument to another macro.

from MacroAccess

Gets an element that is (partially) affected by a macro invocation. This is a superset of the set of expanded elements and includes elements that are not completely enclosed by the expansion as well.

from MacroInvocation

Gets an element that occurs in this macro invocation or a nested macro invocation.

from MacroInvocation

DEPRECATED: use getAPrimaryQlClass instead.

from ElementBase

Gets the closest Element enclosing this one.

from Element

Gets a function that includes an expression that is affected by this macro invocation. If the macro expansion includes the end of one function and the beginning of another, this predicate will get both.

from MacroInvocation

Gets the ith expanded argument of this macro invocation, where the first argument has i = 0. The result has been expanded for macros and macro parameters. If the macro definition does not use this argument, the extractor will avoid computing the expanded form for efficiency, and the result will be "".

from MacroInvocation

Gets a top-level expression associated with this macro invocation, if any. Note that this predicate will fail if the top-level expanded element is not an expression (for example if it is a statement).

from MacroInvocation

Gets the primary file where this element occurs.

from Element

Gets the location of the outermost macro access that triggered this macro access. This is equivalent to calling this.getOutermostMacroAccess().getActualLocation(). For example, the location of the invocation of C in P(C) will be the whole source range starting with P and ending with ).

from MacroAccess

Gets the macro that is being accessed.

from MacroAccess

Gets the name of the accessed macro.

from MacroAccess

Gets the outermost MacroAccess along the chain of getParentInvocation. If this has no parent, the result will be this itself.

from MacroAccess

Gets the parent macro invocation, if any. For example:

from MacroAccess

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

Gets the top-level statement associated with this macro invocation, if any. Note that this predicate will fail if the top-level expanded element is not a statement (for example if it is an expression).

from MacroInvocation

Gets the ith unexpanded argument of this macro invocation, where the first argument has i = 0. The result has been expanded for macro parameters but not for macro invocations. This means that for macro invocations not inside a #define, which can have no macro parameters in their arguments, the result is equivalent to what is in the source text, modulo whitespace.

from MacroInvocation

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

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

from Element

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

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

Gets a textual representation of this element.

from MacroAccess