Fix a bug in std::chrono::abs where it would fail when the duration's period had...
authorMarshall Clow <mclow.lists@gmail.com>
Fri, 26 Jul 2019 15:10:46 +0000 (15:10 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Fri, 26 Jul 2019 15:10:46 +0000 (15:10 +0000)
llvm-svn: 367120

libcxx/include/chrono
libcxx/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp

index 06fa658..51722ad 100644 (file)
@@ -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
 
index 605e27c..8f5544f 100644 (file)
@@ -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;
 }