Is it allowed to jump to a label that's inside an inner scope or a sibling scope? If so, is it allowed to use variables declared in that scope?
Consider this code:
int cond(void);
void use(int);
void foo()
{
{
int y = 2;
label:
use(y);
}
{
int z = 3;
use(z);
/* jump to sibling scope: */ if(cond()) goto label;
}
/* jump to inner scope: */ if(cond()) goto label;
}
Are these goto
s legal?
If so, is y
guaranteed to exist when I jump to label
and to hold the last value assigned to it (2
)?
Or is the compiler allowed to assume y
won't be used after it goes out of scope, which means a single memory location may be used for both y
and z
?
If this code's behavior is undefined, how can I get GCC to emit a warning about it?