[cfe-dev] ARC + goto into protected scope error

John McCall rjmccall at apple.com
Thu Aug 16 19:10:20 PDT 2012


On Aug 16, 2012, at 6:47 PM, Dave Keck wrote:
> 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.

This restriction is not likely to be lifted;  there are a number of challenges
with branches that enter scopes.

I assume your failure label is always at the end of the function;  in that case,
you can wrap everything up to that point in curly braces, like so:

- (void) broadcastChanges {
  {
    if (self.error) goto failure;
    NSString *foo = self.name;
    [self broadcastName: foo];
    return;
  }
  failure:
  abort();  
}

You might also consider moving to a structural programming pattern.

John.



More information about the cfe-dev mailing list