This isn't quite the minimum possible reproduction, but hopefully illustrates the issue well while being bite-sized.
#include <iostream>
int main(int, char **)
{
int i;
std::cin >> i;
switch(i)
{
case 0:
break;
std::cout << "too small" << std::endl;
case 1:
break;
default:
std::cout << "too large" << std::endl;
break;
}
return 0;
}
The problem here, of course, is that the user has added code to a switch statement after the break instead of before it. (Of course in a real example there would have been preexisting code prior to the break statement)
clang is able to detect this with the -Wunreachable-code
flag, and MSVC is able to detect it with /Wall
, but I haven't found a way to get g++ to warn about this.
g++ does have a flag -Wswitch-unreachable
, but that only catches code that appears prior to the first switch label, so it's of no help here.