Hi djasper,

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.

http://reviews.llvm.org/D8443

Files:
  clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  unittests/clang-tidy/GoogleModuleTest.cpp

Index: clang-tidy/google/GlobalNamesInHeadersCheck.cpp
===================================================================
--- clang-tidy/google/GlobalNamesInHeadersCheck.cpp
+++ clang-tidy/google/GlobalNamesInHeadersCheck.cpp
@@ -45,6 +45,16 @@
       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");
 }
Index: unittests/clang-tidy/GoogleModuleTest.cpp
===================================================================
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ 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

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: clang-tidy/google/GlobalNamesInHeadersCheck.cpp
===================================================================
--- clang-tidy/google/GlobalNamesInHeadersCheck.cpp
+++ clang-tidy/google/GlobalNamesInHeadersCheck.cpp
@@ -45,6 +45,16 @@
       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");
 }
Index: unittests/clang-tidy/GoogleModuleTest.cpp
===================================================================
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ 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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to