]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix missing __to_timeout_timespec for targets using POSIX sleep [PR122293]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 15 Oct 2025 11:52:27 +0000 (12:52 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 15 Oct 2025 20:54:56 +0000 (21:54 +0100)
The preprocessor condition for defining the new __to_timeout_timespec
function templates did not match all the conditions under which it's
needed.

std::this_thread::sleep_for is defined #if ! defined _GLIBCXX_NO_SLEEP
but it relies on __to_timeout_timespec which was only being defined for
targets that use nanosleep, or clock_gettime, or use gthreads.

For a non-gthreads target that uses POSIX sleep to implement
std::this_thread::sleep_for, the build fails with:

include/bits/this_thread_sleep.h:71:40: error: '__to_timeout_timespec' is not a member of 'std::chrono' [-Wtemplate-body]
   71 |         struct timespec __ts = chrono::__to_timeout_timespec(__rtime);
      |                                        ^~~~~~~~~~~~~~~~~~~~~

Presumably the same would happen for mingw-w64 if configured with
--disable-threads (as that would be a non-gthreads target that doesn't
use nanosleep or clock_gettime).

libstdc++-v3/ChangeLog:

PR libstdc++/122293
* include/bits/chrono.h (__to_timeout_timespec): Fix
preprocessor condition to match the conditions under which
callers of this function are defined.
* include/bits/this_thread_sleep.h: Remove unused include.

libstdc++-v3/include/bits/chrono.h
libstdc++-v3/include/bits/this_thread_sleep.h

index 7f505aa0f0fff6084cbacfcad9cdd4056bf4f280..4dc399855165b8a7c7cb13d642d44b5380daabb8 100644 (file)
@@ -1515,8 +1515,9 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
   } // namespace filesystem
 #endif // C++17 && HOSTED
 
-#if defined _GLIBCXX_USE_NANOSLEEP || defined _GLIBCXX_USE_CLOCK_REALTIME \
-    || defined _GLIBCXX_HAS_GTHREADS
+#if _GLIBCXX_HOSTED
+#if ! defined _GLIBCXX_NO_SLEEP || defined _GLIBCXX_HAS_GTHREADS \
+    || _GLIBCXX_HAVE_LINUX_FUTEX
 namespace chrono
 {
 /// @cond undocumented
@@ -1585,7 +1586,8 @@ namespace chrono
 
 /// @endcond
 } // namespace chrono
-#endif // USE_NANOSLEEP || USE_CLOCK_REALTIME || HAS_GTHREADS
+#endif // !NO_SLEEP || HAS_GTHREADS || HAVE_LINUX_FUTEX
+#endif // HOSTED
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
index 01f25dda2af0750f2d880e1abe9fb519c6ee68fc..7c9d573d86d87f42f773e298be0e247343d5b385 100644 (file)
@@ -36,7 +36,6 @@
 
 #if __cplusplus >= 201103L
 #include <bits/chrono.h> // std::chrono::*
-#include <ext/numeric_traits.h> // __int_traits
 
 #ifdef _GLIBCXX_USE_NANOSLEEP
 # include <cerrno>  // errno, EINTR