Compiler issue. All cases in a switch statement shares a same scope, and ARC 
works by inserting code into beginning and end of scopes. switch() statement 
jumps around, making code path very unpredictable, confusing ARC.

Sent from my iPhone

> On 2013年10月22日, at 16:02, "Gerriet M. Denkmann" <[email protected]> wrote:
> 
> 
>> On 22 Oct 2013, at 14:48, ChanMaxthon <[email protected]> wrote:
>> 
>> Just put a set of braces after every case: and it should be okay. A set of 
>> braces here actually sets up a mini stack frame that makes ARC work.
> 
> 非常感谢
> Works perfectly now.
> (I still would like to know whether my code was faulty, or whether this is a 
> compiler bug)
> 
> 
> Kind regards
> 
> Gerriet.
> 
>>> On 2013年10月22日, at 15:41, "Gerriet M. Denkmann" <[email protected]> 
>>> wrote:
>>> 
>>> Converting to Arc (Xcode 5.0).
>>> 
>>> This works fine without Arc (regardless whether TRIGGER_ERROR is defined or 
>>> not):
>>> 
>>> NSMutableString *mus = [ NSMutableString string ];
>>> NSString *word = @"abc";
>>> 
>>> switch( self.colourType )
>>> {
>>>  case colour_link:                
>>>      [ mus appendString: @"<a href=\"" ]; 
>>>      #define    TRIGGER_ERROR
>>>      #ifdef        TRIGGER_ERROR
>>>      NSString *urlStr = [ word stringByAddingPercentEscapesUsingEncoding: 
>>> NSUTF8StringEncoding ];
>>>      [ mus appendString: urlStr ];
>>>      #else    //    no_ERROR
>>>      [ mus appendString: [ word stringByAddingPercentEscapesUsingEncoding: 
>>> NSUTF8StringEncoding ] ];
>>>      #endif    //    no_ERROR
>>> 
>>>      break;
>>> 
>>>  default:     
>>>      [ mus appendString: word ];
>>> };
>>> 
>>> But with Arc, if TRIGGER_ERROR is defined, I get an error: "Switch case is 
>>> in protected scope" with the further explanation: "Jump bypasses 
>>> initialization of retaining variable".
>>> 
>>> 
>>> Was the old (non-arc) code faulty (but the compiler did not notice this)?
>>> Why is the arc-version (with TRIGGER_ERROR defined) wrong?
> 

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to