It appears that the implicit conversion from a derived to an empty base class
is incorrect.

Consider the following code:

empty.cc:

#include <stdio.h>

class simple_base {
public:
  int sb;
};

class empty_base {
public:
  void test_eb() {
    printf("empty_base this @ %p\n", this);
  }
};

class class1 : public simple_base, public empty_base {
public:
  int c1;

  void test(empty_base* p) {
    printf("empty_base @ %p\n", p);
  }
};

class class2 {
public:
  int c2;
  class1 c1;
  int i3;

  void test(class1* p) {
    printf("class1 @ %p, i3 @ %p\n", p, &i3);
    c1.test(p);

    printf("empty_base should be at %p\n", (char*)p +
sizeof(simple_base));
    c1.test_eb();
  }
};

int main (int argc, char * const argv[]) {
  class2 c2;
  printf("class2 @ %p\n", &c2);
  c2.test(&c2.c1);
  return 0;
}

compiling this using:

g++ empty.cc and executing results in:
class2 @ 0xbfffce50
class1 @ 0xbfffce54, i3 @ 0xbfffce5c
empty_base @ 0xbfffce54
empty_base should be at 0xbfffce58
empty_base this @ 0xbfffce54

I would have expected the output to be:

class2 @ 0xbfffce50
class1 @ 0xbfffce54, i3 @ 0xbfffce5c
empty_base @ 0xbfffce58
empty_base should be at 0xbfffce58
empty_base this @ 0xbfffce58

version of gcc:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit 
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52)


Thanks,

Bao.

-- 
           Summary: Incorrect conversion from derived to empty base class
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bduong at progress dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to