[cfe-dev] Even more clang ideas

Ted Kremenek kremenek at apple.com
Sat Jul 26 10:21:31 PDT 2008


On Jul 26, 2008, at 12:02 AM, Chris Hanson wrote:

> On Jul 25, 2008, at 6:28 PM, Ted Kremenek wrote:
>
>>> It is, in fact, an error to return a NSMutableArray in a method
>>> that's prototyped to return an NSArray due to C pointer aliasing
>>> rules. The 'id' type is the closest thing that Objective-C has to a
>>> 'generic object pointer type', so if a method wants to return a
>>> pointer to an object of more than one type, it really should declare
>>> the return type as 'id'.  Again, this is due to the C pointer
>>> aliasing rules rather than any OO conceptual rules.
>>
>> Again, I'm not certain how much C99's aliasing rules apply to
>> Objective-C object references.  Objective-C doesn't have a formal
>> specification akin to C99, so the specification (if you want to call
>> it that) is whatever the current compiler implementation allows.
>
> The current specification of Objective-C is "The Objective-C 2.0  
> Programming Language" at <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ 
> >.

Thanks Chris!  What I meant by a "formal" specification is something  
with the detail to write a compiler and runtime with.  The document  
you reference (while excellent) doesn't provide that kind of detail.   
In our implementation of Objective-C support in Clang, we are really  
leaning on the knowledge of specific people who either had an hand in  
conceiving the language or implemented its support in gcc.

> John is also incorrect about the above:  It is *not* an error, in  
> Objective-C, to return an instance of a subclass from a method  
> prototyped as returning an instance of the superclass.

I don't think I addressed that point directly, and I'm glad you did  
so.  This idea follows from standard type theory for functions: the  
return type is allowed to be a covariant type.

> Objective-C is its own language that extends C99, not a preprocessor  
> for C99, and this is one of the extensions that Objective-C adds.

Exactly.

>  In fact, in Objective-C it is not possible to say "this method  
> returns an instance of specifically this class and no other class"  
> -- you can only say "this method returns an instance of this class  
> or any subclass."


Excellent point.  I don't think most standard OO languages allow you  
to express the first statement either.  (others please chime in on  
this one if you know better!)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080726/93062f29/attachment.html>


More information about the cfe-dev mailing list