Visual C++ incorrectly reports ambiguity when covariance is used with virtual inheritance - by James McNellis

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


7
0
Sign in
to vote
ID 590625 Comments
Status Closed Workarounds
Type Bug Repros 5
Opened 8/28/2010 8:25:08 PM
Access Restriction Public

Description

Consider the following class hierarchy:

    struct A {
        virtual A* f() = 0;
    };

    struct B : virtual A {
        virtual B* f();
    };

    struct C : virtual A {
        virtual C* f();
    };

    struct D : B, C {
       virtual D* f();
    };  // line 15

Visual C++ 2010 RTM reports:

    1>z:\stubby.cpp(15): error C2250: 'D' : ambiguous inheritance of 'B *A::f(void)'

There should be no ambiguity.  If the return type of f() is not covariant (for example, if we have all of the f()s return void*), Visual C++ compiles the code without error.

g++ and Comeau both compile this code without error.

This may or may not be related to another bug reported a few years ago:  https://connect.microsoft.com/VisualStudio/feedback/details/100328/covariant-return-types-and-virtual-inheritance#details

(This bug was posted on Stack Overflow at http://stackoverflow.com/questions/3592648/c-weird-diamond-inheritance-issue)
Sign in to post a comment.
Posted by Phi10101010 on 1/16/2014 at 2:54 PM
for
class a
class b1 : virtual public a
class b2 : virtual public a

class c1 : virtual public a, virtual public b1, virtual public b2
instead of
class c1 : virtual public b1, virtual public b2
could help.
Posted by bayer.tomas on 8/3/2011 at 2:19 PM
I report this problem too, see the code below. I considers this error as serious and urgent,and ask for its removal in the release of the VS. Thanks.

class A
{
public:
    virtual A * copy () const = 0;
    virtual ~A() = 0;
};

A::~A(){}

class B
{
public:
    virtual B * copy () const = 0;
    virtual ~B() = 0;
};

B::~B(){}

class C: virtual public A , public B
{
public:
    virtual C * copy () const = 0;
    virtual ~C() = 0;
};

C::~C(){}

class D: virtual public A
{
public:
    virtual D * copy () const {return new D (*this);}
    virtual ~D() {}
};

class E: virtual public D , public C
{
public:
    virtual E * copy () const {return new E (*this);}
    virtual ~E() {}
}; //Error C2250: 'E' : ambiguous inheritance of 'D *A::copy(void) const

Posted by Microsoft on 9/28/2010 at 1:57 PM
Hi, JamesMcNellis:
    Thank you for reporting the issue to Microsoft.
    We can confirm that this is a bug but we regret we are unable to fix it in the next release due to its severity and relative priority with other bugs/work.
    We will though keep the bug in our database and we will look at it for a future release of Visual C++.

Xiang Fan, Visual C++ Team
Posted by Microsoft on 8/29/2010 at 7:25 PM
Thanks for your feedback. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 8/29/2010 at 2:40 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)