[cfe-dev] Obj-C false positive warning with deprecation and instancetype?
Douglas Gregor
dgregor at apple.com
Wed Jan 11 14:03:44 PST 2012
On Jan 11, 2012, at 8:10 AM, Sean McBride wrote:
> Hi all,
>
> Using clang r147866 on Mac OS X 10.7, the code below causes this warning:
>
> $ clang -fsyntax-only test.m
> test.m:18:11: warning: 'initWithContentsOfURL:' is deprecated [-Wdeprecated-declarations]
> return [[[self alloc] initWithContentsOfURL:inURL] autorelease];
> ^
>
> NSString has a deprecated method initWithContentsOfURL:, but in my own class it's not deprecated. I would have thought that between my own use of instancetype and clang's special casing of alloc that this should not warn. Is it a false positive bug?
>
> -----------
> #import <Foundation/Foundation.h>
>
> @interface Awesome : NSObject { }
> - (instancetype)initWithContentsOfURL:(NSURL*)inURL; // designated initializer
> + (instancetype)awsomeWithContentsOfURL:(NSURL*)inURL;
> @end
>
> @implementation Awesome
>
> - (instancetype)initWithContentsOfURL:(NSURL*)inURL
> {
> self = [super init];
> return self;
> }
>
> + (instancetype)awsomeWithContentsOfURL:(NSURL*)inURL
> {
> return [[[self alloc] initWithContentsOfURL:inURL] autorelease];
> }
>
> @end
>
> int main (int argc, char *argv[])
> {
> (void)argc; (void)argv;
> return 0;
> }
> -----------
IIRC, we've seen this bug before, and the issue is that the related result type inference for message sends to 'self' within class methods is not working properly. Definitely looks like a Clang bug.
- Doug
More information about the cfe-dev
mailing list