[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures #106445 (PR #117953)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 20:15:51 PDT 2025


================
@@ -1186,15 +1188,28 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
       CheckCXXThisCapture(C->Loc, /*Explicit=*/true, /*BuildAndDiagnose*/ true,
                           /*FunctionScopeIndexToStopAtPtr*/ nullptr,
                           C->Kind == LCK_StarThis);
-      if (!LSI->Captures.empty())
-        LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
-      continue;
+      if (!LSI->Captures.empty()) { //
+        SourceManager &SourceMgr = Context.getSourceManager();
+        const LangOptions &LangOpts = Context.getLangOpts();
+        SourceRange TrimmedRange =
+            Lexer::makeFileCharRange(
+                CharSourceRange::getTokenRange(C->ExplicitRange), SourceMgr,
+                LangOpts)
+                .getAsRange();
----------------
ojhunt wrote:

I'd prefer `.getAsRange();` on the preceding line, but if clang-format puts it here I guess we accept that.

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


More information about the cfe-commits mailing list