Author: Manthan Singla Date: 2026-01-01T12:18:40+03:00 New Revision: 92f16356340d230f04e67d9d7b8f3d91b9f0513b
URL: https://github.com/llvm/llvm-project/commit/92f16356340d230f04e67d9d7b8f3d91b9f0513b DIFF: https://github.com/llvm/llvm-project/commit/92f16356340d230f04e67d9d7b8f3d91b9f0513b.diff LOG: [clang-tidy] Rename google-build-namespaces to misc-anonymous-namespace-in-header (#173484) This PR renames the check `google-build-namespaces` to `misc-anonymous-namespace-in-header` and adds documentation on why anonymous namespaces in headers are problematic. Closes #170979 Added: clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.h clang-tools-extra/test/clang-tidy/checkers/misc/anonymous-namespace-in-header.cpp Modified: clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp clang-tools-extra/clang-tidy/google/CMakeLists.txt clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp clang-tools-extra/clang-tidy/misc/CMakeLists.txt clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/cert/dcl59-cpp.rst clang-tools-extra/docs/clang-tidy/checks/fuchsia/header-anon-namespaces.rst clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst clang-tools-extra/docs/clang-tidy/checks/list.rst Removed: clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h clang-tools-extra/test/clang-tidy/checkers/google/namespaces.cpp ################################################################################ diff --git a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp index c14e5c8076377..f64cb47d18b4e 100644 --- a/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp @@ -30,7 +30,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 62cb24f2510da..1eb2c6f843935 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -8,7 +8,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.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..71b555d5e538b 100644 --- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt @@ -18,12 +18,12 @@ add_clang_library(clangTidyGoogleModule STATIC IntegerTypesCheck.cpp OverloadedUnaryAndCheck.cpp TodoCommentCheck.cpp - UnnamedNamespaceInHeaderCheck.cpp UpgradeGoogletestCaseCheck.cpp UsingNamespaceDirectiveCheck.cpp LINK_LIBS clangTidy + clangTidyMiscModule clangTidyModernizeModule clangTidyReadabilityModule clangTidyUtils diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index b20e07a4b5e2c..fd015e951e837 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -8,6 +8,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" +#include "../misc/AnonymousNamespaceInHeaderCheck.h" #include "../modernize/AvoidCStyleCastCheck.h" #include "../readability/BracesAroundStatementsCheck.h" #include "../readability/FunctionSizeCheck.h" @@ -25,7 +26,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::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 79% rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp index 054bdc8d1230e..c459ba5d9f2e9 100644 --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.cpp @@ -6,26 +6,27 @@ // //===----------------------------------------------------------------------===// -#include "UnnamedNamespaceInHeaderCheck.h" +#include "AnonymousNamespaceInHeaderCheck.h" +#include "../utils/FileExtensionsUtils.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 +38,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 65% rename from clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h rename to clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h index 78e8127a5a342..8245bdcfa8fd3 100644 --- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h +++ b/clang-tools-extra/clang-tidy/misc/AnonymousNamespaceInHeaderCheck.h @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#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. /// @@ -21,10 +20,10 @@ 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 -class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck { +/// https://clang.llvm.org/extra/clang-tidy/checks/misc/anonymous-namespace-in-header.html +class AnonymousNamespaceInHeaderCheck : public ClangTidyCheck { public: - UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); + AnonymousNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context); bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { return LangOpts.CPlusPlus; } @@ -35,6 +34,6 @@ class UnnamedNamespaceInHeaderCheck : 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 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 7894ae667f168..f8550b30b9789 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -8,6 +8,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" +#include "AnonymousNamespaceInHeaderCheck.h" #include "ConfusableIdentifierCheck.h" #include "ConstCorrectnessCheck.h" #include "CoroutineHostileRAIICheck.h" @@ -42,6 +43,8 @@ namespace { 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 512cd29ed2715..a154b4e08fae8 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -363,6 +363,11 @@ New check aliases <clang-tidy/checks/misc/multiple-inheritance>` 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>` 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..93567ab26f855 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,11 @@ .. 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..497f7ed6f6dfe 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,11 @@ .. 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>` +The `fuchsia-header-anon-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/google/build-namespaces.rst b/clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst index b421d992d63a6..72c92e1920c66 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,10 +1,14 @@ .. 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. +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. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index e150c5ff50fda..e0de2b9c2dada 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -228,7 +228,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" @@ -262,6 +261,7 @@ Clang-Tidy Checks :doc:`llvmlibc-implementation-in-namespace <llvmlibc/implementation-in-namespace>`, :doc:`llvmlibc-inline-function-decl <llvmlibc/inline-function-decl>`, "Yes" :doc:`llvmlibc-restrict-system-libc-headers <llvmlibc/restrict-system-libc-headers>`, "Yes" + :doc:`misc-anonymous-namespace-in-header <misc/anonymous-namespace-in-header>`, :doc:`misc-confusable-identifiers <misc/confusable-identifiers>`, :doc:`misc-const-correctness <misc/const-correctness>`, "Yes" :doc:`misc-coroutine-hostile-raii <misc/coroutine-hostile-raii>`, @@ -447,7 +447,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>`, @@ -584,8 +584,9 @@ 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:`fuchsia-multiple-inheritance <fuchsia/multiple-inheritance>`, :doc:`misc-multiple-inheritance <misc/multiple-inheritance>`, + :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-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>`, 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..eef596da2e77c --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc/anonymous-namespace-in-header.rst @@ -0,0 +1,20 @@ +.. title:: clang-tidy - misc-anonymous-namespace-in-header + +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. + +References +---------- + +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`. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.h b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.h new file mode 100644 index 0000000000000..f4d87f5bc9511 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/anonymous-namespace.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 87% 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..f300741138a87 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}}:" -#include "Inputs/google-namespaces.h" -// CHECK: warning: do not use unnamed namespaces in header files [google-build-namespaces] +// 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/anonymous-namespace.h" +// CHECK: warning: do not use unnamed namespaces in header files [misc-anonymous-namespace-in-header] using namespace spaaaace; // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
