public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19605] New: Wrong member offset in inherited classes
@ 2005-01-24 14:52 peter at os dot inf dot tu-dresden dot de
  2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: peter at os dot inf dot tu-dresden dot de @ 2005-01-24 14:52 UTC (permalink / raw)
  To: gcc-bugs

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;
}

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

peter@erwin:~/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)
peter@erwin:~/t5> /usr/local/gcc/head/bin/g++ --static -o c.4.x c.cc
peter@erwin:~/t5> ./c.4.x
a: 0
b: 0x4
c: 0
d: 0x4
e: 0
f: 0x4
g: 0x18
h: 0x1c
peter@erwin:~/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
peter@erwin:~/t5> g++-3.2 -o c.3.x c.cc
peter@erwin:~/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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-01-29  0:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
2005-01-24 15:02 ` [Bug c++/19605] [4.0 Regression] " pinskia at gcc dot gnu dot org
2005-01-24 15:04 ` pinskia at gcc dot gnu dot org
2005-01-24 15:12 ` fm3 at os dot inf dot tu-dresden dot de
2005-01-26  4:12 ` bangerth at dealii dot org
2005-01-29  0:01 ` mmitchel at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).