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: [PATCH] Re: [rfc] __builtin_offsetof for c and c++



On Feb 8, 2004, at 22:09, Andreas Jaeger wrote:
At least this does not look correct, you need to add 2004 and not
2003.

Please check that all files that you touch have 2004 in it.


Do you have any testcases?


There are already some testcases in the testsuite for this.

Here is one which currently fails with the current way but passes with
this new way:

// { dg-run }
// { dg-options "-O2" }

#include <stddef.h>

#define assert_link_error(a) ((void) ((a) ? 0 : link_error ()))

int link_error(void);

struct X { int ary[38]; };

struct A {
    template<int N, class T>
      int offset(T*) { return offsetof(typename T::X, ary[N]); }

    template<int N>
      int offset() { return offsetof(X, ary[N]); }

      int offset() { return offsetof(X, ary[34]); }
};

struct B { typedef ::X X; };

int main()
{
    A a;
    assert_link_error(a.offset<34>((B*)0) == a.offset<34>());
    assert_link_error(a.offset<34>((B*)0) == a.offset());
    assert_link_error(a.offset<34>() == a.offset());
}


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