blob: d8f38cbef1f903020337b041a1a3c1f79b765f54 [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"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
13#include "clang/AST/ASTContext.h"
14
15using namespace clang::ast_matchers;
16
17namespace clang {
18namespace tidy {
19namespace build {
20
21void UsingNamespaceDirectiveCheck::registerMatchers(
22 ast_matchers::MatchFinder *Finder) {
23 Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
24}
25
26void
27UsingNamespaceDirectiveCheck::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