Autogenerated ivars not retained by ARC

Originator:hamish
Number:rdar://9842232 Date Originated:26-Jul-2011 06:45 PM
Status:Closed (Behaves Correctly) Resolved:
Product:iPhone SDK [sic] Product Version:5.0 beta 4
Classification:Serious Bug Reproducible:Always
 
Summary:
EXC_BAD_ACCESS arises when using autogenerated ivars (@synthesize prop = myProp with no declaration of myProp).

Steps to Reproduce:
See https://gist.github.com/1107320

Expected Results:
The same behaviour whether or not the ivar declarations are commented out.

Actual Results:
Crash when the ivar declarations are commented out.

Regression:
Unknown.

Notes:
P.S. Please rename "iPhone SDK" and "iPad SDK" under "Product" in the bug reporter to "iOS". Thanks!

Comments

Marked as Fixed (Behaves Correctly) with the explanation:

"For historical reasons, properties that aren't explicitly strong or weak are implicitly "assign", which for Objective-C pointers means unsafe_unretained. This is "correct" but very unsafe, as you've found, and so ARC will now output an error on this code. Instead, you must explicitly say that a property of Objective-C pointer type is strong, weak, or unsafe_unretained before you synthesize it, like so: @property(strong, nonatomic, readonly) UILabel *textLabel; Furthermore, if the synthesized ivar already exists, ARC will verify that it has matching semantics; if the synthesized ivar does not already exist, it will be created with matching semantics."

If you set a storage type in the @property it'll work, otherwise it defaults to unsafe_unretained.

(Not breaking NDA, this is at http://clang.llvm.org/docs/AutomaticReferenceCounting.html)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!