This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH: Fix PR 13275


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
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]