devops.cpp.ast.checks.no_new_in_gtest_setup

Flag new expressions inside a GTest setup function.

A member function named SetUp, SetUpTestSuite, or SetUpTestCase — the fixture-setup hooks GTest calls by name (SetUp() before every test, the other two once per test suite) — is reported for any new expression appearing anywhere in its body. A raw pointer allocated there needs a matching manual release, and whether that release actually runs depends on a separate teardown hook firing later (see also noDeleteInGtestTeardown) — if SetUp() itself throws partway through, or a later SetUp() call in the same fixture leaks the previous allocation, the memory is never freed. Prefer std::unique_ptr/std::shared_ptr (or another RAII owner) so the allocation’s lifetime is tied to the fixture object itself rather than to a hook running at the right time.

Only a literal new expression lexically inside the setup function’s own body is flagged — a call to some other function that itself allocates is not traced into.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["noNewInGtestSetup"]

Classes

NoNewInGtestSetup()

Flag new expressions inside a GTest setup function.

class devops.cpp.ast.checks.no_new_in_gtest_setup.NoNewInGtestSetup[source]

Bases: Check

Flag new expressions inside a GTest setup function.

id: str = 'noNewInGtestSetup'

unique id, used as the cppcheck-style [id] suffix

visit(cursor, filename)[source]

Flag any new-expression inside a GTest setup function body.

Parameters:
  • cursor (clang.Cursor) – The AST node currently being visited.

  • filename (str) – Path of the file being checked.

Returns:

list[Diagnostic] – One diagnostic per new expression found inside cursor’s body, if cursor is a GTest setup function; otherwise an empty list.

Return type:

list[Diagnostic]