Fix cppstd_flag for clang-cl driver in C++23 / C++26 / gnu++ modes#19965
Open
HYUEHFJKhfjklkej wants to merge 1 commit into
Open
Fix cppstd_flag for clang-cl driver in C++23 / C++26 / gnu++ modes#19965HYUEHFJKhfjklkej wants to merge 1 commit into
cppstd_flag for clang-cl driver in C++23 / C++26 / gnu++ modes#19965HYUEHFJKhfjklkej wants to merge 1 commit into
Conversation
`clang-cl` mimics `cl.exe`'s `/std:` flag. The accepted values are a
fixed subset (`c++14`, `c++17`, `c++20`, `c++latest`, plus
`c++23preview` from clang-cl 22). For anything else — `c++23` on older
clang-cl, `c++26`, the pre-standard markers (`c++1y`, `c++2a`, `c++2b`)
and the `gnu++` extensions — the previous mechanical
`flag.replace("=", ":")` produced a `/std:` value that clang-cl rejects
with "argument unused during compilation".
Replace the blanket `=` -> `:` translation with a small helper that:
* emits `/std:c++14`, `/std:c++17`, `/std:c++20` when clang-cl accepts
them directly;
* emits `/std:c++23preview` only on clang-cl 22+ (the version that
introduced the alias);
* routes everything else through `-clang:-std=...` so the inner clang
frontend receives the original GCC-style flag — the documented
escape hatch for unsupported `/std:` values.
The previous code path was not unit-tested; this change adds explicit
coverage for the clang-cl driver, including the C++23 reproduction
from the bug report.
closes conan-io#19887
Member
|
This behavior was still not approved. Ticket #19887 is labeled as "look-into" which means this is still something that the team need to consider and decide how we want to handle it. It is not that clear that the desired direction is this one, so better wait until the team checks it. Thanks. |
memsharded
reviewed
May 20, 2026
Member
memsharded
left a comment
There was a problem hiding this comment.
Looking good, just one clarification, but I think it can be moved forward for next 2.29
| if value in ("c++14", "c++17", "c++20"): | ||
| return f"/std:{value}" | ||
| if value == "c++23" and clang_version >= "22": | ||
| return "/std:c++23preview" |
Member
There was a problem hiding this comment.
As commented in #19887 (comment), I am willing to move this forward, but it would be good to align with CMake in the behavior. Is there any disadvantage to keep the -clang:-std=c++23 syntax for this combination?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
clang-clmimicscl.exe's/std:flag. The driver accepts only asmall set of values:
/std:acceptsc++14,c++17,c++20,c++latest(+c11/c17)c++23previewThe previous mechanical
flag.replace("=", ":")translation incppstd_flagproduced/std:values that clang-cl rejects with"argument unused during compilation" for:
compiler.cppstd=23on any clang-cl version (/std:c++23is not avalid token);
compiler.cppstd=26(no/std:form exists yet);_cppstd_clangfor older clangs:c++1y,c++1z,c++2a,c++2b;gnu++extension (gnu++14,gnu++17, ...).Fix
Replace the blanket
=->:translation with a small helper that:/std:c++14,/std:c++17,/std:c++20when clang-cl acceptsthe value directly;
/std:c++23previewonly on clang-cl ≥ 22 (the version thatintroduced the alias for
-std=c++23);-clang:-std=...so the inner clangfrontend receives the original GCC-style flag — the documented escape
hatch for unsupported
/std:values.closes #19887
Test plan
The clang-cl branch in
cppstd_flagwas previously not covered by unittests. This PR adds explicit coverage:
pytest test/unittests/client/build/cpp_std_flags_test.pypytest test/unittests/tools/ test/unittests/client/build/Reference for the clang-cl
/std:values:https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html
Reference for the
-clang:passthrough:https://clang.llvm.org/docs/UsersManual.html#the-clang-cl-driver