summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-07-16 14:16:56 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-07-16 14:16:56 +0000
commit2252cbf4e89d76b1c39da89b01d67b3e2b73154b (patch)
tree972a4a9393e381d401b0fd4acd64c20e6e1c0cb5 /clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
parent73ef216c73164e1012c22a8813e7543637163996 (diff)
downloadbcm5719-llvm-2252cbf4e89d76b1c39da89b01d67b3e2b73154b.tar.gz
bcm5719-llvm-2252cbf4e89d76b1c39da89b01d67b3e2b73154b.zip
[clang-tidy] Add namespaces checkers.
This change contains of two checkers that warn about 1. anonymous namespaces in header files. 2. 'using namespace' directives everywhere. Differential Revision: http://reviews.llvm.org/D4523 llvm-svn: 213153
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
new file mode 100644
index 00000000000..d8f38cbef1f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
@@ -0,0 +1,41 @@
+//===--- UsingNamespaceDirectiveCheck.cpp - clang-tidy ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "UsingNamespaceDirectiveCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/ASTContext.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace build {
+
+void UsingNamespaceDirectiveCheck::registerMatchers(
+ ast_matchers::MatchFinder *Finder) {
+ Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
+}
+
+void
+UsingNamespaceDirectiveCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace");
+ SourceLocation Loc = U->getLocStart();
+ if (U->isImplicit() || !Loc.isValid())
+ return;
+
+ diag(Loc, "do not use namespace using-directives. Use using-declarations "
+ "instead.");
+ // TODO: We could suggest a list of using directives replacing the using
+ // namespace directive.
+}
+
+} // namespace build
+} // namespace tidy
+} // namespace clang
OpenPOWER on IntegriCloud