================
@@ -84,6 +84,21 @@ SourceLocation Sema::getLocForEndOfToken(SourceLocation Loc, 
unsigned Offset) {
   return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts);
 }
 
+SourceRange Sema::getRangeForNextToken(SourceLocation Loc,
+                                       bool IncludeComments) {
+  if (!Loc.isValid())
+    return SourceRange();
+  std::optional<Token> NextToken =
+      Lexer::findNextToken(Loc, SourceMgr, LangOpts, IncludeComments);
----------------
ojhunt wrote:

I'm using this one function for two purposes:

* Finding the (presumed) comma and stepping over it
* Finding the start of the next token

It seemed like a reasonable approach, and given we're producing a fixit 
diagnostic I don't think the perf matters.

Basically what I'm trying to do is say given an unused capture:

```cpp
auto foo = [a, unused,           b] ... // just a pile of white space for 
illustrative purposes
auto bar = [a, unused, /* ... */ b] ...
auto wibble = [a,  /* ... */  unused, b] ...
auto thingy = [a,  unused /* ... */, b] ...
```

produce fixits that result in

```cpp
auto foo = [a, b] ... // just a pile of white space for illustrative purposes
auto bar = [a, /* ... */ b] ...
auto wibble = [a, b] ...
auto thingy = [a, b] ...
```

and for that what we want to do is find the end of the comma, and the start of 
the next token, simply using the "findNextToken" to just get those tokens seems 
reasonable.

Of course as we discussed in discord, that function doesn't handle macros, and 
handling this correctly for macros would imply the Sema "wrapper" excludes 
macro wrappers (so would not just be a wrapper) or every user has to check for 
macros.

https://github.com/llvm/llvm-project/pull/141148
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to