libstdc++: Fix chrono::__detail::ceil to work with C++11 (was Re: [PATCH v5 6/8] libstdc++ atomic_futex: Avoid rounding errors in std::future::wait_* [PR91486])

Mike Crowe mac@mcrowe.com
Sat Sep 19 10:37:49 GMT 2020


On Friday 11 September 2020 at 19:59:36 +0100, Jonathan Wakely wrote:
> commit 53ad6b1979f4bd7121e977c4a44151b14d8a0147
> Author: Jonathan Wakely <jwakely@redhat.com>
> Date:   Fri Sep 11 19:59:11 2020
> 
>     libstdc++: Fix chrono::__detail::ceil to work with C++11
>     
>     In C++11 constexpr functions can only have a return statement, so we
>     need to fix __detail::ceil to make it valid in C++11. This can be done
>     by moving the comparison and increment into a new function, __ceil_impl,
>     and calling that with the result of the duration_cast.
>     
>     This would mean the standard C++17 std::chrono::ceil function would make
>     two further calls, which would add too much overhead when not inlined.
>     For C++17 and later use a using-declaration to add chrono::ceil to
>     namespace __detail. For C++11 and C++14 define chrono::__detail::__ceil
>     as a C++11-compatible constexpr function template.
>
>
>     libstdc++-v3/ChangeLog:
>     
>             * include/std/chrono [C++17] (chrono::__detail::ceil): Add
>             using declaration to make chrono::ceil available for internal
>             use with a consistent name.
>             (chrono::__detail::__ceil_impl): New function template.
>             (chrono::__detail::ceil): Use __ceil_impl to compare and
>             increment the value. Remove SFINAE constraint.

This change introduces a new implementation of ceil that, as far as I can
tell, has no tests. A patch is attached to add the equivalent of the
existing chrono::ceil tests for chrono::__detail::ceil. The tests fail to
compile if I run them without 53ad6b1979f4bd7121e977c4a44151b14d8a0147 as
expected due to the previous non-C++11-compliant implementation.

Mike.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libstdc-Test-C-11-implementation-of-std-chrono-__det.patch
Type: text/x-diff
Size: 3166 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20200919/29c8655a/attachment.bin>


More information about the Libstdc++ mailing list