This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Re: [rfc] __builtin_offsetof for c and c++
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Andreas Jaeger <aj at suse dot de>
- Cc: Richard Henderson <rth at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>, Gabriel Dos Reis <gdr at integrable-solutions dot net>, Andrew Pinski <pinskia at physics dot uc dot edu>
- Date: Sun, 8 Feb 2004 22:30:30 -0800
- Subject: Re: [PATCH] Re: [rfc] __builtin_offsetof for c and c++
- References: <A8F6A3D4-5AC5-11D8-9B31-000393A6D2F2@physics.uc.edu> <m3llncbx7e.fsf@gromit.moeb>
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());
}