[llvm-bugs] [Bug 30604] New: A data member reached by several paths through a multiple inheritance does not receive maximum access

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 3 16:17:50 PDT 2016


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

            Bug ID: 30604
           Summary: A data member reached by several paths through a
                    multiple inheritance does not receive maximum access
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: iliyaaizin at mail.tau.ac.il
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

In the following code:
//////////////////////////
struct S2
{
   int n = 1;
};

struct S3: virtual S2 {};
struct S4: virtual S3 {};
struct S6: protected S4, virtual S3 {};

int main (int argc, char* argv[])
{
    S6 obj;
    int num = obj.n;

    return 0;
}
///////////////////////////////

data member n is inherited twice by S6, once public and once protected.
According to C++11 standard, section 11.6 [class.paths]: the access is that of
the path that gives most access. That means n should by public in S6, and
therefor accessible from main.
But we get the following compilation error:
////////////////////////////////////////////
clang.cpp:13:12: error: cannot cast 'S6' to its protected base class 'S2'
        int num = obj.n;
                  ^
clang.cpp:8:12: note: constrained by protected inheritance here
struct S6: protected S4, virtual S3 {};
           ^~~~~~~~~~~~
clang.cpp:13:16: error: 'n' is a protected member of 'S2'
        int num = obj.n;
                      ^
clang.cpp:8:12: note: constrained by protected inheritance here
struct S6: protected S4, virtual S3 {};
           ^~~~~~~~~~~~
clang.cpp:3:8: note: member is declared here
   int n = 1;
       ^
2 errors generated.
/////////////////////////////////////////////////
The command used to compile is: clang file.cpp -std=c++11 -o file.exe
Compiler version:
clang version 3.8.1 (branches/release_38)
Target: i686-pc-windows-msvc
Thread model: posix

-- 
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/20161003/17402404/attachment-0001.html>


More information about the llvm-bugs mailing list