Skip to content

Conversation

@ostorc
Copy link

@ostorc ostorc commented Dec 6, 2025

This PR closes #170979.

@github-actions
Copy link

github-actions bot commented Dec 6, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2025

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Ondřej Štorc (ostorc)

Changes

This PR closes #170979.


Full diff: https://github.com/llvm/llvm-project/pull/170986.diff

17 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/google/CMakeLists.txt (-1)
  • (modified) clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/misc/CMakeLists.txt (+1)
  • (modified) clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp (+3)
  • (renamed) clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.cpp (+2-2)
  • (renamed) clang-tools-extra/clang-tidy/misc/UnnamedNamespaceInHeaderCheck.h (+6-6)
  • (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst (+2-2)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst (+2-2)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst (+6-9)
  • (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+4-3)
  • (added) clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst (+14)
  • (modified) clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp (-4)
  • (renamed) clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anon-namespaces.h ()
  • (added) clang-tools-extra/test/clang-tidy/checkers/misc/namespaces.cpp (+3)
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
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/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..3f89491d398db 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..9475dfba36000 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -229,7 +229,7 @@ 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:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`,
    :doc:`google-build-using-namespace <google/build-using-namespace>`,
    :doc:`google-default-arguments <google/default-arguments>`,
    :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes"
@@ -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`.
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]

@github-actions
Copy link

github-actions bot commented Dec 6, 2025

🐧 Linux x64 Test Results

  • 3054 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

…anonymous-namespace-in-header' and create new documentation for the latter
…ymous-namespace-in-header' in tests and move it to coresponding place
@ostorc ostorc force-pushed the tidy-rename-google-build-namespaces-to-misc-anonymous-namespace-in-header branch from 1e209d8 to a33d504 Compare December 6, 2025 21:23
@@ -1,7 +1,6 @@
// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the whole test file to misc and rename it "anonymous-namespace-in-header.cpp" (same as checkname)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file was also testing other checks, so maybe that was the reason for this "universal" name. Should I still change it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should move tests to misc and name it as check name.
You can leave this with little test-case as sanity check for google-build-namespaces,google-build-using-namespace (like what you did not for misc/namespaces.cpp)

ostorc and others added 2 commits December 8, 2025 08:24
Co-authored-by: mitchell <mitchell.xu2@gmail.com>
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

…spaceInHeaderCheck' and update related references
@ostorc ostorc force-pushed the tidy-rename-google-build-namespaces-to-misc-anonymous-namespace-in-header branch from 0915f3c to a83daf0 Compare December 8, 2025 08:35
@ostorc ostorc force-pushed the tidy-rename-google-build-namespaces-to-misc-anonymous-namespace-in-header branch from a83daf0 to 4adad39 Compare December 8, 2025 08:40
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
Copy link
Member

@zeyi2 zeyi2 Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other alias documentation, we use References which looks like this, so it may be a good idea to also add them here.

Suggested change
definitions of the same entity, leading to unexpected behavior or linker errors.
References
----------
https://google.github.io/styleguide/cppguide.html#Namespaces
Corresponding cpplint.py check name: `build/namespaces`.

But please wait for other reviewers to verify this :)

@zeyi2 zeyi2 requested a review from vbvictor December 8, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang-tidy] Rename 'google-build-namespaces' check to 'misc-anonymous-namespace-in-header' and keep initial as alias.

4 participants