[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 13 12:00:50 PST 2025


================
@@ -173,22 +200,27 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
   for (unsigned Index : Sorted) {
     const Expr *Arg = Call.getArg(Index);
     if (Commas[Index]) {
-      if (Index >= Commas.size()) {
-        Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
-      } else {
+      if (Index + 1 < Call.getNumArgs()) {
         // Remove the next comma
-        Commas[Index + 1] = true;
-        Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-            {Arg->getBeginLoc(),
-             Lexer::getLocForEndOfToken(
-                 Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts())
-                 .getLocWithOffset(1)}));
+        const Expr *NextArg = Call.getArg(Index + 1);
+        std::optional<CharSourceRange> CommaLoc = GetCommaLoc(
+            Arg->getEndLoc().getLocWithOffset(1), NextArg->getBeginLoc());
----------------
PiotrZSL wrote:

Note: getEndLoc point to token, you may want to take into account length of token, but still it should be fine.

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


More information about the cfe-commits mailing list