Index: clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp @@ -45,6 +45,16 @@ return; } + if (const auto* UsingDirective = dyn_cast(D)) { + if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) { + // Anynoumous namespaces inject a using directive into the AST to import + // the names into the containing namespace. + // We should not have them in headers, but there is another warning for + // that. + return; + } + } + diag(D->getLocStart(), "using declarations in the global namespace in headers are prohibited"); } Index: clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp +++ clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp @@ -101,6 +101,10 @@ EXPECT_FALSE(runCheckOnCode("SOME_MACRO(namespace std);", "foo.h")); } +TEST_F(GlobalNamesInHeadersCheckTest, RegressionAnonymousNamespace) { + EXPECT_FALSE(runCheckOnCode("namespace {}", "foo.h")); +} + } // namespace test } // namespace tidy } // namespace clang