discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why/how is count method not emitting warning/error on id?


From: David Chisnall
Subject: Re: Why/how is count method not emitting warning/error on id?
Date: Sun, 9 Jul 2017 10:28:17 +0100

On 8 Jul 2017, at 17:46, Ivan Vučica <ivan@vucica.net> wrote:
> 
> That you get a warning at all is clang playing smart and saying "absolutely 
> nowhere, in any of the types that I saw in this compilation unit, did I see 
> this method".

It’s a little bit more than that.  The types of the declared method tell the 
compiler what the argument frame should look like for the call.  If you don’t 
have a declaration, then the compiler doesn’t know what this should look like 
(and it’s not safe to deduce this from the arguments at the call site, because 
there may be some expected implicit casts).  Clang will warn (actually, I’m 
surprised this isn’t an error), saying ‘I don’t know how to construct a call 
frame for this invocation’.  In ARC mode, the types also include ownership 
information and so you will violate the memory safety guarantees if you call a 
method with unknown types, so this will also be rejected for that reason.

The same will happen if you declare a method in two different class hierarchies 
with different types: if the receiver type is id then the compiler doesn’t know 
which one to choose and so requires an explicit cast.  With the Apple runtime, 
this will potentially lead to stack corruption if you don’t do it correctly, 
with the GNUstep runtime it should trigger an exception.

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]