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
This commit is contained in:
Marshall Clow
2019-07-26 15:10:46 +00:00
parent d0ad5eb1bf
commit 4bd3f7d588
2 changed files with 7 additions and 1 deletions

View 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

View 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;
}