commit | 4bd3f7d5883fe12c8b0aa22d956d424d5a594cfc | [log] [tgz] |
---|---|---|
author | Marshall Clow <mclow.lists@gmail.com> | Fri Jul 26 15:10:46 2019 +0000 |
committer | Marshall Clow <mclow.lists@gmail.com> | Fri Jul 26 15:10:46 2019 +0000 |
tree | 23451b052c39611db97bce53a457377e5e8388d4 | |
parent | d0ad5eb1bf8ba3703489856c05ec108d99b539d8 [diff] |
Fix a bug in std::chrono::abs where it would fail when the duration's period had not been reduced.s git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@367120 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/chrono b/include/chrono index 06fa658..51722ad 100644 --- a/include/chrono +++ b/include/chrono
@@ -1428,7 +1428,7 @@ >::type abs(duration<_Rep, _Period> __d) { - return __d >= __d.zero() ? __d : -__d; + return __d >= __d.zero() ? +__d : -__d; } #endif
diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp index 605e27c..8f5544f 100644 --- a/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp
@@ -49,5 +49,11 @@ static_assert(h2.count() == 3, ""); } + { +// Make sure it works for durations that are not LCD'ed - example from LWG3091 + constexpr auto d = std::chrono::abs(std::chrono::duration<int, std::ratio<60, 100>>{2}); + static_assert(d.count() == 2, ""); + } + return 0; }