Bug 60829 - Illegal access to private base of public base granted.
Summary: Illegal access to private base of public base granted.
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2014-04-12 00:25 UTC by arm.nahm
Modified: 2021-07-23 12:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.7.3, 4.8.3, 4.9.0
Last reconfirmed: 2021-07-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description arm.nahm 2014-04-12 00:25:29 UTC
struct A{};
class B: A {};
struct C: A {};
struct D: B, C {
    D() { B::a = 0; }
};

The above code compiles in g++, even though the standard does not allow D access to any member of the private base class A of public base class B.
Comment 2 Marc Glisse 2014-04-12 06:16:09 UTC
(In reply to arm.nahm from comment #0)
> The above code compiles in g++,

No it doesn't. Please make sure to copy-paste directly from a file you have tested.
Comment 3 Markus Trippelsdorf 2014-04-12 06:35:42 UTC
markus@x4 /tmp % cat test.ii
class A
{
public:
  int a;
};

class B : private A
{
};

class C : public A
{
};

class D : public B, public C
{
  D () { B::a = 0; }
};

markus@x4 /tmp % g++ -c test.ii
markus@x4 /tmp % clang++ -c test.ii
test.ii:17:13: error: cannot cast 'B' to its private base class 'A'
  D () { B::a = 0; }
            ^
test.ii:7:11: note: declared private here
class B : private A
          ^~~~~~~~~
test.ii:17:13: error: 'a' is a private member of 'A'
  D () { B::a = 0; }
            ^
test.ii:7:11: note: constrained by private inheritance here
class B : private A
          ^~~~~~~~~
test.ii:4:7: note: member is declared here
  int a;
      ^
2 errors generated.
Comment 4 Markus Trippelsdorf 2014-04-14 14:55:58 UTC
EDG also rejects the code:

test.ii(17): error #308: member "A::a" (declared at line 4) is inaccessible
    D () { B::a = 0; }
              ^
Comment 5 Richard Biener 2014-06-12 13:52:32 UTC
Unsetting target milestone of open non-regression bug from version of branch being closed.