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" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/ASTMatchers/ASTMatchers.h" 14 15 using namespace clang::ast_matchers; 16 17 namespace clang { 18 namespace tidy { 19 namespace build { 20 21 void UsingNamespaceDirectiveCheck::registerMatchers( 22 ast_matchers::MatchFinder *Finder) { 23 Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this); 24 } 25 26 void 27 UsingNamespaceDirectiveCheck::check(const MatchFinder::MatchResult &Result) { 28 const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace"); 29 SourceLocation Loc = U->getLocStart(); 30 if (U->isImplicit() || !Loc.isValid()) 31 return; 32 33 diag(Loc, "do not use namespace using-directives. Use using-declarations " 34 "instead."); 35 // TODO: We could suggest a list of using directives replacing the using 36 // namespace directive. 37 } 38 39 } // namespace build 40 } // namespace tidy 41 } // namespace clang 42