|
|
@ -1270,16 +1270,28 @@ class ValueType : public Value {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check for integer overflow.
|
|
|
|
// Check for integer overflow.
|
|
|
|
|
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
|
|
|
|
if (std::is_signed_v<I> == std::is_signed_v<decltype(a)>) {
|
|
|
|
|
|
|
|
#else
|
|
|
|
if (std::is_signed<I>::value == std::is_signed<decltype(a)>::value) {
|
|
|
|
if (std::is_signed<I>::value == std::is_signed<decltype(a)>::value) {
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// conversion does not change sign
|
|
|
|
// conversion does not change sign
|
|
|
|
const auto imin = std::numeric_limits<I>::min();
|
|
|
|
const auto imin = std::numeric_limits<I>::min();
|
|
|
|
const auto imax = std::numeric_limits<I>::max();
|
|
|
|
const auto imax = std::numeric_limits<I>::max();
|
|
|
|
if (imax < b || a < imin || imax < a) {
|
|
|
|
if (imax < b || a < imin || imax < a) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
|
|
|
|
} else if (std::is_signed_v<I>) {
|
|
|
|
|
|
|
|
#else
|
|
|
|
} else if (std::is_signed<I>::value) {
|
|
|
|
} else if (std::is_signed<I>::value) {
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// conversion is from unsigned to signed
|
|
|
|
// conversion is from unsigned to signed
|
|
|
|
|
|
|
|
#if __cplusplus >= 201402L
|
|
|
|
|
|
|
|
const auto imax = std::make_unsigned_t<I>(std::numeric_limits<I>::max());
|
|
|
|
|
|
|
|
#else
|
|
|
|
const auto imax = typename std::make_unsigned<I>::type(std::numeric_limits<I>::max());
|
|
|
|
const auto imax = typename std::make_unsigned<I>::type(std::numeric_limits<I>::max());
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if (imax < b || imax < a) {
|
|
|
|
if (imax < b || imax < a) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1290,8 +1302,13 @@ class ValueType : public Value {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Inputs are not negative so convert them to unsigned.
|
|
|
|
// Inputs are not negative so convert them to unsigned.
|
|
|
|
|
|
|
|
#if __cplusplus >= 201402L
|
|
|
|
|
|
|
|
const auto a_u = std::make_unsigned_t<decltype(a)>(a);
|
|
|
|
|
|
|
|
const auto b_u = std::make_unsigned_t<decltype(b)>(b);
|
|
|
|
|
|
|
|
#else
|
|
|
|
const auto a_u = typename std::make_unsigned<decltype(a)>::type(a);
|
|
|
|
const auto a_u = typename std::make_unsigned<decltype(a)>::type(a);
|
|
|
|
const auto b_u = typename std::make_unsigned<decltype(b)>::type(b);
|
|
|
|
const auto b_u = typename std::make_unsigned<decltype(b)>::type(b);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if (imax < b_u || imax < a_u) {
|
|
|
|
if (imax < b_u || imax < a_u) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|