Title
Protected members and access via qualified-id
Status
drafting
Section
11.8.5 [class.protected]
Submitter
Hubert Tong

Created on 2015-10-16.00:00:00 last changed 80 months ago

Messages

Date: 2022-02-18.07:47:23

The following line in the example in 11.8.5 [class.protected] paragraph 1 is no longer allowed following the change from issue 1873:

  class B {
  protected:
    int i;
    static int j;
  };
  // ...
  class D2 : public B {
    friend void fr(B*, D1*, D2*);
    void mem(B*, D1*);
  };
  void fr(B* pb, D1* p1, D2* p2) {
    // ...
    p2->B::i = 4;  // OK (access through a D2, even though naming class is B)
    // ...
  }

The example line ought to work, but none of the bullets in 11.8.3 [class.access.base] paragraph 5 apply:

A member m is accessible at the point R when named in class N if
  • m as a member of N is public, or
  • m as a member of N is private, and R occurs in a direct member or friend of class N, or
  • m as a member of N is protected, and R occurs in a direct member or friend of class N, or in a member of a class P derived from N, where m as a member of P is public, private, or protected, or
  • there exists a base class B of N that is accessible at R, and m is accessible at R when named in class B.

One aproach might be that 11.8.3 [class.access.base] bullet 5.3 should also consider friends of a class P derived from N where P is the type of the object expression (if any) or a base class thereof, and m as a member of P is public, protected, or private.

History
Date User Action Args
2018-04-11 00:00:00adminsetstatus: open -> drafting
2015-10-16 00:00:00admincreate