assert(!isGCEnabled() && "Autorelease counts in GC mode?");
unsigned Cnt = V.getCount();
+ // FIXME: Handle sending 'autorelease' to already released object.
+
+ if (V.getKind() == RefVal::ReturnedOwned)
+ ++Cnt;
+
if (ACnt <= Cnt) {
if (ACnt == Cnt) {
V.clearCounts();
- V = V ^ RefVal::NotOwned;
+ if (V.getKind() == RefVal::ReturnedOwned)
+ V = V ^ RefVal::ReturnedNotOwned;
+ else
+ V = V ^ RefVal::NotOwned;
}
- else {
+ else {
V.setCount(Cnt - ACnt);
V.setAutoreleaseCount(0);
}
- (BOOL)isEqual:(id)object;
- (oneway void)release;
- (id)retain;
+- (id)autorelease;
@end
@protocol NSCopying
- (id)copyWithZone:(NSZone *)zone;
CFRelease(ref); // expected-warning{{Reference-counted object is used after it is released}}
}
+// Test regular use of -autorelease
+@interface TestAutorelease
+-(NSString*) getString;
+@end
+@implementation TestAutorelease
+-(NSString*) getString {
+ NSString *str = [[NSString alloc] init];
+ return [str autorelease]; // no-warning
+}
+@end
+
@interface C1 : NSObject {}
- (NSString*) getShared;
+ (C1*) sharedInstance;