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,
staticfree 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
Flag |
- class devops.cpp.ast.checks.no_void_pointer_param.NoVoidPointerParam[source]
Bases:
CheckFlag
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_INSTANTIATIONof the file is known.- 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: