[cfe-dev] ARC + goto into protected scope error
Jordan Rose
jordan_rose at apple.com
Thu Aug 16 18:56:50 PDT 2012
If you put the variable in its own scope, preventing accidental access, you won't get the error:
int main() {
goto cleanup;
{
NSString *str;
}
cleanup:
return 0;
}
If you don't do this, you bypass the zero-initialization of 'str', and when ARC tries to clean it up, it'll end up trying to release some random bit of memory.
This should handle any valid case; if you want to use 'goto' but can't enclose the variables in their own scope, you'll have to move the declarations before the goto (as K&R intended *grin*).
Jordan
On Aug 16, 2012, at 18:47 , Dave Keck <davekeck at gmail.com> wrote:
> Hi all,
>
> I use the "check for success/goto failed" pattern everywhere, but
> Clang refuses to compile such code with ARC enabled if the goto
> bypasses a variable declaration (giving a "goto into protected scope"
> error.)
>
> Is this something that's likely to be fixed? Compiling the program
> below triggers the error.
>
> // compile with: clang -framework Foundation -fobjc-arc <file>.m
> #import <Foundation/Foundation.h>
> int main() {
> goto cleanup;
> NSString *str;
> cleanup:
> return 0;
> }
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list