From Jason Turner

[class.access.base]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp9u518m74/{from.md → to.md} +23 -23
tmp/tmp9u518m74/{from.md → to.md} RENAMED
@@ -36,17 +36,17 @@ Here `B` is a public base of `D2`, `D4`, and `D6`, a private base of
36
 
37
  — *end example*]
38
 
39
  [*Note 1*:
40
 
41
- A member of a private base class might be inaccessible as an inherited
42
- member name, but accessible directly. Because of the rules on pointer
43
- conversions [[conv.ptr]] and explicit casts ([[expr.type.conv]],
44
- [[expr.static.cast]], [[expr.cast]]), a conversion from a pointer to a
45
- derived class to a pointer to an inaccessible base class might be
46
- ill-formed if an implicit conversion is used, but well-formed if an
47
- explicit cast is used. For example,
48
 
49
  ``` cpp
50
  class B {
51
  public:
52
  int mi; // non-static member
@@ -65,24 +65,24 @@ void DD::f() {
65
  b.mi = 3; // OK (b.mi is different from this->mi)
66
  b.si = 3; // OK (b.si is different from this->si)
67
  ::B::si = 3; // OK
68
  ::B* bp1 = this; // error: B is a private base class
69
  ::B* bp2 = (::B*)this; // OK with cast
70
- bp2->mi = 3; // OK: access through a pointer to B.
71
  }
72
  ```
73
 
74
  — *end note*]
75
 
76
  A base class `B` of `N` is *accessible* at *R*, if
77
 
78
  - an invented public member of `B` would be a public member of `N`, or
79
- - *R* occurs in a member or friend of class `N`, and an invented public
80
- member of `B` would be a private or protected member of `N`, or
81
- - *R* occurs in a member or friend of a class `P` derived from `N`, and
82
- an invented public member of `B` would be a private or protected
83
- member of `P`, or
84
  - there exists a class `S` such that `B` is a base class of `S`
85
  accessible at *R* and `S` is a base class of `N` accessible at *R*.
86
 
87
  [*Example 2*:
88
 
@@ -106,20 +106,20 @@ class N: private S {
106
  ```
107
 
108
  — *end example*]
109
 
110
  If a base class is accessible, one can implicitly convert a pointer to a
111
- derived class to a pointer to that base class ([[conv.ptr]],
112
- [[conv.mem]]).
113
 
114
  [*Note 2*: It follows that members and friends of a class `X` can
115
  implicitly convert an `X*` to a pointer to a private or protected
116
  immediate base class of `X`. — *end note*]
117
 
118
  The access to a member is affected by the class in which the member is
119
- named. This naming class is the class in which the member name was
120
- looked up and found.
121
 
122
  [*Note 3*: This class can be explicit, e.g., when a *qualified-id* is
123
  used, or implicit, e.g., when a class member access operator
124
  [[expr.ref]] is used (including cases where an implicit “`this->`” is
125
  added). If both a class member access operator and a *qualified-id* are
@@ -128,15 +128,15 @@ is the class denoted by the *nested-name-specifier* of the
128
  *qualified-id* (that is, `T`). — *end note*]
129
 
130
  A member `m` is accessible at the point *R* when named in class `N` if
131
 
132
  - `m` as a member of `N` is public, or
133
- - `m` as a member of `N` is private, and *R* occurs in a member or
134
- friend of class `N`, or
135
- - `m` as a member of `N` is protected, and *R* occurs in a member or
136
- friend of class `N`, or in a member of a class `P` derived from `N`,
137
- where `m` as a member of `P` is public, private, or protected, or
138
  - there exists a base class `B` of `N` that is accessible at *R*, and
139
  `m` is accessible at *R* when named in class `B`.
140
  \[*Example 3*:
141
  ``` cpp
142
  class B;
@@ -145,11 +145,11 @@ A member `m` is accessible at the point *R* when named in class `N` if
145
  int i;
146
  friend void f(B*);
147
  };
148
  class B : public A { };
149
  void f(B* p) {
150
- p->i = 1; // OK: B* can be implicitly converted to A*, and f has access to i in A
151
  }
152
  ```
153
 
154
  — *end example*]
155
 
 
36
 
37
  — *end example*]
38
 
39
  [*Note 1*:
40
 
41
+ A member of a private base class can be inaccessible as inherited, but
42
+ accessible directly. Because of the rules on pointer conversions
43
+ [[conv.ptr]] and explicit casts
44
+ [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]], a conversion
45
+ from a pointer to a derived class to a pointer to an inaccessible base
46
+ class can be ill-formed if an implicit conversion is used, but
47
+ well-formed if an explicit cast is used. For example,
48
 
49
  ``` cpp
50
  class B {
51
  public:
52
  int mi; // non-static member
 
65
  b.mi = 3; // OK (b.mi is different from this->mi)
66
  b.si = 3; // OK (b.si is different from this->si)
67
  ::B::si = 3; // OK
68
  ::B* bp1 = this; // error: B is a private base class
69
  ::B* bp2 = (::B*)this; // OK with cast
70
+ bp2->mi = 3; // OK, access through a pointer to B.
71
  }
72
  ```
73
 
74
  — *end note*]
75
 
76
  A base class `B` of `N` is *accessible* at *R*, if
77
 
78
  - an invented public member of `B` would be a public member of `N`, or
79
+ - *R* occurs in a direct member or friend of class `N`, and an invented
80
+ public member of `B` would be a private or protected member of `N`, or
81
+ - *R* occurs in a direct member or friend of a class `P` derived from
82
+ `N`, and an invented public member of `B` would be a private or
83
+ protected member of `P`, or
84
  - there exists a class `S` such that `B` is a base class of `S`
85
  accessible at *R* and `S` is a base class of `N` accessible at *R*.
86
 
87
  [*Example 2*:
88
 
 
106
  ```
107
 
108
  — *end example*]
109
 
110
  If a base class is accessible, one can implicitly convert a pointer to a
111
+ derived class to a pointer to that base class
112
+ [[conv.ptr]], [[conv.mem]].
113
 
114
  [*Note 2*: It follows that members and friends of a class `X` can
115
  implicitly convert an `X*` to a pointer to a private or protected
116
  immediate base class of `X`. — *end note*]
117
 
118
  The access to a member is affected by the class in which the member is
119
+ named. This naming class is the class in whose scope name lookup
120
+ performed a search that found the member.
121
 
122
  [*Note 3*: This class can be explicit, e.g., when a *qualified-id* is
123
  used, or implicit, e.g., when a class member access operator
124
  [[expr.ref]] is used (including cases where an implicit “`this->`” is
125
  added). If both a class member access operator and a *qualified-id* are
 
128
  *qualified-id* (that is, `T`). — *end note*]
129
 
130
  A member `m` is accessible at the point *R* when named in class `N` if
131
 
132
  - `m` as a member of `N` is public, or
133
+ - `m` as a member of `N` is private, and *R* occurs in a direct member
134
+ or friend of class `N`, or
135
+ - `m` as a member of `N` is protected, and *R* occurs in a direct member
136
+ or friend of class `N`, or in a member of a class `P` derived from
137
+ `N`, where `m` as a member of `P` is public, private, or protected, or
138
  - there exists a base class `B` of `N` that is accessible at *R*, and
139
  `m` is accessible at *R* when named in class `B`.
140
  \[*Example 3*:
141
  ``` cpp
142
  class B;
 
145
  int i;
146
  friend void f(B*);
147
  };
148
  class B : public A { };
149
  void f(B* p) {
150
+ p->i = 1; // OK, B* can be implicitly converted to A*, and f has access to i in A
151
  }
152
  ```
153
 
154
  — *end example*]
155