ARCing instance through expression statement to ivar crashes
| Originator: | joachimb | ||
| Number: | rdar://10255703 | Date Originated: | 08-Oct-2011 08:41 PM |
| Status: | Open | Resolved: | |
| Product: | iPhone SDK | Product Version: | Xcode 4.2 GM/4D199 |
| Classification: | Serious bug | Reproducible: | Always |
Summary:
Assigning an instance variable through an expression statement will release the intermediate prematurely, and then crash as the now-deleted object is retained by the instance variable assignment.
Reduced case:
#import <Foundation/Foundation.h>
@interface Hej : NSObject { id level; } @end
@implementation Hej
-(void)test;
{
level = ({id temp = [NSObject new]; temp; });
}
@end
int main (int argc, const char * argv[]) {
@autoreleasepool {
[[Hej new] test];
}
return 0;
}
Regression:
Assigning to a local variable and then the ivar works fine.
Notes:
Compiler is "Apple LLVM Compiler 3.0".
You might also be asking yourself, "why are you using GCC compiler extensions? They make my head hurt.". I love expression statements, because they allow me to write things like:
#define $notNull(x) ({ __typeof(x) xx = (x); NSAssert(xx != nil, @"Must not be nil"); xx; })
used like
[dict setObject:$notNull([foo bar]) forKey:@"thing"];
Comments
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!