I'm reviewing a lot of code where I need to ensure there are no static_cast (or any cast) calls on variables that could be out of range of the enum class that is being cast to. Ideally I'd be able to receive a warning or have some way to detect code that is casting from, for example, an int when the enum class in question has an underlying type of unsigned char.
enum class some_enum_class : unsigned char
{
SomeVal,
};
int BadVal = 1000;
auto EnumVar = static_cast<some_enum_class>(BadVal); //Trigger Warning!
Is there any way to accomplish this? (hopefully in MSVC?)