https://gcc.gnu.org/g:381dbd4a9564525d930737a790c9b7d31dfc181f

commit r16-3535-g381dbd4a9564525d930737a790c9b7d31dfc181f
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Tue Sep 2 17:04:13 2025 +0100

    libstdc++: Restore C++20 <chrono> support for old std::string ABI
    
    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 <tkami...@redhat.com>

Diff:
---
 libstdc++-v3/include/bits/version.def | 10 ++++++++++
 libstdc++-v3/include/bits/version.h   |  9 +++++++++
 libstdc++-v3/include/std/chrono       | 13 ++++++++-----
 libstdc++-v3/src/c++20/clock.cc       |  2 +-
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 84c755da10e2..8707a123109f 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -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 = {
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 410e3205339d..c7569f42773c 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 d1a01fbdf0a8..f0207eaae8e0 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -53,11 +53,14 @@
 #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
 
diff --git a/libstdc++-v3/src/c++20/clock.cc b/libstdc++-v3/src/c++20/clock.cc
index 9d674b0b46a2..4af65046e1f8 100644
--- a/libstdc++-v3/src/c++20/clock.cc
+++ b/libstdc++-v3/src/c++20/clock.cc
@@ -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()

Reply via email to