llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.13k stars 12.02k forks source link

Can't implicitly cast from class with multiple inheritance to a base of a virtually base class if public inheritance follows after private or protected, but not before them #28965

Open llvmbot opened 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 28591
Version 3.1
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @Quuxplusone,@DougGregor,@miyuki,@rprichard,@vabr-g

Extended Description

# version: clang-703.0.31, 
# sample.cpp
class foo {};
class foofoo: public foo {};
class private_bar: private virtual foofoo {};
class public_bar: public virtual foofoo {};
class foobar_public_first: public public_bar, public private_bar {};
class foobar_private_first: public private_bar, public public_bar {};

void test_foobar() {
    foo *foo1 = new foobar_public_first(); // OK
    foo *foo2 = new foobar_private_first(); // compile error - "Cannot cast 'foobar_private_first' to its private base class 'foo'"
}

So, availability of casting to base depends on how ancestor classes are ordered in the inheritance list.

d0027324-493a-46be-8448-4091c7735e73 commented 6 years ago

This issue also seems to have the same root cause as llvm/llvm-bugzilla-archive#32180 .

rprichard commented 7 years ago

This issue looks related to (or is a duplicate of) issue 19795: llvm/llvm-project#20169

Quuxplusone commented 7 years ago

I have also hit this bug, both on Xcode and on top-of-tree Clang. My test case is exactly isomorphic to Maxim's test case.