================
@@ -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) {
+ // Check whether StarToken has leading space or not
+ const bool StarTokenHasNoLeadingSpace =
+ PrevToken->getEndLoc() == StarToken.getLocation();
+ if (PrevToken->isAnyIdentifier() && StarTokenHasNoLeadingSpace)
+ ReplaceText = " ";
+ }
----------------
vbvictor wrote:
IMO, this should be a separate function to only return true/false and we should
add whitespace based on that.
https://github.com/llvm/llvm-project/pull/202015
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits