Hi,

On 2013-10-22 17:50, Sean McBride wrote:
On Tue, 22 Oct 2013 10:31:01 +0200, Daniel Höpfl said:

Was the old (non-arc) code faulty (but the compiler did not notice
this)?
Why is the arc-version (with TRIGGER_ERROR defined) wrong?

It is wrong in the non-arc world, too. (ISO/IEC 9899:2011 AKA C11,
6.8.6.1: "A goto statement shall not jump from outside the scope of an
identifier having a variably modified type to inside the scope of that
identifier" - switch is a special case of goto.)

Daniel,

I don't think you can quote the Standard about 'goto' and just wave
your hands and say it applies to 'switch' also.  :)  The Standard's
description of 'switch' should contain the answer.

OK ... but as you say, the standard should contain the answer. Next try:


C11, 6.8.4.2, paragraph 7 (The example): "the object whose identifier is i exists with automatic storage duration (within the block) but is never initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will access an indeterminate value." (Using this paragraph because it compresses the scope/initializing topic into one sentence.)


In your shorter example, the compiler does not complain for int*, because it is okay for foo to be uninitialized.

If we use NSObject* as type of foo, this is okay for non-ARC, too.


With ARC, we have to include the ARC specification: "A retainable object pointer is either a null pointer or a pointer to a valid object." - <http://clang.llvm.org/docs/AutomaticReferenceCounting.html#retain-count-semantics>


Back to your example: foo is in scope but not initialized.
This is not acceptable for ARC (even if foo is not used in the scope).


So: clang is right. :-)

Maybe clang/ARC should simply init NSObject *foo with nil (even when the Cxx standard says it is uninitialized in this case).


IMHO, that's pretty weird!

It is ... if you move the "default:" label to the top, it works with ARC, too: C11, 6.8.4.2, p. 2 not met, foo's scope is now limited to "case 1:".


Bye,
   Daniel

_______________________________________________

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