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 aconst T &.value: the parameter must be passed by value (Torconst 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
Flag parameters of configured types passed in the wrong way. |
- class devops.cpp.ast.checks.enforce_pass_by_type.EnforcePassByType[source]
Bases:
CheckFlag parameters of configured types passed in the wrong way.
- 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
typesis missing/malformed, a mode is unknown, orcheck_getteris 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: