Skip to content

Commit bbc80ab

Browse files
committed
proxy-types.h: add static_assert to detect when an int fields is too small to hold an enum value
1 parent abe254b commit bbc80ab

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/mp/proxy-types.h

+3
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@ LocalType BuildPrimitive(InvokeContext& invoke_context,
963963
TypeList<LocalType>,
964964
typename std::enable_if<std::is_enum<Value>::value>::type* enable = nullptr)
965965
{
966+
using E = std::make_unsigned_t<std::underlying_type_t<Value>>;
967+
using T = std::make_unsigned_t<LocalType>;
968+
static_assert(std::numeric_limits<T>::max() >= std::numeric_limits<E>::max(), "mismatched integral/enum types");
966969
return static_cast<LocalType>(value);
967970
}
968971

0 commit comments

Comments
 (0)