10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
13#include "clang/Lex/Lexer.h"
22 std::optional<StringRef> HeaderFileExtensionsOption =
24 RawStringHeaderFileExtensions =
26 if (HeaderFileExtensionsOption) {
31 << RawStringHeaderFileExtensions;
34 HeaderFileExtensions = Context->getHeaderFileExtensions();
39 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
43 ast_matchers::MatchFinder *Finder) {
44 Finder->addMatcher(decl(anyOf(usingDecl(), usingDirectiveDecl()),
45 hasDeclContext(translationUnitDecl()))
51 const auto *D = Result.Nodes.getNodeAs<
Decl>(
"using_decl");
53 if (D->getBeginLoc().isMacroID())
57 if (Result.SourceManager->isInMainFile(
58 Result.SourceManager->getExpansionLoc(D->getBeginLoc()))) {
61 D->getBeginLoc(), *Result.SourceManager, HeaderFileExtensions))
65 if (
const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
66 if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
75 diag(D->getBeginLoc(),
76 "using declarations in the global namespace in headers are prohibited");
const FunctionDecl * Decl
std::optional< StringRef > get(StringRef LocalName) const
Read a named option from the Context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
DiagnosticBuilder configurationDiag(StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) const
Adds a diagnostic to report errors in the check's configuration.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
StringRef defaultFileExtensionDelimiters()
Returns recommended default value for the list of file extension delimiters.
bool parseFileExtensions(StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
Parses header file extensions from a semicolon-separated list.
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether spelling location of Loc is in header file.
llvm::StringMap< ClangTidyValue > OptionMap