r186105 - ObjectiveC arc[qoi]: When due to change of certain methods'

jahanian fjahanian at apple.com
Thu Jul 11 12:01:50 PDT 2013

Problem is that methods return wrong type for their family. I will change the diagnostics to  say ‘casting’ instead of ‘returning’.
John M. may want to add more content to reason for such castings.

- Fariborz

On Jul 11, 2013, at 11:40 AM, Arthur O'Dwyer <arthur.j.odwyer at gmail.com> wrote:

> On Thu, Jul 11, 2013 at 9:48 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>> @interface Fail @end
>> @protocol X @end
>> @implementation Fail
>> -- (id<X>) initWithX
>> +- (id<X>) initWithX // expected-note {{compiler has implicitly changed method 'initWithX' return type}}
>> {
>> -  return (id)self; // expected-warning {{casting 'Fail *' to incompatible type 'id<X>'}}
>> +  return (id)self; // expected-warning {{returning 'Fail *' from a function with incompatible result type 'id<X>'}}
>> }
>> @end
> FWIW, I don't understand these new diagnostics at all. I understand
> that with ARC the return type of initWithX must be (Fail*), not
> (id<X>); but if the compiler has indeed "implicitly changed [the]
> return type" to (Fail*), then why is it complaining so loudly about
> the correct "return" statement? [Under ARC, it's always valid to
> return "self" from an init method.] Or, if the compiler did NOT change
> initWithX's return type, then why is it saying it did?
>> + at implementation UIViewController
>> ++ (UIViewController<PMFilterManager> *)newFilterViewControllerForType // expected-note {{compiler has implicitly changed method 'newFilterViewControllerForType' return type}}
>> +{
>> +        UIViewController<PMFilterManager> *filterVC;
>> +        return filterVC; // expected-warning {{incompatible pointer types returning 'UIViewController *' from a function with result type 'UIViewController<PMFilterManager> *'}}
>> +}
>> + at end
> These diagnostics just look wrong. UIViewController's
> newFilterViewControllerForType method is expected by ARC to return
> (UIViewController*), and in fact that's how it's prototyped (with the
> addition of an extra protocol, which doesn't hurt anything). And in
> fact its return statement returns an expression of type
> (UIViewController<PMFilterManager>*), which is implicitly convertible
> to (UIViewController*). So these diagnostics are just confusing and
> useless; there's no error here to diagnose.
> Thoughts?
> -Arthur

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130711/49ba39ca/attachment.html>

More information about the cfe-commits mailing list