I've come across an error that I thought should have been a warning:
char* p;
int main()
{
if (p) goto continue_func;
int a = 3;
continue_func:
int b = 2;
}
The error I get:
initialization of 'a' is skipped by 'goto continue_func'
transfer of control bypasses initialization of:
I don't see why this is illegal. If the case had been something like this:
char* p;
int main()
{
if (p) goto continue_func;
int a = 3;
continue_func:
int b = 2;
int c = a + b;
std::cout << c;
}
Then I understand that a is being used. But in the first example it's not. Is this truly illegal C++, and why?