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

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 3 02:54:30 PDT 2025


================
@@ -84,6 +84,29 @@ SourceLocation Sema::getLocForEndOfToken(SourceLocation Loc, unsigned Offset) {
   return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts);
 }
 
+SourceRange
+Sema::getRangeForNextToken(SourceLocation Loc, bool IncludeMacros,
+                           bool IncludeComments,
+                           std::optional<tok::TokenKind> ExpectedToken) {
+  if (!Loc.isValid())
+    return SourceRange();
+  std::optional<Token> NextToken =
+      Lexer::findNextToken(Loc, SourceMgr, LangOpts, IncludeComments);
+  if (!NextToken)
+    return SourceRange();
+  if (ExpectedToken && NextToken->getKind() != *ExpectedToken)
+    return SourceRange();
+  SourceLocation TokenStart = NextToken->getLocation();
+  SourceLocation TokenEnd = NextToken->getLastLoc();
+  if (!TokenStart.isValid() || !TokenEnd.isValid())
+    return SourceRange();
+  if (!IncludeMacros) {
+    if (TokenStart.isMacroID() || TokenEnd.isMacroID())
+      return SourceRange();
+  }
----------------
cor3ntin wrote:

You casn merge all of that in a single statement

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


More information about the cfe-commits mailing list