Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <iostream>
#include <optional>
#include <string>

Expand Down Expand Up @@ -173,21 +174,21 @@ 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;
const Expr *NextArg = Call.getArg(Index + 1);
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
{Arg->getBeginLoc(),
Lexer::getLocForEndOfToken(
Arg->getEndLoc(), 0, Ctx.getSourceManager(), Ctx.getLangOpts())
.getLocWithOffset(1)}));
{Arg->getBeginLoc(), NextArg->getBeginLoc().getLocWithOffset(-1)}));
} else {
Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
}
} else {
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc()));
// At this point we know Index > 0 because `Commas[0] = true` earlier
Commas[Index] = true;
const Expr *PrevArg = Call.getArg(Index - 1);
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
PrevArg->getEndLoc().getLocWithOffset(1), Arg->getEndLoc()));
}
}
}
Expand Down
Loading