Skip to content

Commit 922cc58

Browse files
committed
Use findNextTerminator
1 parent 776323f commit 922cc58

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "AvoidReturnWithVoidValueCheck.h"
10+
#include "../utils/LexerUtils.h"
1011
#include "clang/AST/Stmt.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -51,10 +52,9 @@ void AvoidReturnWithVoidValueCheck::check(
5152
DiagnosticBuilder Diag = diag(VoidReturn->getBeginLoc(),
5253
"return statement within a void function "
5354
"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())
5858
return;
5959
const StringRef ReturnExpr =
6060
Lexer::getSourceText(CharSourceRange::getTokenRange(
@@ -64,8 +64,7 @@ void AvoidReturnWithVoidValueCheck::check(
6464
if (!SurroundingBlock)
6565
Replacement = "{" + Replacement + "}";
6666
Diag << FixItHint::CreateReplacement(
67-
CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
68-
SemicolonPos->getEndLoc()),
67+
CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(), SemicolonPos),
6968
Replacement);
7069
}
7170

0 commit comments

Comments
 (0)