Benjamin Kramer | 2252cbf | 2014-07-16 14:16:56 +0000 | [diff] [blame] | 1 | //===--- UsingNamespaceDirectiveCheck.cpp - clang-tidy ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "UsingNamespaceDirectiveCheck.h" |
Chandler Carruth | 3cbd71c | 2015-01-14 11:24:38 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTContext.h" |
Benjamin Kramer | 2252cbf | 2014-07-16 14:16:56 +0000 | [diff] [blame] | 12 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 13 | #include "clang/ASTMatchers/ASTMatchers.h" |
Benjamin Kramer | 2252cbf | 2014-07-16 14:16:56 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace clang::ast_matchers; |
| 16 | |
| 17 | namespace clang { |
| 18 | namespace tidy { |
Alexander Kornienko | ed824e0 | 2015-03-05 13:46:14 +0000 | [diff] [blame^] | 19 | namespace google { |
Benjamin Kramer | 2252cbf | 2014-07-16 14:16:56 +0000 | [diff] [blame] | 20 | namespace build { |
| 21 | |
| 22 | void UsingNamespaceDirectiveCheck::registerMatchers( |
| 23 | ast_matchers::MatchFinder *Finder) { |
| 24 | Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this); |
| 25 | } |
| 26 | |
| 27 | void |
| 28 | UsingNamespaceDirectiveCheck::check(const MatchFinder::MatchResult &Result) { |
| 29 | const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace"); |
| 30 | SourceLocation Loc = U->getLocStart(); |
| 31 | if (U->isImplicit() || !Loc.isValid()) |
| 32 | return; |
| 33 | |
| 34 | diag(Loc, "do not use namespace using-directives. Use using-declarations " |
| 35 | "instead."); |
| 36 | // TODO: We could suggest a list of using directives replacing the using |
| 37 | // namespace directive. |
| 38 | } |
| 39 | |
| 40 | } // namespace build |
Alexander Kornienko | ed824e0 | 2015-03-05 13:46:14 +0000 | [diff] [blame^] | 41 | } // namespace google |
Benjamin Kramer | 2252cbf | 2014-07-16 14:16:56 +0000 | [diff] [blame] | 42 | } // namespace tidy |
| 43 | } // namespace clang |