devops.cpp.ast.checks.enforce_pass_by_type

Enforce how parameters of certain types are passed.

Configure the per-type rules via the project TOML file:

[cpp.ast_check_config.passByType.types] “molsys::SimulationBox” = { mode = “const_ref”, check_getter = true } “Real” = “value” “std::string_view” = { mode = “const_ref_or_value” }

mode is one of:

  • const_ref: the parameter must be a const T &.

  • value: the parameter must be passed by value (T or const T).

  • const_ref_or_value: either of the above.

Non-const references, rvalue references and pointers are always flagged. A plain string is shorthand for { mode = "<string>" }.

With check_getter = true (per type, default false) the return type of simple getters of that type (non-static, const member functions without parameters) is checked with the same mode. Other functions’ return types are never checked.

Matching uses the base type (cv-qualifiers, references and pointers stripped), exactly like paramNameForType.

Classes

EnforcePassByType()

Flag parameters of configured types passed in the wrong way.

class devops.cpp.ast.checks.enforce_pass_by_type.EnforcePassByType[source]

Bases: Check

Flag parameters of configured types passed in the wrong way.

id: str = 'passByType'

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

configure(config)[source]

Load the per-type rules from the check’s TOML config block.

Parameters:

config (dict) – Expected shape: {"types": {"TypeName": "<mode>" | {"mode": "<mode>", "check_getter": bool}, ...}}.

Raises:

ConfigError – If types is missing/malformed, a mode is unknown, or check_getter is not a boolean.

Return type:

None

visit(cursor, filename)[source]

Flag a parameter (or simple getter return) passed/returned wrongly.

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

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

Returns:

list[Diagnostic] – A single diagnostic if cursor is offending, otherwise an empty list.

Return type:

list[Diagnostic]