Strange behaviour on virtual inheritance

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behaviour on virtual inheritance

Kristóf Umann 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
Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour on virtual inheritance

Kristóf Umann via cfe-dev
On 8/8/19 12:49 PM, Mustafa Kemal GILOR via cfe-dev wrote:

>
> 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.
>

This is probably https://bugs.llvm.org/show_bug.cgi?id=28591


--
Regards,
  Mikhail Maltsev
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev