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

Arthur O'Dwyer arthur.j.odwyer at gmail.com
Thu Jul 11 11:40:09 PDT 2013

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.


More information about the cfe-commits mailing list