This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Strange behaviour in C++...


On Aug 25, 1999, "Christopher R. Jones" <cj@interlog.com> wrote:

> I am puzzled at the lack of attention this thread has received.

Maybe it's because it's a known bug, that has been pestering GNU/Linux
forever, because of the choice to enable -fvtable-thunks by default
quite a long time ago, for performance reasons, despite the bug? :-)

In fact, I seem to recall there was an attempt to fix it for gcc 2.95
(was it Martin v. Löewis?), but, if it ever got in the CVS tree, it
seems that it didn't work for this case :-(

I'm installing the following testcase in the testsuite:

// Copyright (C) 1999 Free Software Foundation

// by Alexandre Oliva <oliva@dcc.unicamp.br>
// based on bug report by Fredrik Öhrström <d92-foh@nada.kth.se>

// Special g++ Options: -fvtable-thunks
// execution test - XFAIL *-*-*

#include <cstdlib>

using namespace std;

struct vbase {
  virtual int get_a() const = 0;
};

struct base: virtual vbase {
  int a;
  base(int aa) : a(aa) {}
  int get_a() const { return a; }
};

struct mid: base {
  mid(int bb) : base(bb) {
    // when mid is not in charge of vbase initialization,
    // a derived-aware vtable is needed for vbase
    if (((vbase*)this)->get_a() != bb)
      abort();
  }
};

struct derived: virtual mid {
  derived(int cc) : mid(cc) {}
};

int main () {
  derived(1);
}

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]