[cfe-dev] Obj-C false positive warning with deprecation and instancetype?
devlists at shadowlab.org
Wed Jan 11 11:57:54 PST 2012
Le 11 janv. 2012 à 20:01, jahanian a écrit :
> 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.
According to clang doc, "+alloc implicitly has a related result type". So clang should be able to determine what the return type is.
More information about the cfe-dev