cast: silence warnings when lossless casting to smaller sized enums

This commit is contained in:
Danny Robson 2018-12-06 15:58:23 +11:00
parent 9eb2784d84
commit 98e9fe45c4

View File

@ -116,9 +116,16 @@ namespace cruft::cast {
// is lossless. // is lossless.
CHECK_EQ (static_cast<SrcT> (dst), src); CHECK_EQ (static_cast<SrcT> (dst), src);
return dst; return dst;
#else #else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
if constexpr (std::is_enum_v<DstT>) {
auto const val = static_cast<std::underlying_type_t<DstT>> (src);
return static_cast<DstT> (val);
} else {
return static_cast<DstT> (src); return static_cast<DstT> (src);
}
#pragma GCC diagnostic pop
#endif #endif
} }