From: Jonathan Wakely Date: Thu, 13 Oct 2016 14:42:09 +0000 (+0100) Subject: Replace non-constexpr decrement in std::chrono::floor X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0c0d2a4cf0fbad6cb92dcf666b24fde8fac8b104;p=gcc.git Replace non-constexpr decrement in std::chrono::floor * include/std/chrono (floor): Replace non-constexpr operation. * testsuite/20_util/duration_cast/rounding.cc: Test conversion to durations with floating pointer representations. From-SVN: r241122 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1dac9caa868..5a8153498f4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2016-10-13 Jonathan Wakely + * include/std/chrono (floor): Replace non-constexpr operation. + * testsuite/20_util/duration_cast/rounding.cc: Test conversion to + durations with floating pointer representations. + * src/c++11/compatibility-thread-c++0x.cc (_Bind_simple) (_Bind_simple_helper, __bind_simple): Restore for ABI compat symbols. diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index cb8c8765183..ceae7f805c1 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -224,7 +224,7 @@ _GLIBCXX_END_NAMESPACE_VERSION { auto __to = chrono::duration_cast<_ToDur>(__d); if (__to > __d) - --__to; + return __to - _ToDur{1}; return __to; } diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc index a7533230273..2a1df7478d4 100644 --- a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc +++ b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc @@ -27,6 +27,8 @@ using namespace std::chrono_literals; using std::chrono::seconds; +using fp_seconds = std::chrono::duration; + static_assert( std::chrono::floor(1000ms) == 1s ); static_assert( std::chrono::floor(1001ms) == 1s ); static_assert( std::chrono::floor(1500ms) == 1s ); @@ -34,6 +36,7 @@ static_assert( std::chrono::floor(1999ms) == 1s ); static_assert( std::chrono::floor(2000ms) == 2s ); static_assert( std::chrono::floor(2001ms) == 2s ); static_assert( std::chrono::floor(2500ms) == 2s ); +static_assert( std::chrono::floor(500ms) == fp_seconds{0.5f} ); static_assert( std::chrono::ceil(1000ms) == 1s ); static_assert( std::chrono::ceil(1001ms) == 2s ); @@ -42,6 +45,7 @@ static_assert( std::chrono::ceil(1999ms) == 2s ); static_assert( std::chrono::ceil(2000ms) == 2s ); static_assert( std::chrono::ceil(2001ms) == 3s ); static_assert( std::chrono::ceil(2500ms) == 3s ); +static_assert( std::chrono::ceil(500ms) == fp_seconds{0.5f} ); static_assert( std::chrono::round(1000ms) == 1s ); static_assert( std::chrono::round(1001ms) == 1s );