[cfe-commits] r41613 - in /cfe/trunk: AST/Expr.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtVisitor.h include/clang/Basic/DiagnosticKinds.def
Chris Lattner
clattner at apple.com
Thu Aug 30 16:52:19 PDT 2007
On Aug 30, 2007, at 3:55 PM, Neil Booth wrote:
> Chris Lattner wrote:-
>
>>> I thought it would be instructive to figure that out yourself :)
>>>
>>> struct s { struct { int t; } x[2]; };
>>> int f (void) { return offsetof (struct s, x->t); }
>>
>> Are you sure that's valid? C99 has a maddeningly brief discussion of
>> what is valid in offsetof. By this logic, wouldn't offsetof (struct
>> s, x+1) also be valid?
>
> Hmm, I guess it would. Yuk.
>
> The std for this is written in ridiculously vague language
> that could be read as intending only a single identifier as the
> second argument.
Yep.
> In each thread different members of the C committee have said that
> only an identifier was intended. To me that only begs the question
> of why the language is so opaque - surely easier to just say it
> shall be an identifier?
Yeah, it surely would :)
> But your example has convinced me that restricting this offsetof to
> just an identifier is probably a good idea - accepting generic
> expressions can get out of control.
Ok, at this point, we now support the simple case (which is arguably
what the standard intends), and support what GCC does, diagnosing it
as an extended form of offsetof. I think this is a good tradeoff: it
gives us compatibility with the standard and with GCC, and has low
complexity. What a mess!
Thanks Neil,
-Chris
More information about the cfe-commits
mailing list