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


> | These are both undefined behavior.  No diagnostic is required.
> 
> I disagree that they are undefined behaviour.  The standard says
> "shall".  See Matt Austern's recent message on this topic on
> gcc@gcc.gnu.org. 

The standard says:

"The result of applying  the  offsetof  macro  to  a field  that is a
static data member or a function member is undefined."

So, the first case is undefined, no diagnostic required.

The second case is a missed diagnostic about a POD.  I agree that this
is a defect -- one we've always had.  However, fixing that is easy, and
the code to implement it is the same whether you use the thing I
implemented or __builtin_offsetof.

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.

To be fair, the diagnostics are:

/home/mitchell/tmp/test.C:16: warning: invalid access to non-static data
member `A::c' of NULL object
/home/mitchell/tmp/test.C:16: warning: (perhaps the `offsetof' macro was
used incorrectly)

> | Since you think arguing about this is a good use of your time, I can
> | only conclude that V3 is now bug-free and as fast as possible!  I am
> | overjoyed. :-)
> 
> Is this the way you think we shall justify extensions under the name
> of bug-fixes? 

I'm not going there with you.

I corrected bugs in the C++ front end relating to the handling of
integral constant expressions.  (We accepted things we should not.) 
That made our "offsetof" macro not work in situations where the standard
requires it to work.  I fixed that too.

I'm not opposed to "__builtin_offsetof", but I can't see any benefit to
it either.  If you want to implement it, go right ahead.

I'm not going to waste any more time discussing this issue.

-- 
Mark Mitchell <mark@codesourcery.com>
CodeSourcery, LLC


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