[libcxx-commits] [libcxx] r367120 - Fix a bug in std::chrono::abs where it would fail when the duration's period had not been reduced.s
Marshall Clow via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 26 08:10:46 PDT 2019
Author: marshall
Date: Fri Jul 26 08:10:46 2019
New Revision: 367120
URL: http://llvm.org/viewvc/llvm-project?rev=367120&view=rev
Log:
Fix a bug in std::chrono::abs where it would fail when the duration's period had not been reduced.s
Modified:
libcxx/trunk/include/chrono
libcxx/trunk/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp
Modified: libcxx/trunk/include/chrono
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/chrono?rev=367120&r1=367119&r2=367120&view=diff
==============================================================================
--- libcxx/trunk/include/chrono (original)
+++ libcxx/trunk/include/chrono Fri Jul 26 08:10:46 2019
@@ -1428,7 +1428,7 @@ typename enable_if
>::type
abs(duration<_Rep, _Period> __d)
{
- return __d >= __d.zero() ? __d : -__d;
+ return __d >= __d.zero() ? +__d : -__d;
}
#endif
Modified: libcxx/trunk/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp?rev=367120&r1=367119&r2=367120&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp Fri Jul 26 08:10:46 2019
@@ -49,5 +49,11 @@ int main(int, char**)
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;
}
More information about the libcxx-commits
mailing list