Fall back to -std=c++2a on compilers without -std=c++20 - #105
Open
bernardladenthin wants to merge 1 commit into
Open
Fall back to -std=c++2a on compilers without -std=c++20#105bernardladenthin wants to merge 1 commit into
bernardladenthin wants to merge 1 commit into
Conversation
GCC 8 implements C++20 under the pre-release spelling only. CMake still lists cxx_std_20 as supported there because it maps the feature onto -std=c++2a, so the feature list cannot tell us which spelling the compiler accepts. Probe the flag itself instead.
This was referenced Aug 1, 2026
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.
Problem
test/CMakeLists.txtcompilestest20.cppwith a hardcoded-std=c++20. GCC 8 — stillthe system compiler on RHEL 8 and its rebuilds — only implements C++20 under the
pre-release spelling and rejects the flag outright:
The test suite therefore cannot be built with it at all, although the library itself
compiles fine.
Fix
Probe the flag instead of the CMake feature.
CMAKE_CXX_COMPILE_FEATURESlistscxx_std_20on GCC 8, because CMake maps that feature onto-std=c++2a— so the featurelist cannot tell us which spelling the compiler accepts.
check_cxx_compiler_flagcan,and
-std=c++2ais used where-std=c++20is unknown.This keeps
test20.cppa real C++20 translation unit on those compilers, rather thansilently falling back to the default standard.
Testing
Ubuntu 20.04 (glibc 2.31, so the library builds there regardless of #104), with
g++-88.4.0:
test20.cpp:unrecognized command line option '-std=c++20'Regression checks, all unchanged:
On MSVC the probe correctly reports failure —
cl.exeonly warns (D9002: ignoring unknown option), but CMake's built-in fail patterns catch that. The-std=c++2afallback is then discarded anyway, because
subprocess_set_cxx_flagsskips the standardflag whenever
SUBPROCESS_CXX_USE_STD_FLAGis false.