Strange behaviour on virtual inheritance

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Strange behaviour on virtual inheritance

Nathan Ridge via cfe-dev
Hello all,

I've encountered a strange behaviour while messing with virtual inheritance. Assume that we have the following structures;

struct foo{
    void f(){}
};

template<typename B>
struct bar : private virtual B{ }; // A template struct which uses CRTP

struct zxe : public foo{};

And we have a struct, which inherits from both zxe, and bar at the same time.

struct qua  :  public bar<zxe>,       // restricting foo access  
                     public virtual zxe      // providing public foo access                         
{ };

int main(void) {
    qua q;
    q.f();
}

When we try to call f() on an instance of qua, the compiler throws the following error;

"cannot cast 'qua' to its private base class 'foo'"

But, if we change order of inheritance, the error disappears.

struct qua  :  public virtual zxe,      // providing public foo access     
                     public bar<zxe>        // restricting foo access             
{ };

Is this a bug, or related to standard?  I've tried same example in GCC 9.1, 8.1, 4.9 and both versions are compiled just fine. 

The full error log is available in attachments.

Thanks in advance,
Mustafa



_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

error.log (2K) Download Attachment