C++ PATCH: Fix PR 13275

Gabriel Dos Reis gdr@integrable-solutions.net
Thu Dec 18 03:12:00 GMT 2003


Richard Henderson <rth@redhat.com> writes:

| > You might as well just let the preprocessor do the work for you.
| 
| Possibly.
| 
| Joseph mentioned the possibility of better diagnostics with the
| __builtin_offsetof form.

Yes.  We have opportunity to give better error messages.  Consider
what we get with the current implementtation of __offsetof__ on

    #include <stddef.h>

    struct A {
       static A b;
       A& c;
    };

    A A::b = { A::b };

    int main() {
       offsetof(A, c);
    }

That is certainly an invalid use of offsetof, but speaking of NULL
object does not make sense.

| And I think Gaby's point is that it is simply not possible to abuse
| __builtin_offsetof, whereas __offsetof__ could be used to cheat
| in some instance.  In what way, I'm not sure, but ...

Basically, the solution proposed by Mark assumes that the preprocessor
understands C++, but it does not.  In particular, it relies on normal
name lookup rules  that may find things like static data members or
things in bases classes -- one of the C++ requirements is that the
type should be a POD.  See the example I posted on Mark's request.

-- Gaby
 



More information about the Gcc-patches mailing list