[PATCH] libstdc++: Fix missing __to_timeout_timespec for targets using POSIX sleep
Tomasz Kaminski
tkaminsk@redhat.com
Wed Oct 15 14:04:41 GMT 2025
On Wed, Oct 15, 2025 at 3:01 PM Tomasz Kaminski <tkaminsk@redhat.com> wrote:
>
>
> On Wed, Oct 15, 2025 at 2:17 PM Jonathan Wakely <jwakely@redhat.com>
> wrote:
>
>> 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:
>>
>> * 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.
>> ---
>>
>> Bootstrapped arm-eabi, testing on powerpc64le-linux now.
>>
> Do we need to even try to ifdef this function, it's template and would not
> be instantiated.
> Except ::timespec, there seems to be nothing that it would depend on that
> wouldn't be generally available.
>
>From out of list discussion: These conditions are meant to replicate
situations, when we require that timespec
to be defined. It is included in c++17 or later. so for C++11 we aim to
require it only when it was already used.
LGTM.
>
>
> libstdc++-v3/include/bits/chrono.h | 4 ++--
> libstdc++-v3/include/bits/this_thread_sleep.h | 1 -
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/chrono.h
> b/libstdc++-v3/include/bits/chrono.h
> index 7f505aa0f0ff..2b0550b15f76 100644
> --- a/libstdc++-v3/include/bits/chrono.h
> +++ b/libstdc++-v3/include/bits/chrono.h
> @@ -1515,8 +1515,8 @@ _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 ! defined _GLIBCXX_NO_SLEEP || defined _GLIBCXX_HAS_GTHREADS \
> + || _GLIBCXX_HAVE_LINUX_FUTEX
> namespace chrono
> {
> /// @cond undocumented
> diff --git a/libstdc++-v3/include/bits/this_thread_sleep.h
> b/libstdc++-v3/include/bits/this_thread_sleep.h
> index 01f25dda2af0..7c9d573d86d8 100644
> --- a/libstdc++-v3/include/bits/this_thread_sleep.h
> +++ b/libstdc++-v3/include/bits/this_thread_sleep.h
> @@ -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
> --
> 2.51.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20251015/f7e05bdc/attachment-0001.htm>
More information about the Libstdc++
mailing list