blob: 7a2587225150c89e23c2b18bd9594313bf1522f9 [file] [log] [blame]
Benjamin Kramer2252cbf2014-07-16 14:16:56 +00001//===--- 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 Carruth3cbd71c2015-01-14 11:24:38 +000011#include "clang/AST/ASTContext.h"
Benjamin Kramer2252cbf2014-07-16 14:16:56 +000012#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/ASTMatchers/ASTMatchers.h"
Benjamin Kramer2252cbf2014-07-16 14:16:56 +000014
15using namespace clang::ast_matchers;
16
17namespace clang {
18namespace tidy {
Alexander Kornienkoed824e02015-03-05 13:46:14 +000019namespace google {
Benjamin Kramer2252cbf2014-07-16 14:16:56 +000020namespace build {
21
22void UsingNamespaceDirectiveCheck::registerMatchers(
23 ast_matchers::MatchFinder *Finder) {
24 Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
25}
26
27void
28UsingNamespaceDirectiveCheck::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 Kornienkoed824e02015-03-05 13:46:14 +000041} // namespace google
Benjamin Kramer2252cbf2014-07-16 14:16:56 +000042} // namespace tidy
43} // namespace clang