devops.cpp.ast.checks.no_in_class_member_definition

Flag member functions whose body is written inside the class definition.

Member functions are declared in the class and defined outside of it (void Foo::bar() { ... }), also for classes that live only in a .cpp file. This keeps class definitions short and readable as an interface.

Flagged are in-class bodies of ordinary, static, operator and conversion member functions, constructors, destructors and member function templates, in classes, structs and unions, nested classes and class templates. Templates are flagged too: their members can still be defined after the class in the same header (or an included .tpp file).

Never flagged:

  • declarations without a body, pure virtual (= 0), = default and = delete members;

  • member functions synthesized by a macro (e.g. MSTD_ENUM or GTest’s TEST/TEST_F), detected via the macro instantiation that covers the member’s location;

  • members of local classes (declared inside a function body) and of unnamed classes, since C++ offers no way to define those outside the class;

  • in-class friend function definitions (hidden friends), which are not member functions;

  • lambdas, which are expressions rather than member functions.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["noInClassMemberDefinition"]

Classes

NoInClassMemberDefinition()

Flag member functions defined inside their class body.

class devops.cpp.ast.checks.no_in_class_member_definition.NoInClassMemberDefinition[source]

Bases: Check

Flag member functions defined inside their class body.

Reporting is deferred to finalize(): whether a member was synthesized by a macro is only known once every MACRO_INSTANTIATION cursor in the file has been seen.

id: str = 'noInClassMemberDefinition'

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

visit(cursor, filename)[source]

Record macro instantiations and in-class member definitions.

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

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

Returns:

list[Diagnostic] – Always empty; diagnostics are emitted from finalize().

Return type:

list[Diagnostic]

finalize(filename)[source]

Emit diagnostics for buffered members not produced by a macro.

Parameters:

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

Returns:

list[Diagnostic] – One diagnostic per member function defined inside its class.

Return type:

list[Diagnostic]