Author: sbenza Date: Tue Mar 24 10:21:45 2015 New Revision: 233087 URL: http://llvm.org/viewvc/llvm-project?rev=233087&view=rev Log: Fix false positive on anonymous namespaces in headers.
Summary: 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. Reviewers: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D8443 Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp Modified: clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp?rev=233087&r1=233086&r2=233087&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp Tue Mar 24 10:21:45 2015 @@ -45,6 +45,16 @@ void GlobalNamesInHeadersCheck::check(co return; } + if (const auto* UsingDirective = dyn_cast<UsingDirectiveDecl>(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"); } Modified: clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp?rev=233087&r1=233086&r2=233087&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp (original) +++ clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp Tue Mar 24 10:21:45 2015 @@ -101,6 +101,10 @@ TEST_F(GlobalNamesInHeadersCheckTest, Us 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 _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
