[cfe-dev] Strange behaviour on virtual inheritance

Mustafa Kemal GILOR via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 8 04:49:43 PDT 2019


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190808/9f339202/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error.log
Type: text/x-log
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190808/9f339202/attachment.bin>


More information about the cfe-dev mailing list