From 1a04d1330e680c5d6c2be4a7a82facc955f19e06 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 1 May 2017 14:21:51 +1000 Subject: [PATCH] verify_types: add type static assertions --- src/util/verify_types.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/verify_types.h b/src/util/verify_types.h index 148b4377..5833d5ec 100644 --- a/src/util/verify_types.h +++ b/src/util/verify_types.h @@ -33,16 +33,25 @@ #include "util/compile_error.h" #include +#include namespace ue2 { template To_T verify_cast(From_T val) { + static_assert(std::is_integral::value, + "Output type must be integral."); + static_assert(std::is_integral::value || + std::is_enum::value || + std::is_convertible::value, + "Must be integral or enum type, or convertible to output."); + To_T conv_val = static_cast(val); if (static_cast(conv_val) != val) { assert(0); throw ResourceLimitError(); } + return conv_val; }