[llvm-bugs] [Bug 35462] New: dynamic_cast to virtual base with multiple access control

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 29 07:28:29 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35462

            Bug ID: 35462
           Summary: dynamic_cast to virtual base with multiple access
                    control
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: stephane.zimmermann at trust-in-soft.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following code:

struct Foo {
    int x = 42;
    virtual void f() {}
};

struct PublicBar: public virtual Foo { };
struct PrivateBar: private virtual Foo { };

struct EntryPoint {
    virtual void g() {}
};

struct Baz: PublicBar, PrivateBar, EntryPoint {};

int main(void) {
    Baz b;
    EntryPoint *e = &b;
    Foo *f = dynamic_cast<Foo *>(e);
    return f->x;
}

when compiled and executed causes a segmentation fault because the dynamic_cast
is failing.

The dynamic cast should not fail, as the Foo base is unique because it is
virtual and is accessible because of the path PublicBar::Foo.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171129/0d92ad3d/attachment.html>


More information about the llvm-bugs mailing list