[gnu.g++.bug] virtual base classes

jjc@UUNET.UU.NET (James Clark) (05/12/89)

I'm having problems with virtual base classes:

Script started on Thu May 11 18:53:46 1989
jclark% cat test.c
#include <stdio.h>

struct A {
  int n;
  void set(int);
  void print();
};

void A::set(int i)
{
  n = i;
}

void A::print()
{
  fprintf(stderr, "%d\n", n);
}

struct B : virtual A {
};


main()
{
  B *p = new B;
  p->set(5);
  p->print();
  fprintf(stderr, "p->n = %d\n", p->n);
}
jclark% make test
/u/local/g++/g++ -B/u/local/g++/ -g -v -I.   -sun4 -o test test.c 
g++ version 1.35.0-
 /usr/local/lib/gcc-cpp -+ -v -I. -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ test.c /tmp/cca25650.cpp
GNU CPP version 1.35
 /u/local/g++/cc1plus /tmp/cca25650.cpp -quiet -dumpbase test.c -noreg -version -G -o /tmp/cca25650.s
GNU C++ version 1.35.0- (sparc) compiled by GNU C version 1.35.
 as /tmp/cca25650.s -o test.o
 /u/local/g++/ld++ -o test -C -C /u/local/g++/crt0+.o test.o -lg++ /usr/local/lib/gcc-gnulib -lg -lc
/u/local/g++/g++: unrecognized option `-sun4'
jclark% test
Segmentation fault (core dumped)
jclark% gdb test core
GDB 3.1, Copyright (C) 1988 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /u/jjc/test/test...done.
Core file is from "test".
Program terminated with signal 11, Segmentation fault.
Type "help" for a list of commands.
(gdb) where
#0  0x2120 in set_PSA_SI ($this=(struct A *) 0x0, i=5) (test.c line 11)
#1  0x2198 in main () (test.c line 26)
(gdb) quit
jclark% exit
jclark% 
script done on Thu May 11 18:54:21 1989

If I've understood virtual base classes, this ought to have worked.

James Clark
jjc@jclark.uucp

tiemann@YAHI.STANFORD.EDU (Michael Tiemann) (05/12/89)

   I'm having problems with virtual base classes:
   
   Script started on Thu May 11 18:53:46 1989
   jclark% cat test.c
   #include <stdio.h>
   
   struct A {
     int n;
     void set(int);
     void print();
   };
   
   void A::set(int i)
   {
     n = i;
   }
   
   void A::print()
   {
     fprintf(stderr, "%d\n", n);
   }
   
   struct B : virtual A {
   };
   
   
   main()
   {
     B *p = new B;
     p->set(5);
     p->print();
     fprintf(stderr, "p->n = %d\n", p->n);
   }

Here is what I get with this morning's compiler:

yahi% a.out
5
p->n = 5

ekrell@ulysses.att.com (06/05/89)

With a pre-release cfront 2.0, I get:

5
p->n = 5

so it looks like you found a g++ bug.