[clang-tools-extra] [clang-tidy] Fix modernize-loop-convert by introducing space (PR #202015)
Gaurav Dhingra via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 10 06:16:21 PDT 2026
================
@@ -698,11 +698,32 @@ void LoopConvertCheck::doConversion(
std::string ReplaceText;
SourceRange Range = Usage.Range;
if (Usage.Expression) {
+ // Decide whether `ReplaceText` needs to be pre-appended with a space
+ // or not. In cases like `delete*it`, we can't just change it to
+ // `deleteit` we need to introduce space after `delete` to make it
+ // `delete it`.
+ Token StarToken;
+ if (Usage.Kind == Usage::UK_Default &&
+ !Lexer::getRawToken(Usage.Range.getBegin(), StarToken,
+ Context->getSourceManager(), getLangOpts(),
+ false) &&
+ StarToken.is(tok::star)) {
+ std::optional<Token> PrevToken = Lexer::findPreviousToken(
+ Usage.Range.getBegin(), Context->getSourceManager(),
+ getLangOpts(), true);
+ if (PrevToken) {
----------------
gxyd wrote:
I've reverted to using `if (!PrevToken) return false;` for now on this PR to get the tests passing.
https://github.com/llvm/llvm-project/pull/202015
More information about the cfe-commits
mailing list