devops.cpp.ast.checks.enforce_member_function_leading_underscore

Enforce a leading underscore on private and protected member functions.

Any ordinary member function (including static and template member functions) declared under a private: or protected: access specifier must have a name starting with _ (e.g. _compute, _isReady). Public member functions are never flagged, since they are part of the class’s external interface and not the concern of this check.

A handful of member-function kinds are never flagged, because their name is fixed by the language or by a base class and renaming them isn’t something the author can freely do:

  • Constructors and destructors — their name is always the class’s own name (or ~ClassName).

  • Operator overloads and conversion functions (operator==, operator[], operator int() const, …) — the operator’s spelling is fixed by the language grammar.

  • Methods that override a base class’s virtual method — the override must keep the base method’s exact name to bind at all.

As with memberLeadingUnderscore, a member function synthesized by a macro invoked on the same source line is not flagged either.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["memberFunctionLeadingUnderscore"]

Classes

EnforceMemberFunctionLeadingUnderscore()

Flag private/protected member functions without a leading underscore.

class devops.cpp.ast.checks.enforce_member_function_leading_underscore.EnforceMemberFunctionLeadingUnderscore[source]

Bases: Check

Flag private/protected member functions without a leading underscore.

Reporting is deferred to finalize() for the same reason as in EnforceMemberLeadingUnderscore: whether a candidate was synthesized by a macro can only be known once every MACRO_INSTANTIATION cursor in the file has been seen.

id: str = 'memberFunctionLeadingUnderscore'

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

visit(cursor, filename)[source]

Record macro-instantiation lines and candidate methods for filename.

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() once the whole file (including its macro instantiations) is known.

Return type:

list[Diagnostic]

finalize(filename)[source]

Emit diagnostics for buffered methods not on a macro-instantiation line.

Parameters:

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

Returns:

list[Diagnostic] – One diagnostic per offending member function whose line isn’t covered by a macro instantiation.

Return type:

list[Diagnostic]