diff --git a/src/serialize.h b/src/serialize.h index 7ee9556dc1..a44cc2c001 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -538,14 +538,15 @@ struct CustomUintFormatter template void Unser(Stream& s, I& v) { - static_assert(std::numeric_limits::max() >= MAX && std::numeric_limits::min() <= 0, "CustomUintFormatter type too small"); + using U = typename std::conditional::value, std::underlying_type, std::common_type>::type::type; + static_assert(std::numeric_limits::max() >= MAX && std::numeric_limits::min() <= 0, "Assigned type too small"); uint64_t raw = 0; if (BigEndian) { s.read(((char*)&raw) + 8 - Bytes, Bytes); - v = be64toh(raw); + v = static_cast(be64toh(raw)); } else { s.read((char*)&raw, Bytes); - v = le64toh(raw); + v = static_cast(le64toh(raw)); } } };