[cfe-dev] Obj-C false positive warning with deprecation and instancetype?
fjahanian at apple.com
Wed Jan 11 11:01:05 PST 2012
On Jan 11, 2012, at 10:49 AM, jahanian wrote:
> 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?
> It is not false positive. [self alloc] is of type 'id'. Not knowing which initWithContentsOfURL gets called, clang goes out of its way to issue the deprecated warning so user can take action.
> You can make your intention known to clang by type-casting [self alloc].
> - Fariborz
If alloc is using instancetype then you shouldn't see this warning. Please file a bug report with the pre-processed file.
More information about the cfe-dev