MSVC warning for potentially uninitialized variables is not particularly good, in particular it falsely claims that i can be uninitialized in this program:
#include<cstdlib>
enum class Color{
Red,
Green
};
int f(Color c){
int i;
switch(c){
case Color::Red:
i=11;
case Color::Green:
i=22;
};
return i;
}
int main(){
return f(rand()?Color::Red : Color::Green);
}
warning C4701: potentially uninitialized local variable 'i' used
I can obviously just initialize the i to 0 or disable warnings with pargmas, but then this warning will not fire if I add enum Blue and I never handle it in switch and I want it to fire in that case.
Is there any way to make this MSVC warning work as expected?