https://github.com/ostorc updated https://github.com/llvm/llvm-project/pull/170986
From 69583481e4bb1df710dd8596ac2eea74219ba00c Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Sat, 6 Dec 2025 17:00:45 +0100 Subject: [PATCH 01/10] [clang-tidy] Rename 'google-build-namespaces' check to 'misc-anonymous-namespace-in-header' --- clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp | 4 ++-- .../clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 4 ++-- clang-tools-extra/clang-tidy/google/CMakeLists.txt | 1 - .../clang-tidy/google/GoogleTidyModule.cpp | 4 ++-- clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 1 + clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 3 +++ .../UnnamedNamespaceInHeaderCheck.cpp | 4 ++-- .../{google => misc}/UnnamedNamespaceInHeaderCheck.h | 12 ++++++------ 8 files changed, 18 insertions(+), 15 deletions(-) rename clang-tools-extra/clang-tidy/{google => misc}/UnnamedNamespaceInHeaderCheck.cpp (94%) rename clang-tools-extra/clang-tidy/{google => misc}/UnnamedNamespaceInHeaderCheck.h (74%) diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp index 16d4be9802cc6..bc570cd59450e 100644 --- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp @@ -31,12 +31,12 @@ #include "../bugprone/UnsafeFunctionsCheck.h" #include "../bugprone/UnusedReturnValueCheck.h" #include "../concurrency/ThreadCanceltypeAsynchronousCheck.h" -#include "../google/UnnamedNamespaceInHeaderCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" #include "../misc/NonCopyableObjectsCheck.h" #include "../misc/PredictableRandCheck.h" #include "../misc/StaticAssertCheck.h" #include "../misc/ThrowByValueCatchByReferenceCheck.h" +#include "../misc/UnnamedNamespaceInHeaderCheck.h" #include "../modernize/AvoidSetjmpLongjmpCheck.h" #include "../modernize/AvoidVariadicFunctionsCheck.h" #include "../performance/MoveConstructorInitCheck.h" @@ -253,7 +253,7 @@ class CERTModule : public ClangTidyModule { "cert-dcl54-cpp"); CheckFactories.registerCheck<bugprone::StdNamespaceModificationCheck>( "cert-dcl58-cpp"); - CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( "cert-dcl59-cpp"); // ERR CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index c62c43f0c42a3..20d86b6cf38ab 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -9,7 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "../google/UnnamedNamespaceInHeaderCheck.h" +#include "../misc/UnnamedNamespaceInHeaderCheck.h" #include "DefaultArgumentsCallsCheck.h" #include "DefaultArgumentsDeclarationsCheck.h" #include "MultipleInheritanceCheck.h" @@ -32,7 +32,7 @@ class FuchsiaModule : public ClangTidyModule { "fuchsia-default-arguments-calls"); CheckFactories.registerCheck<DefaultArgumentsDeclarationsCheck>( "fuchsia-default-arguments-declarations"); - CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( "fuchsia-header-anon-namespaces"); CheckFactories.registerCheck<MultipleInheritanceCheck>( "fuchsia-multiple-inheritance"); diff --git a/clang-tools-extra/clang-tidy/google/CMakeLists.txt b/clang-tools-extra/clang-tidy/google/CMakeLists.txt index 1d4229ebb7b09..4335cf4aa11f9 100644 --- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt @@ -19,7 +19,6 @@ add_clang_library(clangTidyGoogleModule STATIC IntegerTypesCheck.cpp OverloadedUnaryAndCheck.cpp TodoCommentCheck.cpp - UnnamedNamespaceInHeaderCheck.cpp UpgradeGoogletestCaseCheck.cpp UsingNamespaceDirectiveCheck.cpp diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index aff8b45ff2f74..8749cea94c899 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -9,6 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "../misc/UnnamedNamespaceInHeaderCheck.h" #include "../readability/BracesAroundStatementsCheck.h" #include "../readability/FunctionSizeCheck.h" #include "../readability/NamespaceCommentCheck.h" @@ -26,7 +27,6 @@ #include "IntegerTypesCheck.h" #include "OverloadedUnaryAndCheck.h" #include "TodoCommentCheck.h" -#include "UnnamedNamespaceInHeaderCheck.h" #include "UpgradeGoogletestCaseCheck.h" #include "UsingNamespaceDirectiveCheck.h" @@ -40,7 +40,7 @@ class GoogleModule : public ClangTidyModule { void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { CheckFactories.registerCheck<build::ExplicitMakePairCheck>( "google-build-explicit-make-pair"); - CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( "google-build-namespaces"); CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>( "google-build-using-namespace"); diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index e8705aada3f22..94cede12da4d5 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -39,6 +39,7 @@ add_clang_library(clangTidyMiscModule STATIC ThrowByValueCatchByReferenceCheck.cpp UnconventionalAssignOperatorCheck.cpp UniqueptrResetReleaseCheck.cpp + UnnamedNamespaceInHeaderCheck.cpp UnusedAliasDeclsCheck.cpp UnusedParametersCheck.cpp UnusedUsingDeclsCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 03f25775de0bf..157411e9ac36b 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -29,6 +29,7 @@ #include "ThrowByValueCatchByReferenceCheck.h" #include "UnconventionalAssignOperatorCheck.h" #include "UniqueptrResetReleaseCheck.h" +#include "UnnamedNamespaceInHeaderCheck.h" #include "UnusedAliasDeclsCheck.h" #include "UnusedParametersCheck.h" #include "UnusedUsingDeclsCheck.h" @@ -41,6 +42,8 @@ namespace misc { class MiscModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>( + "misc-anonymous-namespace-in-header"); CheckFactories.registerCheck<ConfusableIdentifierCheck>( "misc-confusable-identifiers"); CheckFactories.registerCheck<ConstCorrectnessCheck>( diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp similarity index 94% rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp rename to clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp index 054bdc8d1230e..6bba314b5d947 100644 --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp @@ -12,7 +12,7 @@ using namespace clang::ast_matchers; -namespace clang::tidy::google::build { +namespace clang::tidy::misc::build { UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck( StringRef Name, ClangTidyContext *Context) @@ -37,4 +37,4 @@ void UnnamedNamespaceInHeaderCheck::check( diag(Loc, "do not use unnamed namespaces in header files"); } -} // namespace clang::tidy::google::build +} // namespace clang::tidy::misc::build diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h similarity index 74% rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h rename to clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h index 78e8127a5a342..0225922083d0c 100644 --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H #include "../ClangTidyCheck.h" #include "../utils/FileExtensionsUtils.h" -namespace clang::tidy::google::build { +namespace clang::tidy::misc::build { /// Finds anonymous namespaces in headers. /// @@ -21,7 +21,7 @@ namespace clang::tidy::google::build { /// Corresponding cpplint.py check name: 'build/namespaces'. /// /// For the user-facing documentation see: -/// https://clang.llvm.org/extra/clang-tidy/checks/google/build-namespaces.html +/// https://clang.llvm.org/extra/clang-tidy/checks/misc/build-namespaces.html class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { public: UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); @@ -35,6 +35,6 @@ class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { FileExtensionsSet HeaderFileExtensions; }; -} // namespace clang::tidy::google::build +} // namespace clang::tidy::misc::build -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H From 84388d2da3ef1e8b0e619d33800af5ce0f9c08e5 Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Sat, 6 Dec 2025 17:10:09 +0100 Subject: [PATCH 02/10] [clang-tidy] Update references to 'google-build-namespaces' to 'misc-anonymous-namespace-in-header' and create new documentation for the latter --- .../docs/clang-tidy/checks/cert/dcl59-cpp.rst | 4 ++-- .../checks/fuchsia/header-anon-namespaces.rst | 4 ++-- .../clang-tidy/checks/google/build-namespaces.rst | 13 +++++-------- clang-tools-extra/docs/clang-tidy/checks/list.rst | 7 ++++--- .../checks/misc/anonymous-namespace-in-header.rst | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst index 027d2eca09195..ee66ec92f8478 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst @@ -1,10 +1,10 @@ .. title:: clang-tidy - cert-dcl59-cpp .. meta:: - :http-equiv=refresh: 5;URL=../google/build-namespaces.html + :http-equiv=refresh: 5;URL=../misc/anonymous-namespace-in-header.html cert-dcl59-cpp ============== The `cert-dcl59-cpp` check is an alias, please see -:doc:`google-build-namespaces <../google/build-namespaces>` +:doc:`misc-anonymous-namespace-in-header <../misc/anonymous-namespace-in-header>` for more information. diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst index a92f3f411c031..44cd73259c2fd 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst @@ -1,10 +1,10 @@ .. title:: clang-tidy - fuchsia-header-anon-namespaces .. meta:: - :http-equiv=refresh: 5;URL=../google/build-namespaces.html + :http-equiv=refresh: 5;URL=../misc/anonymous-namespace-in-header.html fuchsia-header-anon-namespaces ============================== The fuchsia-header-anon-namespaces check is an alias, please see -:doc:`google-build-namespace <../google/build-namespaces>` +:doc:`misc-anonymous-namespace-in-header <../misc/anonymous-namespace-in-header>` for more information. diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst index b421d992d63a6..26a0765221ce6 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst @@ -1,13 +1,10 @@ .. title:: clang-tidy - google-build-namespaces +.. meta:: + :http-equiv=refresh: 5;URL=../misc/anonymous-namespace-in-header.html google-build-namespaces ======================= -`cert-dcl59-cpp` redirects here as an alias for this check. -`fuchsia-header-anon-namespaces` redirects here as an alias for this check. - -Finds anonymous namespaces in headers. - -https://google.github.io/styleguide/cppguide.html#Namespaces - -Corresponding cpplint.py check name: `build/namespaces`. +The `google-build-namespaces` check is an alias, please see +:doc:`misc-anonymous-namespace-in-header <../misc/anonymous-namespace-in-header>` +for more information. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 8bb112f3d1832..295a6b07474e7 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -229,7 +229,6 @@ Clang-Tidy Checks :doc:`fuchsia-trailing-return <fuchsia/trailing-return>`, :doc:`fuchsia-virtual-inheritance <fuchsia/virtual-inheritance>`, :doc:`google-build-explicit-make-pair <google/build-explicit-make-pair>`, - :doc:`google-build-namespaces <google/build-namespaces>`, :doc:`google-build-using-namespace <google/build-using-namespace>`, :doc:`google-default-arguments <google/default-arguments>`, :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes" @@ -264,6 +263,7 @@ Clang-Tidy Checks :doc:`llvmlibc-implementation-in-namespace <llvmlibc/implementation-in-namespace>`, :doc:`llvmlibc-inline-function-decl <llvmlibc/inline-function-decl>`, "Yes" :doc:`llvmlibc-restrict-system-libc-headers <llvmlibc/restrict-system-libc-headers>`, "Yes" + :doc:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`, :doc:`misc-confusable-identifiers <misc/confusable-identifiers>`, :doc:`misc-const-correctness <misc/const-correctness>`, "Yes" :doc:`misc-coroutine-hostile-raii <misc/coroutine-hostile-raii>`, @@ -446,7 +446,7 @@ Check aliases :doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes" :doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`, :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`, :doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`, - :doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`, + :doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`, :doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`, :doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`, :doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`, @@ -583,7 +583,8 @@ Check aliases :doc:`cppcoreguidelines-noexcept-swap <cppcoreguidelines/noexcept-swap>`, :doc:`performance-noexcept-swap <performance/noexcept-swap>`, "Yes" :doc:`cppcoreguidelines-non-private-member-variables-in-classes <cppcoreguidelines/non-private-member-variables-in-classes>`, :doc:`misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes>`, :doc:`cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init>`, :doc:`modernize-use-default-member-init <modernize/use-default-member-init>`, "Yes" - :doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`google-build-namespaces <google/build-namespaces>`, + :doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`, + :doc:`google-build-namespaces <google/build-namespaces>`, :doc:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`, :doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes" :doc:`google-readability-function-size <google/readability-function-size>`, :doc:`readability-function-size <readability/function-size>`, :doc:`google-readability-namespace-comments <google/readability-namespace-comments>`, :doc:`llvm-namespace-comment <llvm/namespace-comment>`, diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst new file mode 100644 index 0000000000000..796642adc095f --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst @@ -0,0 +1,14 @@ +.. title:: clang-tidy - anonymous-namespace-in-header + +anonymous-namespace-in-header +============================= + +`cert-dcl59-cpp` redirects here as an alias for this check. +`fuchsia-header-anon-namespaces` redirects here as an alias for this check. +`google-build-namespaces` redirects here as an alias for this check. + +Finds anonymous namespaces in headers. + +https://google.github.io/styleguide/cppguide.html#Namespaces + +Corresponding cpplint.py check name: `build/namespaces`. From 07e1f950dbff7d1e16b9d9a80911cba61bd87814 Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Sat, 6 Dec 2025 17:15:36 +0100 Subject: [PATCH 03/10] [clang-tidy] Replace 'google-build-namespaces' checks with 'misc-anonymous-namespace-in-header' in tests and move it to coresponding place --- .../test/clang-tidy/checkers/google/namespaces.cpp | 4 ---- .../google-namespaces.h => misc/Inputs/anon-namespaces.h} | 0 .../test/clang-tidy/checkers/misc/namespaces.cpp | 3 +++ 3 files changed, 3 insertions(+), 4 deletions(-) rename clang-tools-extra/test/clang-tidy/checkers/{google/Inputs/google-namespaces.h => misc/Inputs/anon-namespaces.h} (100%) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp index 9bda3c0451b39..d830146fe1ff1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp @@ -1,7 +1,3 @@ -// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" -#include "Inputs/google-namespaces.h" -// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces] - using namespace spaaaace; // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/Inputs/google-namespaces.h b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anon-namespaces.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/google/Inputs/google-namespaces.h rename to clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anon-namespaces.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp new file mode 100644 index 0000000000000..d01547bfde8ce --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp @@ -0,0 +1,3 @@ +// RUN: clang-tidy %s -checks='-*,misc-anonymous-namespace-in-header,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" +#include "Inputs/anon-namespaces.h" +// CHECK: warning: do not use unnamed namespaces in header files [misc-anonymous-namespace-in-header] From a33d504c1bda6d9483fc127a6281a5698d7f16cb Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Sat, 6 Dec 2025 17:19:54 +0100 Subject: [PATCH 04/10] [clang-tidy] Update release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++ .../test/clang-tidy/checkers/google/namespaces.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 42160fa9cb51c..9d2ed11a4044a 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -328,6 +328,11 @@ New check aliases <clang-tidy/checks/bugprone/copy-constructor-mutates-argument>` keeping initial check as an alias to the new one. +- Renamed :doc:`google-build-namespaces` to + :doc:`misc-anonymous-namespace-in-header + <clang-tidy/checks/misc/anonymous-namespace-in-header>` + keeping initial check as an alias to the new one. + Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp index d830146fe1ff1..b0b278001d11d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp @@ -1,3 +1,6 @@ +// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" +#include "../misc/Inputs/anon-namespaces.h" +// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces] using namespace spaaaace; // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] From b3599aa2e76eee4e820423ebe96c93ddb0f6f266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0torc?= <[email protected]> Date: Mon, 8 Dec 2025 08:24:15 +0100 Subject: [PATCH 05/10] Update clang-tools-extra/docs/ReleaseNotes.rst Co-authored-by: mitchell <[email protected]> --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 9d2ed11a4044a..89c012630bcc0 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -328,7 +328,7 @@ New check aliases <clang-tidy/checks/bugprone/copy-constructor-mutates-argument>` keeping initial check as an alias to the new one. -- Renamed :doc:`google-build-namespaces` to +- Renamed :doc:`google-build-namespaces <clang-tidy/checks/google/build-namespaces>` to :doc:`misc-anonymous-namespace-in-header <clang-tidy/checks/misc/anonymous-namespace-in-header>` keeping initial check as an alias to the new one. From 1645a52df569ede75d77b5ea03907299735627af Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Mon, 8 Dec 2025 08:27:23 +0100 Subject: [PATCH 06/10] [clang-tidy] Refactor 'UnnamedNamespaceInHeaderCheck' namespace and update related registrations --- clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 2 +- clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp | 2 +- clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 2 +- .../clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp | 2 +- .../clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index 20d86b6cf38ab..660f0cee92ff7 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -32,7 +32,7 @@ class FuchsiaModule : public ClangTidyModule { "fuchsia-default-arguments-calls"); CheckFactories.registerCheck<DefaultArgumentsDeclarationsCheck>( "fuchsia-default-arguments-declarations"); - CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::UnnamedNamespaceInHeaderCheck>( "fuchsia-header-anon-namespaces"); CheckFactories.registerCheck<MultipleInheritanceCheck>( "fuchsia-multiple-inheritance"); diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index 8749cea94c899..173262d8e9778 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -40,7 +40,7 @@ class GoogleModule : public ClangTidyModule { void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { CheckFactories.registerCheck<build::ExplicitMakePairCheck>( "google-build-explicit-make-pair"); - CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::UnnamedNamespaceInHeaderCheck>( "google-build-namespaces"); CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>( "google-build-using-namespace"); diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 157411e9ac36b..ffcfa43564a78 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -42,7 +42,7 @@ namespace misc { class MiscModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<UnnamedNamespaceInHeaderCheck>( "misc-anonymous-namespace-in-header"); CheckFactories.registerCheck<ConfusableIdentifierCheck>( "misc-confusable-identifiers"); diff --git a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp index 6bba314b5d947..d435f7484523e 100644 --- a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp @@ -12,7 +12,7 @@ using namespace clang::ast_matchers; -namespace clang::tidy::misc::build { +namespace clang::tidy::misc { UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck( StringRef Name, ClangTidyContext *Context) diff --git a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h index 0225922083d0c..0635e22dac5c0 100644 --- a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h @@ -12,7 +12,7 @@ #include "../ClangTidyCheck.h" #include "../utils/FileExtensionsUtils.h" -namespace clang::tidy::misc::build { +namespace clang::tidy::misc { /// Finds anonymous namespaces in headers. /// @@ -21,7 +21,7 @@ namespace clang::tidy::misc::build { /// Corresponding cpplint.py check name: 'build/namespaces'. /// /// For the user-facing documentation see: -/// https://clang.llvm.org/extra/clang-tidy/checks/misc/build-namespaces.html +/// https://clang.llvm.org/extra/clang-tidy/checks/misc/anonymous-namespace-in-header.html class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { public: UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); From 3cab057bd9d9e2cff6b87fb1287d8680cb2f8c3a Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Mon, 8 Dec 2025 08:37:44 +0100 Subject: [PATCH 07/10] [clang-tidy] Rename 'UnnamedNamespaceInHeaderCheck' to 'AnonymousNamespaceInHeaderCheck' and update related references --- clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp | 4 ++-- .../clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 4 ++-- .../clang-tidy/google/GoogleTidyModule.cpp | 4 ++-- ...Check.cpp => AnonymousNamespaceInHeaderCheck.cpp} | 10 +++++----- ...aderCheck.h => AnonymousNamespaceInHeaderCheck.h} | 12 ++++++------ clang-tools-extra/clang-tidy/misc/CMakeLists.txt | 2 +- clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) rename clang-tools-extra/clang-tidy/misc/{UnnamedNamespaceInHeaderCheck.cpp => AnonymousNamespaceInHeaderCheck.cpp} (83%) rename clang-tools-extra/clang-tidy/misc/{UnnamedNamespaceInHeaderCheck.h => AnonymousNamespaceInHeaderCheck.h} (73%) diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp index bc570cd59450e..a9886e0be6741 100644 --- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp @@ -31,12 +31,12 @@ #include "../bugprone/UnsafeFunctionsCheck.h" #include "../bugprone/UnusedReturnValueCheck.h" #include "../concurrency/ThreadCanceltypeAsynchronousCheck.h" +#include "../misc/AnonymousNamespaceInHeaderCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" #include "../misc/NonCopyableObjectsCheck.h" #include "../misc/PredictableRandCheck.h" #include "../misc/StaticAssertCheck.h" #include "../misc/ThrowByValueCatchByReferenceCheck.h" -#include "../misc/UnnamedNamespaceInHeaderCheck.h" #include "../modernize/AvoidSetjmpLongjmpCheck.h" #include "../modernize/AvoidVariadicFunctionsCheck.h" #include "../performance/MoveConstructorInitCheck.h" @@ -253,7 +253,7 @@ class CERTModule : public ClangTidyModule { "cert-dcl54-cpp"); CheckFactories.registerCheck<bugprone::StdNamespaceModificationCheck>( "cert-dcl58-cpp"); - CheckFactories.registerCheck<misc::build::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::AnonymousNamespaceInHeaderCheck>( "cert-dcl59-cpp"); // ERR CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>( diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index 660f0cee92ff7..6a9478a446dd3 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -9,7 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "../misc/UnnamedNamespaceInHeaderCheck.h" +#include "../misc/AnonymousNamespaceInHeaderCheck.h" #include "DefaultArgumentsCallsCheck.h" #include "DefaultArgumentsDeclarationsCheck.h" #include "MultipleInheritanceCheck.h" @@ -32,7 +32,7 @@ class FuchsiaModule : public ClangTidyModule { "fuchsia-default-arguments-calls"); CheckFactories.registerCheck<DefaultArgumentsDeclarationsCheck>( "fuchsia-default-arguments-declarations"); - CheckFactories.registerCheck<misc::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::AnonymousNamespaceInHeaderCheck>( "fuchsia-header-anon-namespaces"); CheckFactories.registerCheck<MultipleInheritanceCheck>( "fuchsia-multiple-inheritance"); diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index 173262d8e9778..257bd36e2a381 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -9,7 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "../misc/UnnamedNamespaceInHeaderCheck.h" +#include "../misc/AnonymousNamespaceInHeaderCheck.h" #include "../readability/BracesAroundStatementsCheck.h" #include "../readability/FunctionSizeCheck.h" #include "../readability/NamespaceCommentCheck.h" @@ -40,7 +40,7 @@ class GoogleModule : public ClangTidyModule { void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { CheckFactories.registerCheck<build::ExplicitMakePairCheck>( "google-build-explicit-make-pair"); - CheckFactories.registerCheck<misc::UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<misc::AnonymousNamespaceInHeaderCheck>( "google-build-namespaces"); CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>( "google-build-using-namespace"); diff --git a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp similarity index 83% rename from clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp index d435f7484523e..ed872b538db49 100644 --- a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "UnnamedNamespaceInHeaderCheck.h" +#include "AnonymousNamespaceInHeaderCheck.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" @@ -14,18 +14,18 @@ using namespace clang::ast_matchers; namespace clang::tidy::misc { -UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck( +AnonymousNamespaceInHeaderCheck::AnonymousNamespaceInHeaderCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), HeaderFileExtensions(Context->getHeaderFileExtensions()) {} -void UnnamedNamespaceInHeaderCheck::registerMatchers( +void AnonymousNamespaceInHeaderCheck::registerMatchers( ast_matchers::MatchFinder *Finder) { Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"), this); } -void UnnamedNamespaceInHeaderCheck::check( +void AnonymousNamespaceInHeaderCheck::check( const MatchFinder::MatchResult &Result) { const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>("anonymousNamespace"); const SourceLocation Loc = N->getBeginLoc(); @@ -37,4 +37,4 @@ void UnnamedNamespaceInHeaderCheck::check( diag(Loc, "do not use unnamed namespaces in header files"); } -} // namespace clang::tidy::misc::build +} // namespace clang::tidy::misc diff --git a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h similarity index 73% rename from clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h index 0635e22dac5c0..faf4942b9d899 100644 --- a/clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H #include "../ClangTidyCheck.h" #include "../utils/FileExtensionsUtils.h" @@ -22,9 +22,9 @@ namespace clang::tidy::misc { /// /// For the user-facing documentation see: /// https://clang.llvm.org/extra/clang-tidy/checks/misc/anonymous-namespace-in-header.html -class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { +class AnonymousNamespaceInHeaderCheck : public ClangTidyCheck { public: - UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); + AnonymousNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { return LangOpts.CPlusPlus; } @@ -35,6 +35,6 @@ class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { FileExtensionsSet HeaderFileExtensions; }; -} // namespace clang::tidy::misc::build +} // namespace clang::tidy::misc -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNNAMEDNAMESPACEINHEADERCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H \ No newline at end of file diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index 94cede12da4d5..a6c3d1a266d30 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -18,6 +18,7 @@ add_custom_target(genconfusable DEPENDS Confusables.inc) set_target_properties(genconfusable PROPERTIES FOLDER "Clang Tools Extra/Sourcegenning") add_clang_library(clangTidyMiscModule STATIC + AnonymousNamespaceInHeaderCheck.cpp ConstCorrectnessCheck.cpp CoroutineHostileRAIICheck.cpp DefinitionsInHeadersCheck.cpp @@ -39,7 +40,6 @@ add_clang_library(clangTidyMiscModule STATIC ThrowByValueCatchByReferenceCheck.cpp UnconventionalAssignOperatorCheck.cpp UniqueptrResetReleaseCheck.cpp - UnnamedNamespaceInHeaderCheck.cpp UnusedAliasDeclsCheck.cpp UnusedParametersCheck.cpp UnusedUsingDeclsCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index ffcfa43564a78..201f426666b53 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -9,6 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "AnonymousNamespaceInHeaderCheck.h" #include "ConfusableIdentifierCheck.h" #include "ConstCorrectnessCheck.h" #include "CoroutineHostileRAIICheck.h" @@ -29,7 +30,6 @@ #include "ThrowByValueCatchByReferenceCheck.h" #include "UnconventionalAssignOperatorCheck.h" #include "UniqueptrResetReleaseCheck.h" -#include "UnnamedNamespaceInHeaderCheck.h" #include "UnusedAliasDeclsCheck.h" #include "UnusedParametersCheck.h" #include "UnusedUsingDeclsCheck.h" @@ -42,7 +42,7 @@ namespace misc { class MiscModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck<UnnamedNamespaceInHeaderCheck>( + CheckFactories.registerCheck<AnonymousNamespaceInHeaderCheck>( "misc-anonymous-namespace-in-header"); CheckFactories.registerCheck<ConfusableIdentifierCheck>( "misc-confusable-identifiers"); From d24585c3a987164bc3a07f35733973656c9e660e Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Mon, 8 Dec 2025 09:23:58 +0100 Subject: [PATCH 08/10] Remove unnecessary include of 'FileExtensionsUtils.h' in AnonymousNamespaceInHeaderCheck.h and add it in AnonymousNamespaceInHeaderCheck.cpp --- .../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp | 1 + .../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp index ed872b538db49..c459ba5d9f2e9 100644 --- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "AnonymousNamespaceInHeaderCheck.h" +#include "../utils/FileExtensionsUtils.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h index faf4942b9d899..3b517f8aeabee 100644 --- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h @@ -10,7 +10,6 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H #include "../ClangTidyCheck.h" -#include "../utils/FileExtensionsUtils.h" namespace clang::tidy::misc { From bf62cfde89a73d2dcc11ad1d2b3afe1de3ebdc88 Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Mon, 8 Dec 2025 09:26:45 +0100 Subject: [PATCH 09/10] [clang-tidy] Remove deprecated test file and update namespaces in related tests --- .../clang-tidy/checkers/google/namespaces.cpp | 51 ------------------- .../{anon-namespaces.h => namespaces.h} | 0 .../clang-tidy/checkers/misc/namespaces.cpp | 50 +++++++++++++++++- 3 files changed, 49 insertions(+), 52 deletions(-) delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp rename clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/{anon-namespaces.h => namespaces.h} (100%) diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp deleted file mode 100644 index b0b278001d11d..0000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" -#include "../misc/Inputs/anon-namespaces.h" -// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces] -using namespace spaaaace; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] - -using spaaaace::core; // no-warning - -namespace std { -inline namespace literals { -inline namespace chrono_literals { -} -inline namespace complex_literals { -} -inline namespace string_literals { -} -} -} - -using namespace std::chrono_literals; // no-warning -using namespace std::complex_literals; // no-warning -using namespace std::literals; // no-warning -using namespace std::literals::chrono_literals; // no-warning -using namespace std::literals::complex_literals; // no-warning -using namespace std::literals::string_literals; // no-warning -using namespace std::string_literals; // no-warning - -namespace literals {} - -using namespace literals; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] - -namespace foo { -inline namespace literals { -inline namespace bar_literals {} -} -} - -using namespace foo::literals; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] - -using namespace foo::bar_literals; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] - -using namespace foo::literals::bar_literals; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] - -namespace foo_literals {} - -using namespace foo_literals; -// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anon-namespaces.h b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/namespaces.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anon-namespaces.h rename to clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/namespaces.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp index d01547bfde8ce..7a59f4bd14ac8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp @@ -1,3 +1,51 @@ // RUN: clang-tidy %s -checks='-*,misc-anonymous-namespace-in-header,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:" -#include "Inputs/anon-namespaces.h" +#include "Inputs/namespaces.h" // CHECK: warning: do not use unnamed namespaces in header files [misc-anonymous-namespace-in-header] +using namespace spaaaace; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] + +using spaaaace::core; // no-warning + +namespace std { +inline namespace literals { +inline namespace chrono_literals { +} +inline namespace complex_literals { +} +inline namespace string_literals { +} +} +} + +using namespace std::chrono_literals; // no-warning +using namespace std::complex_literals; // no-warning +using namespace std::literals; // no-warning +using namespace std::literals::chrono_literals; // no-warning +using namespace std::literals::complex_literals; // no-warning +using namespace std::literals::string_literals; // no-warning +using namespace std::string_literals; // no-warning + +namespace literals {} + +using namespace literals; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] + +namespace foo { +inline namespace literals { +inline namespace bar_literals {} +} +} + +using namespace foo::literals; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] + +using namespace foo::bar_literals; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] + +using namespace foo::literals::bar_literals; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] + +namespace foo_literals {} + +using namespace foo_literals; +// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] From 0915f3ce09b147b3e327639a623e702cac88c333 Mon Sep 17 00:00:00 2001 From: Ondrej Storc <[email protected]> Date: Mon, 8 Dec 2025 09:26:56 +0100 Subject: [PATCH 10/10] [clang-tidy] Update documentation for google-build-namespaces and anonymous-namespace-in-header checks --- .../clang-tidy/checks/google/build-namespaces.rst | 4 ++++ .../checks/misc/anonymous-namespace-in-header.rst | 14 +++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst index 26a0765221ce6..de536efefd06c 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst @@ -5,6 +5,10 @@ google-build-namespaces ======================= +https://google.github.io/styleguide/cppguide.html#Namespaces + +Corresponding cpplint.py check name: `build/namespaces`. + The `google-build-namespaces` check is an alias, please see :doc:`misc-anonymous-namespace-in-header <../misc/anonymous-namespace-in-header>` for more information. diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst index 796642adc095f..7a0535f84de80 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst @@ -3,12 +3,8 @@ anonymous-namespace-in-header ============================= -`cert-dcl59-cpp` redirects here as an alias for this check. -`fuchsia-header-anon-namespaces` redirects here as an alias for this check. -`google-build-namespaces` redirects here as an alias for this check. - -Finds anonymous namespaces in headers. - -https://google.github.io/styleguide/cppguide.html#Namespaces - -Corresponding cpplint.py check name: `build/namespaces`. +Finds anonymous namespaces in headers. Anonymous namespaces in headers can lead to +ODR (One Definition Rule) violations, as each translation unit including the header +will have its own unique version of the entities declared within the anonymous +namespace. This can cause issues when linking, as the linker may see multiple +definitions of the same entity, leading to unexpected behavior or linker errors. \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
