devops.cpp.ast.checks.no_global_using

Flag ‘using namespace’ directives and using declarations at namespace/global scope.

Any using namespace X; or using X::Y; that appears directly inside a translation unit or a named/anonymous namespace is reported as an error. Identical constructs inside a function, lambda, or class body are silently allowed because their effect is confined to that scope. using enum X; is handled by the separate noGlobalUsingEnum check.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["noGlobalUsing"]

To restrict the check to (or exempt) specific names, use the per-check table. Names are matched exactly against the qualified name as written in the source (std, std::literals, std::string); a leading :: is ignored:

[cpp.ast_check_config.noGlobalUsing]
# Only flag these names (allowlist; empty/unset means "flag everything") ...
enabled_names = ["std"]
# ... and never flag these (applied on top of enabled_names).
disabled_names = ["std::literals", "std::chrono_literals"]

To allow specific names only in certain files or directories, add one or more [[...path_exceptions]] entries. Patterns ending with / match any file under that directory; other patterns use fnmatch (* = one dir level):

[[cpp.ast_check_config.noGlobalUsing.path_exceptions]]
names = ["rad"]
paths = ["src/units/", "include/units/"]

Classes

NoGlobalUsing()

Flag using-namespace directives and using declarations at global/namespace scope.

class devops.cpp.ast.checks.no_global_using.NoGlobalUsing[source]

Bases: NameFilteredCheck

Flag using-namespace directives and using declarations at global/namespace scope.

Only using-statements whose immediate semantic parent is a translation unit or a namespace are flagged. Those inside functions, lambdas, or class bodies are ignored.

id: str = 'noGlobalUsing'

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

visit(cursor, filename)[source]

Flag the cursor if it is a global-scope using-statement.

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 the cursor is a disallowed using-statement, otherwise an empty list.

Return type:

list[Diagnostic]