GCC / Clang
You are looking for -Wswitch-enum.
Warn whenever a switch statement has an index of enumerated type and
lacks a case for one or more of the named codes of that enumeration.
case labels outside the enumeration range also provoke warnings when
this option is used. The only difference between -Wswitch and this
option is that this option gives a warning about an omitted
enumeration code even if there is a default label.
const std::string ToString(OS_type v)
{
// warning: enumeration value 'Windows' not handled in switch [-Wswitch-enum]
switch (v)
{
case OS_type::Linux: return "Linux";
case OS_type::Apple: return "Apple";
default: return "[Unknown OS_type]";
}
}
Even default is used, it complains about the missing Windows enum. Just create the case for Windows and make a fallthrough to the default to suppress the enum.
Visual Studio
VS handles this at compiler level 3 and 4. You need to enable warning C4061 / C4062
. https://msdn.microsoft.com/en-US/library/96f5t7fy.aspx