aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-09-02 17:04:13 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2025-09-03 10:49:06 +0100
commit381dbd4a9564525d930737a790c9b7d31dfc181f (patch)
tree551cda518a27c1de4608efe538c2f3639515c614 /libstdc++-v3
parent9f94029829daf3b83bb95226dcfe003c5ddcade2 (diff)
downloadgcc-381dbd4a9564525d930737a790c9b7d31dfc181f.zip
gcc-381dbd4a9564525d930737a790c9b7d31dfc181f.tar.gz
gcc-381dbd4a9564525d930737a790c9b7d31dfc181f.tar.bz2
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 <tkaminsk@redhat.com>
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/version.def10
-rw-r--r--libstdc++-v3/include/bits/version.h9
-rw-r--r--libstdc++-v3/include/std/chrono13
-rw-r--r--libstdc++-v3/src/c++20/clock.cc2
4 files changed, 28 insertions, 6 deletions
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 <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 9d674b0..4af6504 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()