[clang] [clang] Correct FixIt ranges for unused capture warnings (PR #141148)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Fri May 30 08:10:39 PDT 2025


================
@@ -972,6 +972,12 @@ class Sema final : public SemaBase {
   /// Calls \c Lexer::getLocForEndOfToken()
   SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0);
 
+  /// Calls \c Lexer::findNextToken() to find the next token, and if the
+  /// locations of both ends of the token can be resolved it return that
----------------
ojhunt wrote:

I've been talking to @cor3ntin about this as I added some macro tests and they aren't working as I believe they should, and I think I understand my mistake (I misunderstood the docs for `Lexer::findNextToken`) my intention is to require both ends to not be in a macro, and then add an additional test for a macro in the middle wrapping a comma to make sure that if the comma comes from a macro (rather than any subset of the capture expression) we don't try to produce a fixit.

In principle it would be easy to handle

```cpp
#define COMMA ,
```

But I think there are too many ways for macros to do weird things to warrant even trying in such a case. I think that's also a reasonable tradeoff - a macro around subsets of the capture seems vanishingly unlikely so not providing a fixit in such cases seems fair.

https://github.com/llvm/llvm-project/pull/141148


More information about the cfe-commits mailing list