This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Several levels of virtual inheritance: bug?
- From: Benjamin Redelings I <bredelin at ucla dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 10 Feb 2005 15:46:12 -0800
- Subject: Several levels of virtual inheritance: bug?
Hello,
I have found (what seems to be) a bug in todays CVS version of g++ 4.0.
The reduced testcase no logner calls the wrong virtual function, but
it still crashes. Additionally it is all one file now.
I attatched a reduced test-case (test-smodel.C). Here is the output:
Output in 3.4:
subst model = EQU
subst model = EQU
subst model = EQU
Output in 4.0 CVS:
subst model = EQU
subst model = D\uffff
Segmentation fault
Should I file a bug in bugzilla for this?
-BenRI
#include <string>
#include <iostream>
using std::string;
struct Model {
bool full_tree; // if you remove this, the error goes away
virtual Model* clone() const =0;
virtual std::string name() const =0;
virtual ~Model() {} // if you remove this, the error goes away
};
struct R: virtual public Model {
virtual R* clone() const =0;
};
struct A: virtual public Model {
virtual A* clone() const=0;
};
struct RA: public R, public A {
virtual RA* clone() const=0;
};
//--------------------- EQU Model ------------------------//
struct EQU: public RA {
virtual EQU* clone() const {return new EQU(*this);}
string name() const {return "EQU";}
};
int main() {
Model* M1 = new EQU();
Model* M2 = M1->clone();
Model* M3 = M2->clone();
std::cout<<"subst model = "<<M1->name()<<std::endl;
std::cout<<"subst model = "<<M2->name()<<std::endl;
std::cout<<"subst model = "<<M3->name()<<std::endl;
return 0;
}