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

Chris Lattner clattner at apple.com
Sat Apr 10 13:09:30 PDT 2010

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.


>  These are accepted by GCC, although that's probably not sensible.

No, they aren't.

>> I think that the big AST change to model this correctly is really important, because it will fix a number of other problems and cases where Sema probably accidentally accepts invalid code (what about foo(super), passing it as an argument)?  This is not about a single special case, this is about the design always being broken and wanting to fix the root problem.
> Sema allows foo(super), but it stops in CodeGen.

Right, that is bad, my solution would fix that.

>> Just "leaving it in" will make clang accept illegal code - weaning the invalid code off their constructs is going to be more difficult in the future than it is now.  Since clang has never accepted this, we just continue rejecting it.
> The change doesn't make it accept illegal code, it will make it accept legal code.  The following absolutely should be legal:
> [(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.

> 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.


More information about the cfe-dev mailing list