rdrand: silence a type conversion warning under clang

This commit is contained in:
Danny Robson 2019-07-29 11:20:09 +10:00
parent 2d9a7109b1
commit e723684347

View File

@ -40,5 +40,9 @@ rdrand::operator() ()
if (!__builtin_expect(success, 1))
throw std::runtime_error ("no value available for rdrand");
return res;
// As long as the u64 we just grabbed is of a type we can truncate then
// we'll do just that and return it.
static_assert (sizeof (result_type) <= sizeof (res));
static_assert (std::is_signed_v<result_type> == std::is_signed_v<decltype(res)>);
return static_cast<result_type> (res);
}