Skip to content

Commit ea452c0

Browse files
[clangd] Fix off-by-one error in CommandMangler (#160029)
SawInput() is intended to be called for every argument after a `--`, but it was mistakenly being called for the `--` itself. Partially fixes clangd/clangd#1850
1 parent b9e41ae commit ea452c0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
270270
if (auto *DashDash =
271271
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
272272
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
273-
for (unsigned I = DashDashIndex; I < Cmd.size(); ++I)
273+
// Another +1 so we don't treat the `--` itself as an input.
274+
for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I)
274275
SawInput(Cmd[I]);
275276
Cmd.resize(DashDashIndex);
276277
}

clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,16 @@ TEST(CommandMangler, RespectsOriginalSysroot) {
526526
Not(HasSubstr(testPath("fake/sysroot"))));
527527
}
528528
}
529+
530+
TEST(CommandMangler, StdLatestFlag) {
531+
const auto Mangler = CommandMangler::forTests();
532+
tooling::CompileCommand Cmd;
533+
Cmd.CommandLine = {"clang-cl", "/std:c++latest", "--", "/Users/foo.cc"};
534+
Mangler(Cmd, "/Users/foo.cc");
535+
// Check that the /std:c++latest flag is not dropped
536+
EXPECT_THAT(llvm::join(Cmd.CommandLine, " "), HasSubstr("/std:c++latest"));
537+
}
538+
529539
} // namespace
530540
} // namespace clangd
531541
} // namespace clang

0 commit comments

Comments
 (0)