Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/CompileCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command,
if (auto *DashDash =
ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) {
auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0]
for (unsigned I = DashDashIndex; I < Cmd.size(); ++I)
// Another +1 so we don't treat the `--` itself as an input.
for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I)
SawInput(Cmd[I]);
Cmd.resize(DashDashIndex);
}
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ TEST(CommandMangler, RespectsOriginalSysroot) {
Not(HasSubstr(testPath("fake/sysroot"))));
}
}

TEST(CommandMangler, StdLatestFlag) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the original PR, I'm not sure if this is the best test case for this change, because the fact that transferCompileCommand() drops /std:c++latest is itself a bug which will be fixed in #160030.

But I'm not sure how to write a more direct test for "transferCompileCommand() was not called", and the scenario being tested here is a valid one from a user expectation point of view.

const auto Mangler = CommandMangler::forTests();
tooling::CompileCommand Cmd;
Cmd.CommandLine = {"clang-cl", "/std:c++latest", "--", "/Users/foo.cc"};
Mangler(Cmd, "/Users/foo.cc");
// Check that the /std:c++latest flag is not dropped
EXPECT_THAT(llvm::join(Cmd.CommandLine, " "), HasSubstr("/std:c++latest"));
}

} // namespace
} // namespace clangd
} // namespace clang