42 const MatchFinder::MatchResult &Result) {
43 const auto *VoidReturn = Result.Nodes.getNodeAs<ReturnStmt>(
"void_return");
44 if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
46 const auto *SurroundingBlock =
47 Result.Nodes.getNodeAs<CompoundStmt>(
"compound_parent");
48 if (!StrictMode && !SurroundingBlock)
50 DiagnosticBuilder Diag = diag(VoidReturn->getBeginLoc(),
51 "return statement within a void function "
52 "should not have a specified return value");
54 VoidReturn->getEndLoc(), *Result.SourceManager, getLangOpts());
55 if (SemicolonPos.isInvalid())
57 if (!SurroundingBlock) {
59 VoidReturn, getLangOpts(), *Result.SourceManager,
60 VoidReturn->getBeginLoc());
61 if (BraceInsertionHints)
62 Diag << BraceInsertionHints.openingBraceFixIt()
63 << BraceInsertionHints.closingBraceFixIt();
65 Diag << FixItHint::CreateRemoval(VoidReturn->getReturnLoc());
66 const auto *FunctionParent =
67 Result.Nodes.getNodeAs<FunctionDecl>(
"function_parent");
68 if (!FunctionParent ||
69 (SurroundingBlock && SurroundingBlock->body_back() != VoidReturn))
71 Diag << FixItHint::CreateInsertion(SemicolonPos.getLocWithOffset(1),
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
BraceInsertionHints getBraceInsertionsHints(const Stmt *const S, const LangOptions &LangOpts, const SourceManager &SM, SourceLocation StartLoc, SourceLocation EndLocHint)
Create fix-it hints for braces that wrap the given statement when applied.