I've inherited a very old (+15 years old) C++ program currently running on AIX using IBM's xlc compiler. I came across a switch statement and I don't understand how this ever worked.
Below is a minimal example that shows the situation.
#include <iostream>
using namespace std;
int main()
{
int i=5;
switch( i ) {
case 1:
cout << "case " << i << endl;
break;
case 2:
cout << "case " << i << endl;
break;
Otherwise:
cout << "case " << i << endl;
break;
}
cout << "bye\n";
}
I'm using GCC 7.3.1 on Amazon Linux 2. The program compiles fine and shows this output is:
bye
If I add "-Wall", then it tells me the following:
minex.C: In function ‘int main()’:
minex.C:15:3: warning: label ‘Otherwise’ defined but not used [-Wunused-label]
Otherwise:
^~~~~~~~~
Questions:
Why isn't this a syntax error?
Don't the case labels have to follow the form "case n:" where n is an integer expression or "default:" (or a constant String expression, but that doesn't seem relevant here?
Can someone please point me to a reference that says this is supposed to be allowed?