On Aug 15, 2014, at 20:31 , Antonio Nunes <email@hidden> wrote:
You do have a variable declaration: within the switch statement: "id const browser = [PrBrowserController createPagelessBrowser];” You have to put braces around the statements in a case statement, if you’re declaring variables:
I’m not a C language lawyer, but AFAIK this isn’t an accurate statement.
The declaration you refer to isn’t *in* the switch statement’s scope. IAC:
— There’s no prohibition on declarations inside switch cases, except that a case can’t *begin* with a declaration. For example, I’ve seen code like this:
switch (i) { case 0:; int j = i; … }
The redundant empty statement bumps the declaration to being the *second* statement of the case. That’s an alternate solution to the braces.
— The error message here is not about an illegal declaration, but a protected scope. This refers to the fact that the switch's scope can be entered somewhere other than the top, which means that initializations of variables declared in the scope might be skipped.
— Searching the internet for this error message leads in one case to clang’s ‘TransProtectedScope.cpp’ function, which suggests (vaguely) that the actual problem relates to the implicit ARC-retaining of something in the scope, perhaps the block itself. I'd speculate that the compiler puts the matching release at the closing brace, which would indeed be a protected scope error, since it would try to release something that never was retained (or even created) in the ‘default’ case.
Whether the error is itself a compiler bug, well, that does seem a murky question. In this scenario, considering what the cases are, using an ‘if’ instead seems like the neatest solution.
|