7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " AvoidReturnWithVoidValueCheck.h"
10
+ #include " ../utils/LexerUtils.h"
10
11
#include " clang/AST/Stmt.h"
11
12
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
13
#include " clang/ASTMatchers/ASTMatchers.h"
@@ -51,10 +52,9 @@ void AvoidReturnWithVoidValueCheck::check(
51
52
DiagnosticBuilder Diag = diag (VoidReturn->getBeginLoc (),
52
53
" return statement within a void function "
53
54
" should not have a specified return value" );
54
- std::optional<Token> SemicolonPos =
55
- Lexer::findNextToken (VoidReturn->getRetValue ()->getEndLoc (),
56
- *Result.SourceManager , getLangOpts ());
57
- if (!SemicolonPos)
55
+ const SourceLocation SemicolonPos = utils::lexer::findNextTerminator (
56
+ VoidReturn->getEndLoc (), *Result.SourceManager , getLangOpts ());
57
+ if (SemicolonPos.isInvalid ())
58
58
return ;
59
59
const StringRef ReturnExpr =
60
60
Lexer::getSourceText (CharSourceRange::getTokenRange (
@@ -64,8 +64,7 @@ void AvoidReturnWithVoidValueCheck::check(
64
64
if (!SurroundingBlock)
65
65
Replacement = " {" + Replacement + " }" ;
66
66
Diag << FixItHint::CreateReplacement (
67
- CharSourceRange::getTokenRange (VoidReturn->getBeginLoc (),
68
- SemicolonPos->getEndLoc ()),
67
+ CharSourceRange::getTokenRange (VoidReturn->getBeginLoc (), SemicolonPos),
69
68
Replacement);
70
69
}
71
70
0 commit comments