https://github.com/ThanSin02426 updated https://github.com/llvm/llvm-project/pull/172611
>From 722364c767e04ae6d06894f3ac827f95bebb0195 Mon Sep 17 00:00:00 2001 From: ThanSin02426 <[email protected]> Date: Wed, 17 Dec 2025 14:23:54 +0530 Subject: [PATCH] [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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
