Bug 20354 - g++ problem with virtual function / inheritence (not implemented?)
g++ problem with virtual function / inheritence (not implemented?)
Status: CLOSED DEFERRED
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-11-05 02:49 EST by darkeye
Modified: 2007-04-18 12:29 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-11-05 02:49:38 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description darkeye 2000-11-05 02:49:36 EST
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 07:54:25 EST
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.