11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
14 using namespace clang::ast_matchers;
18 namespace readability {
20 void ElseAfterReturnCheck::registerMatchers(MatchFinder *
Finder) {
24 forEach(ifStmt(hasThen(stmt(anyOf(returnStmt(),
25 compoundStmt(has(returnStmt()))))),
26 hasElse(stmt().bind(
"else")))
32 return FixItHint::CreateRemoval(CharSourceRange::getTokenRange(Loc, Loc));
35 void ElseAfterReturnCheck::check(
const MatchFinder::MatchResult &
Result) {
36 const auto *If = Result.Nodes.getNodeAs<IfStmt>(
"if");
37 SourceLocation ElseLoc = If->getElseLoc();
38 DiagnosticBuilder Diag = diag(ElseLoc,
"don't use else after return");
43 if (
const auto *CS = Result.Nodes.getNodeAs<CompoundStmt>(
"else"))
SourceLocation Loc
'#' location in the include directive
std::unique_ptr< ast_matchers::MatchFinder > Finder
static FixItHint removeToken(SourceLocation Loc)