[clang-tools-extra] [clang-tidy] Fix modernize-loop-convert by introducing space (PR #202015)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 10 02:23:33 PDT 2026
================
@@ -552,6 +552,39 @@ static bool containerIsConst(const Expr *ContainerExpr, bool Dereference) {
return false;
}
+// Returns true if the token at `BeginLocation` is immediately preceded by an
+// identifier or keyword token with no space between them.
+static bool
+isPrecededByAdjacentIdentifierOrKeyword(SourceManager &SourceMgr,
+ const LangOptions &LangOpts,
+ SourceLocation BeginLocation) {
+ std::optional<Token> PrevToken =
+ Lexer::findPreviousToken(BeginLocation, SourceMgr, LangOpts, true);
+ if (!PrevToken)
+ return false;
+ // Check whether the token at `BeginLocation` is immediately adjacent to
+ // the previous token with no space between them.
+ const bool IsAdjacentToPrevToken = PrevToken->getEndLoc() == BeginLocation;
+ return PrevToken->isAnyIdentifier() && IsAdjacentToPrevToken;
+}
+
+// Returns true if the replacement text needs a leading space to avoid merging
+// with the preceding token. This occurs when `*it` is immediately adjacent to
+// a keyword, e.g. `delete*it`, where replacing `*it` with `it` would
+// incorrectly produce `deleteit`. So we insert a space b/w `delete` and `it`.
+static bool requiresLeadingSpace(SourceManager &SourceMgr,
----------------
vbvictor wrote:
```suggestion
static bool requiresLeadingSpace(const SourceManager &SourceMgr,
```
https://github.com/llvm/llvm-project/pull/202015
More information about the cfe-commits
mailing list