[clang-tools-extra] [clang-tidy] Rename google-build-namespaces to misc-anonymous-namespace-in-header (PR #173484)
Manthan Singla via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 25 23:43:51 PST 2025
https://github.com/ThanSin02426 updated https://github.com/llvm/llvm-project/pull/173484
>From 722364c767e04ae6d06894f3ac827f95bebb0195 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Wed, 17 Dec 2025 14:23:54 +0530
Subject: [PATCH 01/12] [clang-tidy] Rename google-build-namespaces to
misc-anonymous-namespace-in-header
Renames the google-build-namespaces check to misc-anonymous-namespace-in-header to make it a general check applicable to non-Google projects.
The old check name is kept as an alias to prevent breaking existing users.
Fixes #170979
---
.../clang-tidy/cert/CERTTidyModule.cpp | 4 +--
.../clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 4 +--
.../clang-tidy/google/CMakeLists.txt | 1 -
.../clang-tidy/google/GoogleTidyModule.cpp | 5 ++--
.../AnonymousNamespaceInHeaderCheck.cpp} | 12 ++++-----
.../AnonymousNamespaceInHeaderCheck.h} | 10 +++----
.../clang-tidy/misc/CMakeLists.txt | 1 +
.../clang-tidy/misc/MiscTidyModule.cpp | 3 +++
clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++
.../checks/google/build-namespaces.rst | 13 ----------
.../docs/clang-tidy/checks/list.rst | 26 +++++++++----------
.../misc/anonymous-namespace-in-header.rst | 14 ++++++++++
.../checkers/misc/Inputs/google-namespaces.h | 7 +++++
.../anonymous-namespace-in-header.cpp} | 6 ++---
14 files changed, 62 insertions(+), 49 deletions(-)
rename clang-tools-extra/clang-tidy/{google/UnnamedNamespaceInHeaderCheck.cpp => misc/AnonymousNamespaceInHeaderCheck.cpp} (80%)
rename clang-tools-extra/clang-tidy/{google/UnnamedNamespaceInHeaderCheck.h => misc/AnonymousNamespaceInHeaderCheck.h} (80%)
delete mode 100644 clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h
rename clang-tools-extra/test/clang-tidy/checkers/{google/namespaces.cpp => misc/anonymous-namespace-in-header.cpp} (89%)
diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
index 16d4be9802cc6..a9886e0be6741 100644
--- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
@@ -31,7 +31,7 @@
#include "../bugprone/UnsafeFunctionsCheck.h"
#include "../bugprone/UnusedReturnValueCheck.h"
#include "../concurrency/ThreadCanceltypeAsynchronousCheck.h"
-#include "../google/UnnamedNamespaceInHeaderCheck.h"
+#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../misc/NewDeleteOverloadsCheck.h"
#include "../misc/NonCopyableObjectsCheck.h"
#include "../misc/PredictableRandCheck.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::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 284f72a8f20fd..b1b3b3fea56fe 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/AnonymousNamespaceInHeaderCheck.h"
#include "../misc/MultipleInheritanceCheck.h"
#include "DefaultArgumentsCallsCheck.h"
#include "DefaultArgumentsDeclarationsCheck.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::AnonymousNamespaceInHeaderCheck>(
"fuchsia-header-anon-namespaces");
CheckFactories.registerCheck<misc::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 982a188e8e808..2441bcd8e9c3d 100644
--- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt
@@ -18,7 +18,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 ce46b3f641790..6e90903507af6 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-
+#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
@@ -26,7 +26,6 @@
#include "IntegerTypesCheck.h"
#include "OverloadedUnaryAndCheck.h"
#include "TodoCommentCheck.h"
-#include "UnnamedNamespaceInHeaderCheck.h"
#include "UpgradeGoogletestCaseCheck.h"
#include "UsingNamespaceDirectiveCheck.h"
@@ -40,7 +39,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::AnonymousNamespaceInHeaderCheck>(
"google-build-namespaces");
CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>(
"google-build-using-namespace");
diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
similarity index 80%
rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
index 054bdc8d1230e..ed872b538db49 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
@@ -6,26 +6,26 @@
//
//===----------------------------------------------------------------------===//
-#include "UnnamedNamespaceInHeaderCheck.h"
+#include "AnonymousNamespaceInHeaderCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::google::build {
+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::google::build
+} // namespace clang::tidy::misc
diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
similarity index 80%
rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
index 78e8127a5a342..86d99df301404 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.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_ANONYMOUSNAMESPACEINHEADERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/FileExtensionsUtils.h"
-namespace clang::tidy::google::build {
+namespace clang::tidy::misc {
/// Finds anonymous namespaces in headers.
///
@@ -22,9 +22,9 @@ namespace clang::tidy::google::build {
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/google/build-namespaces.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;
}
diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 86643eb28d65a..e34b0cf687be3 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
diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index 36e545e06bb6d..14974783b0c5a 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"
@@ -42,6 +43,8 @@ namespace misc {
class MiscModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+ CheckFactories.registerCheck<AnonymousNamespaceInHeaderCheck>(
+ "misc-anonymous-namespace-in-header");
CheckFactories.registerCheck<ConfusableIdentifierCheck>(
"misc-confusable-identifiers");
CheckFactories.registerCheck<ConstCorrectnessCheck>(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 924b2c03cfd18..60811254fb49c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -255,6 +255,11 @@ New checks
Finds calls to STL library iterator algorithms that could be replaced with
LLVM range-based algorithms from ``llvm/ADT/STLExtras.h``.
+- New :doc:`misc-anonymous-namespace-in-header
+ <clang-tidy/checks/misc/anonymous-namespace-in-header>` check.
+
+ FIXME: Write a short description.
+
- New :doc:`misc-override-with-different-visibility
<clang-tidy/checks/misc/override-with-different-visibility>` check.
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
deleted file mode 100644
index b421d992d63a6..0000000000000
--- a/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
+++ /dev/null
@@ -1,13 +0,0 @@
-.. title:: clang-tidy - google-build-namespaces
-
-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`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index e5e77b5cc418b..65dabafe90a19 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@ Clang-Tidy Checks
:doc:`abseil-string-find-str-contains <abseil/string-find-str-contains>`, "Yes"
:doc:`abseil-time-comparison <abseil/time-comparison>`, "Yes"
:doc:`abseil-time-subtraction <abseil/time-subtraction>`, "Yes"
+ :doc:`abseil-unchecked-statusor-access <abseil/unchecked-statusor-access>`,
:doc:`abseil-upgrade-duration-conversions <abseil/upgrade-duration-conversions>`, "Yes"
:doc:`altera-id-dependent-backward-branch <altera/id-dependent-backward-branch>`,
:doc:`altera-kernel-name-restriction <altera/kernel-name-restriction>`,
@@ -180,11 +181,12 @@ Clang-Tidy Checks
:doc:`bugprone-unused-return-value <bugprone/unused-return-value>`,
:doc:`bugprone-use-after-move <bugprone/use-after-move>`,
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
+ :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
+ :doc:`cert-env33-c <cert/env33-c>`,
:doc:`cert-err33-c <cert/err33-c>`,
- :doc:`cert-err60-cpp <cert/err60-cpp>`,
+ :doc:`cert-err52-cpp <cert/err52-cpp>`,
:doc:`cert-flp30-c <cert/flp30-c>`,
- :doc:`cert-msc50-cpp <cert/msc50-cpp>`,
- :doc:`cert-oop58-cpp <cert/oop58-cpp>`,
+ :doc:`cert-mem57-cpp <cert/mem57-cpp>`,
:doc:`concurrency-mt-unsafe <concurrency/mt-unsafe>`,
:doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
:doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines <cppcoreguidelines/avoid-capturing-lambda-coroutines>`,
@@ -222,6 +224,7 @@ Clang-Tidy Checks
:doc:`darwin-dispatch-once-nonstatic <darwin/dispatch-once-nonstatic>`, "Yes"
:doc:`fuchsia-default-arguments-calls <fuchsia/default-arguments-calls>`,
:doc:`fuchsia-default-arguments-declarations <fuchsia/default-arguments-declarations>`, "Yes"
+ :doc:`fuchsia-multiple-inheritance <fuchsia/multiple-inheritance>`,
:doc:`fuchsia-overloaded-operator <fuchsia/overloaded-operator>`,
:doc:`fuchsia-statically-constructed-objects <fuchsia/statically-constructed-objects>`,
:doc:`fuchsia-temporary-objects <fuchsia/temporary-objects>`,
@@ -238,6 +241,7 @@ Clang-Tidy Checks
:doc:`google-objc-function-naming <google/objc-function-naming>`,
:doc:`google-objc-global-variable-declaration <google/objc-global-variable-declaration>`,
:doc:`google-readability-avoid-underscore-in-googletest-name <google/readability-avoid-underscore-in-googletest-name>`,
+ :doc:`google-readability-casting <google/readability-casting>`,
:doc:`google-readability-todo <google/readability-todo>`,
:doc:`google-runtime-float <google/runtime-float>`,
:doc:`google-runtime-int <google/runtime-int>`,
@@ -262,6 +266,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>`, "Yes"
:doc:`misc-confusable-identifiers <misc/confusable-identifiers>`,
:doc:`misc-const-correctness <misc/const-correctness>`, "Yes"
:doc:`misc-coroutine-hostile-raii <misc/coroutine-hostile-raii>`,
@@ -290,7 +295,7 @@ Clang-Tidy Checks
:doc:`misc-use-internal-linkage <misc/use-internal-linkage>`, "Yes"
:doc:`modernize-avoid-bind <modernize/avoid-bind>`, "Yes"
:doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
- :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
+ :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`, "Yes"
:doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`modernize-concat-nested-namespaces <modernize/concat-nested-namespaces>`, "Yes"
@@ -376,7 +381,7 @@ Clang-Tidy Checks
:doc:`readability-avoid-nested-conditional-operator <readability/avoid-nested-conditional-operator>`,
:doc:`readability-avoid-return-with-void-value <readability/avoid-return-with-void-value>`, "Yes"
:doc:`readability-avoid-unconditional-preprocessor-if <readability/avoid-unconditional-preprocessor-if>`,
- :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
+ :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
:doc:`readability-const-return-type <readability/const-return-type>`, "Yes"
:doc:`readability-container-contains <readability/container-contains>`, "Yes"
:doc:`readability-container-data-pointer <readability/container-data-pointer>`, "Yes"
@@ -445,21 +450,16 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
: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-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>`,
- :doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
- :doc:`cert-flp30-c <cert/flp30-c>`, :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`cert-flp37-c <cert/flp37-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
- :doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
:doc:`cert-msc24-c <cert/msc24-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
:doc:`cert-msc30-c <cert/msc30-c>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
:doc:`cert-msc32-c <cert/msc32-c>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
@@ -584,14 +584,12 @@ Check aliases
: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-multiple-inheritance <fuchsia/multiple-inheritance>`, :doc:`misc-multiple-inheritance <misc/multiple-inheritance>`,
- :doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
- :doc:`google-readability-casting <google/readability-casting>`, :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
+ :doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
: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>`,
:doc:`hicpp-avoid-c-arrays <hicpp/avoid-c-arrays>`, :doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
:doc:`hicpp-avoid-goto <hicpp/avoid-goto>`, :doc:`cppcoreguidelines-avoid-goto <cppcoreguidelines/avoid-goto>`,
- :doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
+ :doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
:doc:`hicpp-deprecated-headers <hicpp/deprecated-headers>`, :doc:`modernize-deprecated-headers <modernize/deprecated-headers>`, "Yes"
:doc:`hicpp-explicit-conversions <hicpp/explicit-conversions>`, :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes"
:doc:`hicpp-function-size <hicpp/function-size>`, :doc:`readability-function-size <readability/function-size>`,
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..3906fcd5d1925
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - misc-anonymous-namespace-in-header
+
+misc-anonymous-namespace-in-header
+==================================
+
+`google-build-namespaces` redirects here as an alias for this check.
+`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`.
\ No newline at end of file
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h
new file mode 100644
index 0000000000000..f4d87f5bc9511
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h
@@ -0,0 +1,7 @@
+namespace {
+int x;
+}
+
+namespace spaaaace {
+class core;
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
similarity index 89%
rename from clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp
rename to clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
index 9bda3c0451b39..d47e26036119e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
@@ -1,6 +1,6 @@
-// RUN: clang-tidy %s -checks='-*,google-build-namespaces,google-build-using-namespace' -header-filter='.*' -- | FileCheck %s -implicit-check-not="{{warning|error}}:"
+// 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/google-namespaces.h"
-// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces]
+// 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]
@@ -49,4 +49,4 @@ using namespace foo::literals::bar_literals;
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]
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
\ No newline at end of file
>From 21d21f28be3224694870031cda3e6864cd842e2c Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Thu, 18 Dec 2025 14:43:46 +0530
Subject: [PATCH 02/12] Fix header guards, namespace comments, and include
order
---
clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp | 2 +-
.../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h | 4 ++--
clang-tools-extra/docs/clang-tidy/checks/list.rst | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index 6e90903507af6..68554da855633 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
+#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../modernize/AvoidCStyleCastCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/FunctionSizeCheck.h"
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
index 86d99df301404..8e26fb043d631 100644
--- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
@@ -35,6 +35,6 @@ class AnonymousNamespaceInHeaderCheck : public ClangTidyCheck {
FileExtensionsSet HeaderFileExtensions;
};
-} // namespace clang::tidy::google::build
+} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H
\ No newline at end of file
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 65dabafe90a19..8b199cb80c6f9 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -231,7 +231,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"
@@ -450,7 +449,7 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
: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-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-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>`,
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
@@ -583,7 +582,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>`,
: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>`,
>From 3ee503231e7f4400ec1b45c0823c140c8e55a351 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Thu, 18 Dec 2025 15:09:05 +0530
Subject: [PATCH 03/12] Apply clang-format fixes
---
.../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
index 8e26fb043d631..8a11a5833a416 100644
--- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
@@ -37,4 +37,4 @@ class AnonymousNamespaceInHeaderCheck : public ClangTidyCheck {
} // namespace clang::tidy::misc
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H
\ No newline at end of file
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_ANONYMOUSNAMESPACEINHEADERCHECK_H
>From ad131edce577099fbef3c0e1b94715dd96c3c4b6 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Fri, 19 Dec 2025 21:57:16 +0530
Subject: [PATCH 04/12] Docs: Update style and add rationale for anonymous
namespaces
---
clang-tools-extra/docs/ReleaseNotes.rst | 2 --
.../checks/google/build-namespaces.rst | 8 ++++++++
.../docs/clang-tidy/checks/list.rst | 1 -
.../misc/anonymous-namespace-in-header.rst | 16 +++++++++++-----
4 files changed, 19 insertions(+), 8 deletions(-)
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 60811254fb49c..ef4b70c1cf71a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -255,8 +255,6 @@ New checks
Finds calls to STL library iterator algorithms that could be replaced with
LLVM range-based algorithms from ``llvm/ADT/STLExtras.h``.
-- New :doc:`misc-anonymous-namespace-in-header
- <clang-tidy/checks/misc/anonymous-namespace-in-header>` check.
FIXME: Write a short description.
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
new file mode 100644
index 0000000000000..9b8c350083331
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - google-build-namespaces
+
+google-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.
\ No newline at end of file
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 8b199cb80c6f9..6f0a523933408 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -54,7 +54,6 @@ Clang-Tidy Checks
:doc:`abseil-string-find-str-contains <abseil/string-find-str-contains>`, "Yes"
:doc:`abseil-time-comparison <abseil/time-comparison>`, "Yes"
:doc:`abseil-time-subtraction <abseil/time-subtraction>`, "Yes"
- :doc:`abseil-unchecked-statusor-access <abseil/unchecked-statusor-access>`,
:doc:`abseil-upgrade-duration-conversions <abseil/upgrade-duration-conversions>`, "Yes"
:doc:`altera-id-dependent-backward-branch <altera/id-dependent-backward-branch>`,
:doc:`altera-kernel-name-restriction <altera/kernel-name-restriction>`,
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 3906fcd5d1925..f2017ef7004eb 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,18 @@
misc-anonymous-namespace-in-header
==================================
-`google-build-namespaces` redirects here as an alias for this check.
-`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
+Anonymous namespaces in headers can lead to One Definition Rule (ODR) violations
+because each translation unit including the header will get its own unique version
+of the symbols. This increases binary size and can cause confusing link-time errors.
+
+References
+----------
+
+.. bullet list of aliases or simply the text as requested by the specific style guide
+This check corresponds to the CERT C++ Coding Standard rule
+`DCL59-CPP. Do not define an unnamed namespace in a header file
+<https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL59-CPP.+Do+not+define+an+unnamed+namespace+in+a+header+file>`_.
Corresponding cpplint.py check name: `build/namespaces`.
\ No newline at end of file
>From 93c1aff724f144ed7b95a5a7956d0e2896e6695e Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Fri, 19 Dec 2025 22:16:17 +0530
Subject: [PATCH 05/12] Docs: Remove placeholder text and update ReleaseNotes
description
---
clang-tools-extra/docs/ReleaseNotes.rst | 2 --
.../clang-tidy/checks/misc/anonymous-namespace-in-header.rst | 1 -
2 files changed, 3 deletions(-)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index ef4b70c1cf71a..73c0ff770d659 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -256,8 +256,6 @@ New checks
LLVM range-based algorithms from ``llvm/ADT/STLExtras.h``.
- FIXME: Write a short description.
-
- New :doc:`misc-override-with-different-visibility
<clang-tidy/checks/misc/override-with-different-visibility>` check.
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 f2017ef7004eb..2ecee316a99e1 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
@@ -12,7 +12,6 @@ of the symbols. This increases binary size and can cause confusing link-time err
References
----------
-.. bullet list of aliases or simply the text as requested by the specific style guide
This check corresponds to the CERT C++ Coding Standard rule
`DCL59-CPP. Do not define an unnamed namespace in a header file
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL59-CPP.+Do+not+define+an+unnamed+namespace+in+a+header+file>`_.
>From e58a696a0e01c5e4d4c00564a892d69db430391e Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Wed, 24 Dec 2025 19:22:40 +0530
Subject: [PATCH 06/12] Addressed the suggested changes
---
.../clang-tidy/google/GoogleTidyModule.cpp | 1 -
.../misc/AnonymousNamespaceInHeaderCheck.h | 2 +-
clang-tools-extra/docs/ReleaseNotes.rst | 6 ++++-
.../docs/clang-tidy/checks/cert/dcl59-cpp.rst | 4 ++--
.../checks/fuchsia/header-anon-namespaces.rst | 4 ++--
.../docs/clang-tidy/checks/list.rst | 22 +++++++++++--------
.../misc/anonymous-namespace-in-header.cpp | 2 +-
7 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index 68554da855633..68dac250b93f6 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
-#include "../ClangTidyModuleRegistry.h"
#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../modernize/AvoidCStyleCastCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
index 8a11a5833a416..ec970a41d12ba 100644
--- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
@@ -21,7 +21,7 @@ namespace clang::tidy::misc {
/// 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/anonymous-namespace-in-header.html
class AnonymousNamespaceInHeaderCheck : public ClangTidyCheck {
public:
AnonymousNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 73c0ff770d659..cdd0205c8d3be 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -255,7 +255,6 @@ New checks
Finds calls to STL library iterator algorithms that could be replaced with
LLVM range-based algorithms from ``llvm/ADT/STLExtras.h``.
-
- New :doc:`misc-override-with-different-visibility
<clang-tidy/checks/misc/override-with-different-visibility>` check.
@@ -359,6 +358,11 @@ New check aliases
<clang-tidy/checks/modernize/avoid-c-style-cast>`
keeping initial check as an alias to the new one.
+- 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.
+
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/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 6f0a523933408..21a85cd5e9248 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -180,12 +180,11 @@ Clang-Tidy Checks
:doc:`bugprone-unused-return-value <bugprone/unused-return-value>`,
:doc:`bugprone-use-after-move <bugprone/use-after-move>`,
:doc:`bugprone-virtual-near-miss <bugprone/virtual-near-miss>`, "Yes"
- :doc:`cert-dcl58-cpp <cert/dcl58-cpp>`,
- :doc:`cert-env33-c <cert/env33-c>`,
:doc:`cert-err33-c <cert/err33-c>`,
- :doc:`cert-err52-cpp <cert/err52-cpp>`,
+ :doc:`cert-err60-cpp <cert/err60-cpp>`,
:doc:`cert-flp30-c <cert/flp30-c>`,
- :doc:`cert-mem57-cpp <cert/mem57-cpp>`,
+ :doc:`cert-msc50-cpp <cert/msc50-cpp>`,
+ :doc:`cert-oop58-cpp <cert/oop58-cpp>`,
:doc:`concurrency-mt-unsafe <concurrency/mt-unsafe>`,
:doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
:doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines <cppcoreguidelines/avoid-capturing-lambda-coroutines>`,
@@ -239,7 +238,6 @@ Clang-Tidy Checks
:doc:`google-objc-function-naming <google/objc-function-naming>`,
:doc:`google-objc-global-variable-declaration <google/objc-global-variable-declaration>`,
:doc:`google-readability-avoid-underscore-in-googletest-name <google/readability-avoid-underscore-in-googletest-name>`,
- :doc:`google-readability-casting <google/readability-casting>`,
:doc:`google-readability-todo <google/readability-todo>`,
:doc:`google-runtime-float <google/runtime-float>`,
:doc:`google-runtime-int <google/runtime-int>`,
@@ -293,7 +291,7 @@ Clang-Tidy Checks
:doc:`misc-use-internal-linkage <misc/use-internal-linkage>`, "Yes"
:doc:`modernize-avoid-bind <modernize/avoid-bind>`, "Yes"
:doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
- :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`, "Yes"
+ :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
:doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`modernize-concat-nested-namespaces <modernize/concat-nested-namespaces>`, "Yes"
@@ -379,7 +377,7 @@ Clang-Tidy Checks
:doc:`readability-avoid-nested-conditional-operator <readability/avoid-nested-conditional-operator>`,
:doc:`readability-avoid-return-with-void-value <readability/avoid-return-with-void-value>`, "Yes"
:doc:`readability-avoid-unconditional-preprocessor-if <readability/avoid-unconditional-preprocessor-if>`,
- :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
+ :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`readability-const-return-type <readability/const-return-type>`, "Yes"
:doc:`readability-container-contains <readability/container-contains>`, "Yes"
:doc:`readability-container-data-pointer <readability/container-data-pointer>`, "Yes"
@@ -448,16 +446,21 @@ Check aliases
:doc:`cert-dcl50-cpp <cert/dcl50-cpp>`, :doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
: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:`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>`,
+ :doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
:doc:`cert-err60-cpp <cert/err60-cpp>`, :doc:`bugprone-exception-copy-constructor-throws <bugprone/exception-copy-constructor-throws>`,
:doc:`cert-err61-cpp <cert/err61-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
:doc:`cert-exp42-c <cert/exp42-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-fio38-c <cert/fio38-c>`, :doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
+ :doc:`cert-flp30-c <cert/flp30-c>`, :doc:`bugprone-float-loop-counter <bugprone/float-loop-counter>`,
:doc:`cert-flp37-c <cert/flp37-c>`, :doc:`bugprone-suspicious-memory-comparison <bugprone/suspicious-memory-comparison>`,
:doc:`cert-int09-c <cert/int09-c>`, :doc:`readability-enum-initial-value <readability/enum-initial-value>`, "Yes"
+ :doc:`cert-mem57-cpp <cert/mem57-cpp>`, :doc:`bugprone-default-operator-new-on-overaligned-type <bugprone/default-operator-new-on-overaligned-type>`,
:doc:`cert-msc24-c <cert/msc24-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
:doc:`cert-msc30-c <cert/msc30-c>`, :doc:`misc-predictable-rand <misc/predictable-rand>`,
:doc:`cert-msc32-c <cert/msc32-c>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
@@ -583,12 +586,13 @@ Check aliases
: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:`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>`,
+ :doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
+ :doc:`google-readability-casting <google/readability-casting>`, :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
: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>`,
:doc:`hicpp-avoid-c-arrays <hicpp/avoid-c-arrays>`, :doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
:doc:`hicpp-avoid-goto <hicpp/avoid-goto>`, :doc:`cppcoreguidelines-avoid-goto <cppcoreguidelines/avoid-goto>`,
- :doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`,
+ :doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`hicpp-deprecated-headers <hicpp/deprecated-headers>`, :doc:`modernize-deprecated-headers <modernize/deprecated-headers>`, "Yes"
:doc:`hicpp-explicit-conversions <hicpp/explicit-conversions>`, :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes"
:doc:`hicpp-function-size <hicpp/function-size>`, :doc:`readability-function-size <readability/function-size>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
index d47e26036119e..ad784c47c595b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
@@ -49,4 +49,4 @@ using namespace foo::literals::bar_literals;
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]
\ No newline at end of file
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
>From c30cf8b21b83b13823b54405fa196e455318fdd1 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Wed, 24 Dec 2025 21:49:51 +0530
Subject: [PATCH 07/12] Fix: Remove unused ClangTidyModuleRegistry.h includes
---
clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 1 -
.../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h | 1 -
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 1 -
.../docs/clang-tidy/checks/google/build-namespaces.rst | 2 +-
.../clang-tidy/checks/misc/anonymous-namespace-in-header.rst | 2 +-
5 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index 57e6b4baf0f07..1eb2c6f843935 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -8,7 +8,6 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
-#include "../ClangTidyModuleRegistry.h"
#include "../misc/AnonymousNamespaceInHeaderCheck.h"
#include "../misc/MultipleInheritanceCheck.h"
#include "DefaultArgumentsCallsCheck.h"
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h
index ec970a41d12ba..8245bdcfa8fd3 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 {
diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index 7a34111d8c525..f8550b30b9789 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -8,7 +8,6 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
-#include "../ClangTidyModuleRegistry.h"
#include "AnonymousNamespaceInHeaderCheck.h"
#include "ConfusableIdentifierCheck.h"
#include "ConstCorrectnessCheck.h"
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 9b8c350083331..60557e2f722c8 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,4 +5,4 @@ google-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.
\ No newline at end of file
+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 2ecee316a99e1..387406d709448 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
@@ -16,4 +16,4 @@ This check corresponds to the CERT C++ Coding Standard rule
`DCL59-CPP. Do not define an unnamed namespace in a header file
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL59-CPP.+Do+not+define+an+unnamed+namespace+in+a+header+file>`_.
-Corresponding cpplint.py check name: `build/namespaces`.
\ No newline at end of file
+Corresponding cpplint.py check name: `build/namespaces`.
>From 2a1003257d63b418123129770fa755d2b60b5e31 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Wed, 24 Dec 2025 22:39:48 +0530
Subject: [PATCH 08/12] Fixed some changes
---
.../clang-tidy/google/GoogleTidyModule.cpp | 1 +
clang-tools-extra/docs/ReleaseNotes.rst | 10 +++++-----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index ff8438acb6088..fd015e951e837 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../misc/AnonymousNamespaceInHeaderCheck.h"
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index f1728d97a5a9a..196b565ef2d26 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -357,16 +357,16 @@ New check aliases
<clang-tidy/checks/misc/multiple-inheritance>`
keeping initial check as an alias to the new one.
-- Renamed :doc:`google-readability-casting <clang-tidy/checks/google/readability-casting>` to
- :doc:`modernize-avoid-c-style-cast
- <clang-tidy/checks/modernize/avoid-c-style-cast>`
- keeping initial check as an alias to the new one.
-
- 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.
+- Renamed :doc:`google-readability-casting <clang-tidy/checks/google/readability-casting>` to
+ :doc:`modernize-avoid-c-style-cast
+ <clang-tidy/checks/modernize/avoid-c-style-cast>`
+ keeping initial check as an alias to the new one.
+
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
>From a0d07c4ca57a2d9fae08bcced5fb184ce82e914f Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Thu, 25 Dec 2025 13:02:10 +0530
Subject: [PATCH 09/12] Added the ../utils/FileExtensionsUtils.h
---
.../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
index ed872b538db49..6c2b347921240 100644
--- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "../utils/FileExtensionsUtils.h"
#include "AnonymousNamespaceInHeaderCheck.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
>From ff48d72617a26d7374c03af12296a436e3176a80 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Thu, 25 Dec 2025 13:33:03 +0530
Subject: [PATCH 10/12] Fixed documentation length error
---
.../clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp | 2 +-
.../clang-tidy/checks/misc/anonymous-namespace-in-header.rst | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
index 6c2b347921240..c459ba5d9f2e9 100644
--- a/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "../utils/FileExtensionsUtils.h"
#include "AnonymousNamespaceInHeaderCheck.h"
+#include "../utils/FileExtensionsUtils.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
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 387406d709448..ed3010a2aa61f 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
@@ -6,8 +6,9 @@ misc-anonymous-namespace-in-header
Finds anonymous namespaces in headers.
Anonymous namespaces in headers can lead to One Definition Rule (ODR) violations
-because each translation unit including the header will get its own unique version
-of the symbols. This increases binary size and can cause confusing link-time errors.
+because each translation unit including the header will get its own unique
+version of the symbols. This increases binary size and can cause confusing
+link-time errors.
References
----------
>From 0911c930fa3e2817c6cf9096be0aa4dd1ed67b0d Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Thu, 25 Dec 2025 13:50:06 +0530
Subject: [PATCH 11/12] Wrap documentation lines to under 80 chars
---
.../checks/misc/anonymous-namespace-in-header.rst | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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 ed3010a2aa61f..eef596da2e77c 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
@@ -5,10 +5,10 @@ misc-anonymous-namespace-in-header
Finds anonymous namespaces in headers.
-Anonymous namespaces in headers can lead to One Definition Rule (ODR) violations
-because each translation unit including the header will get its own unique
-version of the symbols. This increases binary size and can cause confusing
-link-time errors.
+Anonymous namespaces in headers can lead to One Definition Rule (ODR)
+violations because each translation unit including the header will get its
+own unique version of the symbols. This increases binary size and can cause
+confusing link-time errors.
References
----------
>From a8be063b8ae39868cfe06491051b2ed6d20b2f39 Mon Sep 17 00:00:00 2001
From: ThanSin02426 <manthan02426 at gmail.com>
Date: Fri, 26 Dec 2025 13:12:20 +0530
Subject: [PATCH 12/12] Fixed the proposed changes
---
.../docs/clang-tidy/checks/google/build-namespaces.rst | 10 +++++++++-
clang-tools-extra/docs/clang-tidy/checks/list.rst | 2 +-
.../{google-namespaces.h => anonymous-namespace.h} | 0
.../checkers/misc/anonymous-namespace-in-header.cpp | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
rename clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/{google-namespaces.h => anonymous-namespace.h} (100%)
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 60557e2f722c8..b85ddbcff75bf 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,8 +1,16 @@
.. title:: clang-tidy - google-build-namespaces
+.. meta::
+ :http-equiv=refresh: 5;URL=../misc/anonymous-namespace-in-header.html
google-build-namespaces
=======================
-The ``google-build-namespaces`` check is an alias, please see
+The `google-build-namespaces` check is an alias, please see
:doc:`misc-anonymous-namespace-in-header <../misc/anonymous-namespace-in-header>`
for more information.
+
+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/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 21a85cd5e9248..b50643eee9a6a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -262,7 +262,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>`, "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>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.h
similarity index 100%
rename from clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/google-namespaces.h
rename to clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.h
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
index ad784c47c595b..f300741138a87 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp
@@ -1,5 +1,5 @@
// 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/google-namespaces.h"
+#include "Inputs/anonymous-namespace.h"
// CHECK: warning: do not use unnamed namespaces in header files [misc-anonymous-namespace-in-header]
using namespace spaaaace;
More information about the cfe-commits
mailing list