]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Restore C++20 <chrono> support for old std::string ABI
authorJonathan Wakely <jwakely@redhat.com>
Tue, 2 Sep 2025 16:04:13 +0000 (17:04 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 3 Sep 2025 09:49:06 +0000 (10:49 +0100)
The r16-3416-g806de30f51c8b9 change to use __cpp_lib_chrono in
preprocessor conditions broke support for <chrono> 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 <tkaminsk@redhat.com>
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/chrono
libstdc++-v3/src/c++20/clock.cc

index 84c755da10e224e87e512e0914a87cda18055182..8707a123109fef3051e806fbcc12c405fb1fbafc 100644 (file)
@@ -594,6 +594,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 = {
index 410e3205339dfee224015f56d62cf255e52888f3..c7569f42773c5aa0c97f95b88439926ed28f34ba 100644 (file)
 #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
index d1a01fbdf0a87502e7b2aaec30bce7bec9d099b0..f0207eaae8e0a23ffbe8112a740888d9c53617b7 100644 (file)
 #if __cpp_lib_bitops >= 201907L
 # include <bit> // __countr_zero
 #endif
-#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED
+#ifdef __glibcxx_chrono_cxx20
+# include <bits/stl_algo.h>     // upper_bound
+# include <bits/range_access.h> // begin/end for arrays
+#endif
+#if __cpp_lib_chrono >= 201803L // C++20 && HOSTED && USE_CXX11_ABI
 # include <sstream>
 # include <string>
 # include <vector>
-# include <bits/stl_algo.h> // upper_bound
 # include <bits/shared_ptr.h>
 # include <bits/unique_ptr.h>
 #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 <bits/chrono_io.h>
 #endif
 
index 9d674b0b46a228fe4aab2699b971bf277dd4df75..4af65046e1f88c0c15de462df3b2fdd73795e205 100644 (file)
@@ -35,7 +35,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 namespace chrono
 {
-#if __cpp_lib_chrono >= 201803L && _GLIBCXX_HOSTED
+#if defined __glibcxx_chrono_cxx20 && _GLIBCXX_HOSTED
   // TODO use CLOCK_TAI on linux, add extension point.
   time_point<tai_clock>
   tai_clock::now()