28 const MatchFinder::MatchResult &Result) {
29 const auto *Def = Result.Nodes.getNodeAs<NamedDecl>(
"static-def");
31 if (Def->getLocation().isMacroID())
35 const DeclContext *DC = Def->getDeclContext();
36 if (DC->getDeclKind() != Decl::Namespace)
40 diag(Def->getLocation(),
"%0 is a static definition in "
41 "anonymous namespace; static is redundant here")
44 SourceLocation Loc = Def->getSourceRange().getBegin();
45 while (Loc < Def->getSourceRange().getEnd() &&
46 !Lexer::getRawToken(Loc, Tok, *Result.SourceManager, getLangOpts(),
48 SourceRange TokenRange(Tok.getLocation(), Tok.getEndLoc());
49 StringRef SourceText =
50 Lexer::getSourceText(CharSourceRange::getTokenRange(TokenRange),
51 *Result.SourceManager, getLangOpts());
52 if (SourceText ==
"static") {
53 Diag << FixItHint::CreateRemoval(TokenRange);
56 Loc = Tok.getEndLoc();