Make lcm/gcd work better in edge cases. Fixes a UBSAN failure.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294779 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2017-02-10 20:49:08 +00:00
parent 00d9a944af
commit ebf66a385f
6 changed files with 52 additions and 28 deletions

View File

@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: c++98, c++03, c++11, c++14
// XFAIL: ubsan
// <numeric>
// template<class _M, class _N>
@@ -132,8 +131,9 @@ int main()
// LWG#2837
{
auto res = std::lcm((int64_t)1234, (int32_t)-2147483648);
static_assert( std::is_same<decltype(res), std::common_type<int64_t, int32_t>::type>::value, "");
assert(res == -1324997410816LL);
auto res1 = std::lcm((int64_t)1234, (int32_t)-2147483648);
(void) std::lcm<int, unsigned long>(INT_MIN, 2); // this used to trigger UBSAN
static_assert( std::is_same<decltype(res1), std::common_type<int64_t, int32_t>::type>::value, "");
assert(res1 == 1324997410816LL);
}
}