Bug 20354 - g++ problem with virtual function / inheritence (not implemented?)
Summary: g++ problem with virtual function / inheritence (not implemented?)
Status: CLOSED DEFERRED
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-11-05 07:49 UTC by darkeye
Modified: 2007-04-18 16:29 UTC (History)
1 user (show)

(edit)
Clone Of:
(edit)
Last Closed: 2000-11-05 07:49:38 UTC


Attachments (Terms of Use)

Description darkeye 2000-11-05 07:49:36 UTC
I found a problem with the g++ in RedHat 7.0, gcc-c++-2.96-54.

The problem is with using virtual inheritance and virtual functions, where
the function return value is overridden. Consider the following typical
example:

class ClassA
{
    public:
        inline virtual ClassA *
        clone ( void )      { return new ClassA(*this); }
};

class ClassB : public virtual ClassA
{
    public:
        inline virtual ClassB *
        clone ( void )      { return new ClassB(*this); }
};


the compiler gives the error:

sorry, not implemented: adjusting pointers for covariant 

is this some joke? :)

If the inheritance is changed from virtual to not virtual, the sample
compiles. But than an error comes when using multiple inheritance. Consider
the following:

class ClassA
{
    public:
        inline virtual ClassA *
        clone ( void )      { return new ClassA(*this); }
};

class ClassB : public ClassA
{
    public:
        inline virtual ClassB *
        clone ( void )      { return new ClassB(*this); }

};

class ClassC : public ClassA
{
    public:
        virtual ClassC *
        clone ( void )      { return new ClassC(*this); }
};

class ClassD : public ClassB, public ClassC
{
    public:
        inline virtual ClassD *
        clone ( void )      { return new ClassD(*this); }
};


then the following errors come:

type `ClassA' is ambiguous base class for type `ClassD'
type `ClassA' is ambiguous base class for type `ClassD'


Both of the above sample compile well with the g++ supplied in RedHat 6.2.
To my knowledge, both sample are correct C++ code, so I don't understand
why it doesn't compile.

Comment 1 Jakub Jelinek 2000-11-29 12:54:25 UTC
Because this needs runtime adjustments of returned pointers.
It is implemented neither in g++ 2.95.x nor in our 2.96 nor in CVS g++.


Note You need to log in before you can comment on or make changes to this bug.