gcc-4.0 returns incorrect class relative offsets for members

Following:

1. example program producing the error
2. console output for gcc 4.0 (incorrect) and gcc 3.2 (correct)

============================================================

#include <cstdio>
#include <iostream>


#define GET_MEMBER_PTR(type,member)                                     \
  ({                                                                    \
    void *type::*p = (void *type::*) &type::member;                     \
    &(((type *) 0)->*p);                                                \
  })

using std::endl;
using std::cout;

class A
{
public:
  unsigned a;
  unsigned b;
};

class B
{
public:
  unsigned c;
  unsigned d;
};

class C
{
public:
  unsigned e;
  unsigned f;
};

class D : public A, public B, public C
{
public:
  unsigned g;
  unsigned h;
};

int
main(void)
{

  cout << "a: " << GET_MEMBER_PTR(D, a) << endl;
  cout << "b: " << GET_MEMBER_PTR(D, b) << endl;
  cout << "c: " << GET_MEMBER_PTR(D, c) << endl;
  cout << "d: " << GET_MEMBER_PTR(D, d) << endl;
  cout << "e: " << GET_MEMBER_PTR(D, e) << endl;
  cout << "f: " << GET_MEMBER_PTR(D, f) << endl;
  cout << "g: " << GET_MEMBER_PTR(D, g) << endl;
  cout << "h: " << GET_MEMBER_PTR(D, h) << endl;

  return 0;
}

===================================================

[EMAIL PROTECTED]:~/t5> /usr/local/gcc/head/bin/g++ -v
Using built-in specs.
Configured with: ../gcc/configure --prefix=/usr/local/gcc/head 
--enable-__cxa_atexit
Thread model: posix
gcc version 4.0.0 20050123 (experimental)
[EMAIL PROTECTED]:~/t5> /usr/local/gcc/head/bin/g++ --static -o c.4.x c.cc
[EMAIL PROTECTED]:~/t5> ./c.4.x
a: 0
b: 0x4
c: 0
d: 0x4
e: 0
f: 0x4
g: 0x18
h: 0x1c
[EMAIL PROTECTED]:~/t5> g++-3.2  -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3
[EMAIL PROTECTED]:~/t5> g++-3.2 -o c.3.x c.cc
[EMAIL PROTECTED]:~/t5> ./c.3.x
a: 0
b: 0x4
c: 0x8
d: 0xc
e: 0x10
f: 0x14
g: 0x18
h: 0x1c

-- 
           Summary: Wrong member offset in inherited classes
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peter at os dot inf dot tu-dresden dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605

Reply via email to