Bug: call of virtual method in virtual base class implemented in derived gets wrong this

Florian Wunderlich fwunderlich@csi.com
Mon Jan 24 15:38:00 GMT 2000

Hello all,

maybe this program rings a bell for someone who knows about the VMT


#include <stdio.h>

class V
  virtual ~V() {}
  virtual unsigned pureInV() = 0;

class B : virtual public V
  void checkV()
    printf ("%x\n", pureInV());

class C : public B
  C() : x1(0x1234)
  unsigned pureInV()    // can also be virtual
    return x1;

  unsigned x1;

class D : public C
  unsigned x;

int main(int argc, char **argv)
  C c;
  D d;
  return 0;


As is quite obvious, this should output

But I get

The displacement of this (the pointer to the current class, that is) is
equivalent to the amount of data in D. Obviously this only happens
before the constructor returns, which sounds a bit like an ill-formed
program, but I checked with the ARM and [class.cdtor].3 explicitly
allows a construct like this.

BTW, pureInV can also have an implementation and does not need to be

I believe this bug should have a *very* obvious cause so I first wanted
to check with you if this is maybe so obvious that it can immediately be

Is gcc-bugs a mailing list? Can I subscribe to know wether you are
fixing the bug? None of the FAQs, info files, or html pages on
gcc.gnu.org said more than just `the mailing list'. Maybe you could
update me somehow so that if you don't fix it, I can have a try.

---------- most probably unimportant bug report data follows

main:~/temp$ g++ -v
Reading specs from /opt/gcc/lib/gcc-lib/i586-linux/2.96/specs
gcc version 2.96 20000117 (experimental)
main:~/temp$ g++ -o proof -Wall proof.cpp

(exactly the same as with gcc-2.95.2, same bug, same commands)

main:~$ uname -a
Linux main 2.2.13 #2 Tue Nov 9 21:08:20 CET 1999 i586 unknown

As the bug also appears without stdio.h, I don't think you really want
preprocessor output.

I configured with `i586-linux --prefix=/opt/gcc --with-gnu-as
--with-gnu-ld --enable-threads --enable-shared'

More information about the Gcc-bugs mailing list