[cfe-dev] [cfe-commits] r100942 - /cfe/trunk/lib/CodeGen/CGObjC.cpp

Chris Lattner clattner at apple.com
Sat Apr 10 14:41:32 PDT 2010

By your logic, we would accept cast of super... But we don't and it is  
intentional.  This is the same issue.


On Apr 10, 2010, at 1:24 PM, David Chisnall <csdavec at swan.ac.uk> wrote:

> On 10 Apr 2010, at 21:09, Chris Lattner wrote:
>> On Apr 10, 2010, at 1:03 PM, David Chisnall wrote:
>>>> The big issue here is that from a language perspective, "super"  
>>>> is not an expression at all.  It is a magic token that is only  
>>>> valid in a message send.  Things like super->ivar *should* be  
>>>> disallowed, as should "id x = super" and many other things that  
>>>> we probably accidentally allow.
>>> Currently, super->ivar is disallowed, so is id x = super.
>> Good.
>>> These are accepted by GCC, although that's probably not sensible.
>> No, they aren't.
> They seem to be on my copy of GCC.  I just tested all of these and  
> they worked.
>>> [(super) foo];
>> No, that should not be legal.  Super is not an expression.  It is  
>> not valid to use it in expression contexts: paren exprs require  
>> that the subexpression be an expression.
>>> While you would never write this directly, it is relatively common  
>>> as a result of macro expansion, when a macro is used to optionally  
>>> remove message sends.  Consider a macro like this:
>>> #ifndef DISABLE_LOGS
>>> #define LOG(x) [(x) log]
>>> #else
>>> #define LOG(x)
>>> #endif
>> Just because something is convenient doesn't mean it should be legal.
> The fact that something is convenient, supported by GCC, and used in  
> existing code seems like a good reason for accepting it...
>>> If you make a message send to super a flag in the AST, then how  
>>> would you represent [(super) foo] or [((super)) foo] in the AST?
>> You wouldn't, we should reject this code, that's the whole point.
> I don't really see a convincing argument for rejecting it.  Even if  
> super is not an expression, being able to put it in brackets seems  
> logical because you use it in the same place as expressions.  If you  
> can put some message receivers in brackets and not others, this  
> makes the language inconsistent and makes macros even more  
> irritating to work with than the C spec normally does.
> And, if something can be used in the same place as an expression,  
> but isn't an expression, what is it?
> David
> -- Sent from my brain

More information about the cfe-dev mailing list