-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][Tooling] Support 'c++latest' in InterpolatingCompilationDatabase #160030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HighCommander4
merged 3 commits into
main
from
users/HighCommander4/clangd-issue-1850-part2
Sep 30, 2025
Merged
[clang][Tooling] Support 'c++latest' in InterpolatingCompilationDatabase #160030
HighCommander4
merged 3 commits into
main
from
users/HighCommander4/clangd-issue-1850-part2
Sep 30, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang Author: Nathan Ridge (HighCommander4) ChangesFixes clangd/clangd#527 Full diff: https://github.com/llvm/llvm-project/pull/160030.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index e324404e627c2..660540afd2320 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -536,6 +536,15 @@ TEST(CommandMangler, StdLatestFlag) {
EXPECT_THAT(llvm::join(Cmd.CommandLine, " "), HasSubstr("/std:c++latest"));
}
+TEST(CommandMangler, StdLatestFlag_Inference) {
+ const auto Mangler = CommandMangler::forTests();
+ tooling::CompileCommand Cmd;
+ Cmd.CommandLine = {"clang-cl", "/std:c++latest", "--", "/Users/foo.cc"};
+ Mangler(Cmd, "/Users/foo.hpp");
+ // Check that the /std:c++latest flag is not dropped during inference
+ EXPECT_THAT(llvm::join(Cmd.CommandLine, " "), HasSubstr("/std:c++latest"));
+}
+
} // namespace
} // namespace clangd
} // namespace clang
diff --git a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
index 995019ca5a4d4..28568426a6c48 100644
--- a/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ b/clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -123,6 +123,15 @@ static types::ID foldType(types::ID Lang) {
}
}
+// Return the language standard that's activated by the /std:c++latest
+// flag in clang-CL mode.
+static LangStandard::Kind latestLangStandard() {
+ // FIXME: Have a single source of truth for the mapping from
+ // c++latest --> c++26 that's shared by the driver code
+ // (clang/lib/Driver/ToolChains/Clang.cpp) and this file.
+ return LangStandard::lang_cxx26;
+}
+
// A CompileCommand that can be applied to another file.
struct TransferableCommand {
// Flags that should not apply to all files are stripped from CommandLine.
@@ -237,9 +246,16 @@ struct TransferableCommand {
// --std flag may only be transferred if the language is the same.
// We may consider "translating" these, e.g. c++11 -> c11.
if (Std != LangStandard::lang_unspecified && foldType(TargetType) == Type) {
- Result.CommandLine.emplace_back((
- llvm::Twine(ClangCLMode ? "/std:" : "-std=") +
- LangStandard::getLangStandardForKind(Std).getName()).str());
+ const char *Spelling =
+ LangStandard::getLangStandardForKind(Std).getName();
+ // In clang-cl mode, the latest standard is spelled 'c++latest' rather
+ // than e.g. 'c++26', and the driver does not accept the latter, so emit
+ // the spelling that the driver does accept.
+ if (ClangCLMode && Std == latestLangStandard()) {
+ Spelling = "c++latest";
+ }
+ Result.CommandLine.emplace_back(
+ (llvm::Twine(ClangCLMode ? "/std:" : "-std=") + Spelling).str());
}
Result.CommandLine.push_back("--");
Result.CommandLine.push_back(std::string(Filename));
@@ -296,8 +312,14 @@ struct TransferableCommand {
// Try to interpret the argument as '-std='.
std::optional<LangStandard::Kind> tryParseStdArg(const llvm::opt::Arg &Arg) {
using namespace driver::options;
- if (Arg.getOption().matches(ClangCLMode ? OPT__SLASH_std : OPT_std_EQ))
+ if (Arg.getOption().matches(ClangCLMode ? OPT__SLASH_std : OPT_std_EQ)) {
+ // "c++latest" is not a recognized LangStandard, but it's accepted by
+ // the clang driver in CL mode.
+ if (ClangCLMode && StringRef(Arg.getValue()) == "c++latest") {
+ return latestLangStandard();
+ }
return LangStandard::getLangKind(Arg.getValue());
+ }
return std::nullopt;
}
};
|
This was referenced Sep 22, 2025
hokein
approved these changes
Sep 29, 2025
Base automatically changed from
users/HighCommander4/clangd-issue-1850-part1
to
main
September 30, 2025 06:49
RiverDave
pushed a commit
that referenced
this pull request
Oct 1, 2025
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes clangd/clangd#527
Fixes clangd/clangd#1850