10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/Lex/Lexer.h"
21 Finder->addMatcher(namespaceAliasDecl(isExpansionInMainFile()).bind(
"alias"),
23 Finder->addMatcher(nestedNameSpecifier().bind(
"nns"),
this);
27 if (
const auto *AliasDecl = Result.Nodes.getNodeAs<NamedDecl>(
"alias")) {
28 FoundDecls[AliasDecl] = CharSourceRange::getCharRange(
29 AliasDecl->getBeginLoc(),
30 Lexer::findLocationAfterToken(
31 AliasDecl->getEndLoc(), tok::semi, *Result.SourceManager,
37 if (
const auto *NestedName =
38 Result.Nodes.getNodeAs<NestedNameSpecifier>(
"nns")) {
39 if (
const auto *AliasDecl = NestedName->getAsNamespaceAlias()) {
40 FoundDecls[AliasDecl] = CharSourceRange();
46 for (
const auto &FoundDecl : FoundDecls) {
47 if (!FoundDecl.second.isValid())
49 diag(FoundDecl.first->getLocation(),
"namespace alias decl %0 is unused")
50 << FoundDecl.first << FixItHint::CreateRemoval(FoundDecl.second);
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
const LangOptions & getLangOpts() const
Returns the language options from the context.
void onEndOfTranslationUnit() override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.