Skip to content

Instantly share code, notes, and snippets.

@tjw
Created March 12, 2015 18:56
Show Gist options
  • Save tjw/b69773a1e0950a3be4ee to your computer and use it in GitHub Desktop.
Save tjw/b69773a1e0950a3be4ee to your computer and use it in GitHub Desktop.
20140181: Regression: clang static analyzer emits spurious warning when releasing strong ivar in -dealloc
#import <Foundation/Foundation.h>
/*
clang --analyze readonly-property-analyzer.m
readonly-property-analyzer.m:20:2: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
[_string release];
^~~~~~~~~~~~~~~~~
1 warning generated.
NOTE: If the properties is changed to include 'strong', this problem goes away (though not my fear that in ARC mode the compiler is now defaulting object-typed properties to be non-strong).
*/
@interface Foo : NSObject
- initWithString:(NSString *)string;
@property(nonatomic,strong,readonly) NSString *string;
@end
@implementation Foo
- initWithString:(NSString *)string;
{
if (!(self = [super init]))
return nil;
_string = [string copy];
return self;
}
- (void)dealloc;
{
[_string release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment