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

Member predicate NewOrNewArrayExpr::getInitializer

For operator new, this gets the call or expression that initializes the allocated object, if any.

As examples, for new int(4), this will be 4, and for new std::vector(4), this will be a call to the constructor std::vector::vector(size_t) with 4 as an argument.

For operator new[], this gets the call or expression that initializes the first element of the array, if any.

This will either be a call to the default constructor for the array’s element type (as in new std::string[10]), or a literal zero for arrays of scalars which are zero-initialized due to extra parentheses (as in new int[10]()).

At runtime, the constructor will be called once for each element in the array, but the constructor call only exists once in the AST.

Expr getInitializer()