From 559ad3e2b7c7e80d9aa0c8f6a1ce3227e06418d6 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:23:11 +0800 Subject: [PATCH] Flag Global Usings in Headers with clang-tidy (#16225) A using-directive or using-declaration in the global namespace of a header reaches every file that includes it, and a using-declaration also makes the include checker treat that header as the one to include for the name. google-global-names-in-headers reports both, on changed lines like the existing check, so headers that still have one are not held to it until the line is touched. The check does not see a using inside a namespace. clang_tidy_diff.py's closing message assumed every finding was a missing include; it now says other findings need a manual fix. --- .clang-tidy | 13 +++++++++---- scripts/clang_tidy_diff.py | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ed2378536e..ab2a1dfbd7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,10 +1,15 @@ # clang-tidy configuration, enforced by the clang-tidy CI job on the lines a pull -# request changes (scripts/clang_tidy_diff.py). Only missing includes are reported -# for now: a file should include the header for every symbol it uses, not rely on -# the precompiled header or another header's includes. Run with --fix to add them. +# request changes (scripts/clang_tidy_diff.py). Two things are reported. +# Missing includes: a file should include the header for every symbol it uses, not +# rely on the precompiled header or another header's includes. Run with --fix to +# add them. +# Using-directives and using-declarations in the global namespace of a header: +# they reach every file that includes the header, and a using-declaration also +# makes the header look like the one to include for that name. Qualify the name +# in the header, and put the using in the source files that want it. # Every check listed here gates pull requests, so enable a new one only once the # code it flags on touched lines is reasonable to fix in passing. -Checks: '-*,misc-include-cleaner' +Checks: '-*,misc-include-cleaner,google-global-names-in-headers' WarningsAsErrors: '*' CheckOptions: # Missing includes only. Builds without the precompiled header break on these. diff --git a/scripts/clang_tidy_diff.py b/scripts/clang_tidy_diff.py index 130e4661df..1e716b6baf 100644 --- a/scripts/clang_tidy_diff.py +++ b/scripts/clang_tidy_diff.py @@ -311,11 +311,12 @@ def main(): for path in fixed: print(f" {path}") if failed and fixed: - print(f"\nclang-tidy still fails on {len(failed)} file(s); the findings above are what --fix could not add.") + print(f"\nclang-tidy still fails on {len(failed)} file(s); the findings above are what --fix could not fix.") return 1 if failed: print(f"\nclang-tidy failed on {len(failed)} file(s). Add the includes it names, or apply its " - "suggestions locally with scripts/run_clang_tidy.sh --fix (scripts\\run_clang_tidy.ps1 -Fix on Windows).") + "suggestions locally with scripts/run_clang_tidy.sh --fix (scripts\\run_clang_tidy.ps1 -Fix on Windows). " + "Other findings need a manual fix.") return 1 print("clang-tidy passed.") return 0