devops.cpp.ast.checks.no_void_pointer_param

Forbid void * parameters in public and protected functions.

A function that is reachable from other translation units or other classes should offer a typed API: a void * (or const void *, void **, …) parameter erases the type and moves every mistake from compile time to run time. Any parameter whose type is a pointer to void at any pointer level (after resolving typedefs and aliases, and also through a reference such as void *&) is flagged on

  • free functions and function templates with external linkage,

  • public and protected member functions, member function templates and constructors.

Not flagged, because they are not part of a public API or their signature is fixed elsewhere:

  • private member functions, static free functions and anything in an anonymous namespace or a local class (these may wrap C APIs),

  • extern "C" declarations,

  • deleted functions (= delete, commonly used to reject conversions),

  • methods overriding a base-class virtual method,

  • function pointer parameters (e.g. void (*cb)(void *)) and parameters of a dependent template type,

  • functions and parameters whose name comes from a macro expansion (e.g. generated test bodies).

Out-of-line definitions are only reported at their first declaration, so a method declared in a header and defined in a .cpp file is reported once.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["noVoidPointerParam"]

Classes

NoVoidPointerParam()

Flag void * parameters of public and protected functions.

class devops.cpp.ast.checks.no_void_pointer_param.NoVoidPointerParam[source]

Bases: Check

Flag void * parameters of public and protected functions.

Reporting is deferred to finalize() so that functions and parameters whose name comes from a macro expansion can be skipped once every MACRO_INSTANTIATION of the file is known.

id: str = 'noVoidPointerParam'

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

visit(cursor, filename)[source]

Record macro expansions and void * parameters of cursor.

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 parameters not named by a macro.

Parameters:

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

Returns:

list[Diagnostic] – One diagnostic per offending parameter.

Return type:

list[Diagnostic]