1//===--- NoNamespaceCheck.cpp - clang-tidy---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "NoNamespaceCheck.h"
10#include "AbseilMatcher.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12
13using namespace clang::ast_matchers;
14
15namespace clang::tidy::abseil {
16
17void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {
18 Finder->addMatcher(NodeMatch: namespaceDecl(hasName(Name: "::absl"), unless(isInAbseilFile()))
19 .bind(ID: "abslNamespace"),
20 Action: this);
21}
22
23void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
24 const auto *AbslNamespaceDecl =
25 Result.Nodes.getNodeAs<NamespaceDecl>(ID: "abslNamespace");
26
27 diag(AbslNamespaceDecl->getLocation(),
28 "namespace 'absl' is reserved for implementation of the Abseil library "
29 "and should not be opened in user code");
30}
31
32} // namespace clang::tidy::abseil
33

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of clang-tools-extra/clang-tidy/abseil/NoNamespaceCheck.cpp