Commit d08e987e authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

base/numerics: Add explicit cast to SafeUnsignedAbs

This was showing up as a -Wconversion error on gcc, when used via
saturated_cast<int16_t>(...).

Change-Id: Ie643478c1678387ddc4b0386998c77bd74d92700
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008277Reviewed-by: default avatarJustin Schuh <jschuh@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734082}
parent 924ef3c0
......@@ -80,8 +80,9 @@ template <typename T>
constexpr typename std::make_unsigned<T>::type SafeUnsignedAbs(T value) {
static_assert(std::is_integral<T>::value, "Type must be integral");
using UnsignedT = typename std::make_unsigned<T>::type;
return IsValueNegative(value) ? 0 - static_cast<UnsignedT>(value)
: static_cast<UnsignedT>(value);
return IsValueNegative(value)
? static_cast<UnsignedT>(0u - static_cast<UnsignedT>(value))
: static_cast<UnsignedT>(value);
}
// This allows us to switch paths on known compile-time constants.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment