summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2015-03-24 15:21:45 +0000
committerSamuel Benzaquen <sbenza@google.com>2015-03-24 15:21:45 +0000
commit3199b9a8b54e95fd76d04aec503ebe2f7c18a572 (patch)
treee8c405b8d4095346dcc2e469544a73c7b08192fa /clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
parentc676f2a8bbab473efe91344c2f25fd181461113c (diff)
downloadbcm5719-llvm-3199b9a8b54e95fd76d04aec503ebe2f7c18a572.tar.gz
bcm5719-llvm-3199b9a8b54e95fd76d04aec503ebe2f7c18a572.zip
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 llvm-svn: 233087
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
index 09493ff6f18..5f7c1cd49e1 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
@@ -45,6 +45,16 @@ void GlobalNamesInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
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");
}
OpenPOWER on IntegriCloud