From 381dbd4a9564525d930737a790c9b7d31dfc181f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 2 Sep 2025 17:04:13 +0100 Subject: libstdc++: Restore C++20 support for old std::string ABI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The r16-3416-g806de30f51c8b9 change to use __cpp_lib_chrono in preprocessor conditions broke support for for freestanding and the COW std::string ABI. That happened because __cpp_lib_chrono is only defined to the C++20 value for hosted and for the new ABI, because the full set of C++20 features are not defined for freestanding and tzdb is not defined for the old ABI. This introduces a new internal feature test macro that corresponds to the features that are always supported (e.g. chrono::local_time, chrono::year, chrono::weekday). libstdc++-v3/ChangeLog: * include/bits/version.def (chrono_cxx20): Define. * include/bits/version.h: Regenerate. * include/std/chrono: Check __glibcxx_chrono_cxx20 instead of __cpp_lib_chrono for C++20 features that don't require the new std::string ABI and/or can be used for freestanding. * src/c++20/clock.cc: Adjust preprocessor condition. Reviewed-by: Tomasz KamiƄski --- libstdc++-v3/include/bits/version.def | 10 ++++++++++ libstdc++-v3/include/bits/version.h | 9 +++++++++ libstdc++-v3/include/std/chrono | 13 ++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'libstdc++-v3/include') diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 84c755d..8707a12 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -595,6 +595,16 @@ ftms = { }; ftms = { + // Unofficial macro for C++20 chrono features supported for old string ABI. + name = chrono_cxx20; + values = { + v = 201800; + cxxmin = 20; + no_stdname = yes; + }; +}; + +ftms = { name = execution; values = { v = 201902; // FIXME: should be 201603L diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 410e320..c7569f4 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -665,6 +665,15 @@ #endif /* !defined(__cpp_lib_chrono) && defined(__glibcxx_want_chrono) */ #undef __glibcxx_want_chrono +#if !defined(__cpp_lib_chrono_cxx20) +# if (__cplusplus >= 202002L) +# define __glibcxx_chrono_cxx20 201800L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_chrono_cxx20) +# endif +# endif +#endif /* !defined(__cpp_lib_chrono_cxx20) && defined(__glibcxx_want_chrono_cxx20) */ +#undef __glibcxx_want_chrono_cxx20 + #if !defined(__cpp_lib_execution) # if (__cplusplus >= 201703L) && _GLIBCXX_HOSTED # define __glibcxx_execution 201902L diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index d1a01fb..f0207ea 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -53,11 +53,14 @@ #if __cpp_lib_bitops >= 201907L # include // __countr_zero #endif -#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED +#ifdef __glibcxx_chrono_cxx20 +# include // upper_bound +# include // begin/end for arrays +#endif +#if __cpp_lib_chrono >= 201803L // C++20 && HOSTED && USE_CXX11_ABI # include # include # include -# include // upper_bound # include # include #endif @@ -81,7 +84,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ namespace chrono { -#if __cpp_lib_chrono >= 201803L +#ifdef __glibcxx_chrono_cxx20 /// @addtogroup chrono /// @{ struct local_t { }; @@ -3319,7 +3322,7 @@ namespace __detail #endif // C++20 } // namespace chrono -#if __cpp_lib_chrono >= 201803L +#ifdef __glibcxx_chrono_cxx20 inline namespace literals { inline namespace chrono_literals @@ -3348,7 +3351,7 @@ namespace __detail _GLIBCXX_END_NAMESPACE_VERSION } // namespace std -#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED +#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED # include #endif -- cgit v1.1