From this FAQ: What are Aggregates and PODs and how/why are they special?
We have this part:
goto statement. As you may know, it is illegal (the compiler should issue an error) to make a jump via goto from a point where some variable was not yet in scope to a point where it is already in scope. This restriction applies only if the variable is of non-POD type. In the following example f() is ill-formed whereas g() is well-formed. Note that Microsoft compiler is too liberal with this rule - just issues a warning in both cases.
int f() {
struct NonPOD { NonPOD(){}};
goto label;
NonPOD x;
label:
return 0;
}
int g(){
struct POD {int i; char c;};
goto label;
POD x;
label:
return 0;
}
I'd like to understand why the difference? It seems like it could be that even though the POD is declared after the goto it is already initialized and nothing more needs to be done whereas the non-POD is not initialized. Or am I barking up the wrong tree?