[clang-tools-extra] [clang-tidy] Fix invalid fix-it for macro expansions (PR #227984)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 03:59:06 PDT 2026
================
@@ -101,11 +101,14 @@ void PreferSingleCharOverloadsCheck::check(
if (!Replacement)
return;
- diag(Literal->getBeginLoc(), "%0 called with a string literal consisting of "
- "a single character; consider using the more "
- "efficient overload accepting a character")
- << FindFunc
- << FixItHint::CreateReplacement(Literal->getSourceRange(), *Replacement);
+ const auto Diag = diag(Literal->getBeginLoc(),
+ "%0 called with a string literal consisting of "
+ "a single character; consider using the more "
+ "efficient overload accepting a character")
+ << FindFunc;
+ if (!Literal->getBeginLoc().isMacroID() && !Literal->getEndLoc().isMacroID())
----------------
zeyi2 wrote:
Could we check all concatenated string tokens rather than only the endpoints?
```c
#define SEP "_"
...
s += "" SEP "";
```
I think we also want to stop emitting fix-its for similar cases like this.
```c++
if (std::none_of(Literal->tokloc_begin(), Literal->tokloc_end(),
[](SourceLocation Loc) { return Loc.isMacroID(); }))
```
https://github.com/llvm/llvm-project/pull/227984
More information about the cfe-commits
mailing list