11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 21 void UnusedAliasDeclsCheck::registerMatchers(MatchFinder *Finder) {
24 if (!getLangOpts().CPlusPlus11)
29 Finder->addMatcher(namespaceAliasDecl(isExpansionInMainFile()).bind(
"alias"),
31 Finder->addMatcher(nestedNameSpecifier().bind(
"nns"),
this);
34 void UnusedAliasDeclsCheck::check(
const MatchFinder::MatchResult &Result) {
35 if (
const auto *AliasDecl = Result.Nodes.getNodeAs<NamedDecl>(
"alias")) {
36 FoundDecls[AliasDecl] = CharSourceRange::getCharRange(
37 AliasDecl->getLocStart(),
38 Lexer::findLocationAfterToken(
39 AliasDecl->getLocEnd(), tok::semi, *Result.SourceManager,
45 if (
const auto *NestedName =
46 Result.Nodes.getNodeAs<NestedNameSpecifier>(
"nns")) {
47 if (
const auto *AliasDecl = NestedName->getAsNamespaceAlias()) {
48 FoundDecls[AliasDecl] = CharSourceRange();
53 void UnusedAliasDeclsCheck::onEndOfTranslationUnit() {
54 for (
const auto &FoundDecl : FoundDecls) {
55 if (!FoundDecl.second.isValid())
57 diag(FoundDecl.first->getLocation(),
"namespace alias decl %0 is unused")
58 << FoundDecl.first << FixItHint::CreateRemoval(FoundDecl.second);
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//