• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I think I wrongly got "Switch case is in protected scope"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think I wrongly got "Switch case is in protected scope"


  • Subject: Re: I think I wrongly got "Switch case is in protected scope"
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 15 Aug 2014 21:25:52 -0700

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.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: I think I wrongly got "Switch case is in protected scope"
      • From: Antonio Nunes <email@hidden>
References: 
 >I think I wrongly got "Switch case is in protected scope" (From: Daryle Walker <email@hidden>)
 >Re: I think I wrongly got "Switch case is in protected scope" (From: Antonio Nunes <email@hidden>)

  • Prev by Date: Re: I think I wrongly got "Switch case is in protected scope"
  • Next by Date: Re: Tabs in TextView
  • Previous by thread: Re: I think I wrongly got "Switch case is in protected scope"
  • Next by thread: Re: I think I wrongly got "Switch case is in protected scope"
  • Index(es):
    • Date
    • Thread