tmp/tmpzpp74ox2/{from.md → to.md}
RENAMED
|
@@ -1,57 +1,58 @@
|
|
| 1 |
#### Class member access <a id="expr.ref">[[expr.ref]]</a>
|
| 2 |
|
| 3 |
A postfix expression followed by a dot `.` or an arrow `->`, optionally
|
| 4 |
-
followed by the keyword `template`
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
For the first option (dot) the first expression shall be a glvalue. For
|
| 11 |
the second option (arrow) the first expression shall be a prvalue having
|
| 12 |
pointer type. The expression `E1->E2` is converted to the equivalent
|
| 13 |
form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
|
| 14 |
first option (dot).[^13]
|
| 15 |
|
| 16 |
Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
|
| 17 |
called the *object expression*. If the object expression is of scalar
|
| 18 |
type, `E2` shall name the pseudo-destructor of that same type (ignoring
|
| 19 |
-
cv-qualifications) and `E1.E2` is
|
| 20 |
returning `void`”.
|
| 21 |
|
| 22 |
-
[*Note
|
| 23 |
[[expr.prim.id.dtor]]. — *end note*]
|
| 24 |
|
| 25 |
Otherwise, the object expression shall be of class type. The class type
|
| 26 |
shall be complete unless the class member access appears in the
|
| 27 |
definition of that class.
|
| 28 |
|
| 29 |
-
[*Note
|
| 30 |
-
|
| 31 |
-
[[basic.scope.class]]. — *end note*]
|
| 32 |
|
| 33 |
-
|
| 34 |
-
base classes.
|
| 35 |
-
|
| 36 |
-
[*Note 3*: Because the name of a class is inserted in its class scope
|
| 37 |
-
[[class]], the name of a class is also considered a nested member of
|
| 38 |
-
that class. — *end note*]
|
| 39 |
-
|
| 40 |
-
[*Note 4*: [[basic.lookup.classref]] describes how names are looked up
|
| 41 |
after the `.` and `->` operators. — *end note*]
|
| 42 |
|
| 43 |
If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
|
| 44 |
category of `E1.E2` are determined as follows. In the remainder of
|
| 45 |
[[expr.ref]], *cq* represents either `const` or the absence of `const`
|
| 46 |
and *vq* represents either `volatile` or the absence of `volatile`. *cv*
|
| 47 |
represents an arbitrary set of cv-qualifiers, as defined in
|
| 48 |
[[basic.type.qualifier]].
|
| 49 |
|
| 50 |
If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
|
| 51 |
-
lvalue
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
- If `E2` is a static data member and the type of `E2` is `T`, then
|
| 55 |
`E1.E2` is an lvalue; the expression designates the named member of
|
| 56 |
the class. The type of `E1.E2` is `T`.
|
| 57 |
- If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
|
|
@@ -64,28 +65,48 @@ rules applies.
|
|
| 64 |
*cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
|
| 65 |
*cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
|
| 66 |
`mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
|
| 67 |
not declared to be a `mutable` member, then the type of `E1.E2` is
|
| 68 |
“*cq12* *vq12* `T`”.
|
| 69 |
-
- If `E2` is
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
- If `E2` refers to a static member function, `E1.E2` is an lvalue.
|
| 74 |
- Otherwise (when `E2` refers to a non-static member function),
|
| 75 |
`E1.E2` is a prvalue. The expression can be used only as the
|
| 76 |
left-hand operand of a member function call [[class.mfct]].
|
| 77 |
\[*Note 5*: Any redundant set of parentheses surrounding the
|
| 78 |
expression is ignored [[expr.prim.paren]]. — *end note*]
|
| 79 |
- If `E2` is a nested type, the expression `E1.E2` is ill-formed.
|
| 80 |
- If `E2` is a member enumerator and the type of `E2` is `T`, the
|
| 81 |
-
expression `E1.E2` is a prvalue
|
|
|
|
| 82 |
|
| 83 |
-
If `E2` is a non-static
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
[*Note 6*: The program is also ill-formed if the naming class is an
|
| 89 |
ambiguous base of the class type of the object expression; see
|
| 90 |
[[class.access.base]]. — *end note*]
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#### Class member access <a id="expr.ref">[[expr.ref]]</a>
|
| 2 |
|
| 3 |
A postfix expression followed by a dot `.` or an arrow `->`, optionally
|
| 4 |
+
followed by the keyword `template`, and then followed by an
|
| 5 |
+
*id-expression*, is a postfix expression. The postfix expression before
|
| 6 |
+
the dot or arrow is evaluated;[^12]
|
| 7 |
+
|
| 8 |
+
the result of that evaluation, together with the *id-expression*,
|
| 9 |
+
determines the result of the entire postfix expression.
|
| 10 |
+
|
| 11 |
+
[*Note 1*: If the keyword `template` is used, the following unqualified
|
| 12 |
+
name is considered to refer to a template [[temp.names]]. If a
|
| 13 |
+
*simple-template-id* results and is followed by a `::`, the
|
| 14 |
+
*id-expression* is a *qualified-id*. — *end note*]
|
| 15 |
|
| 16 |
For the first option (dot) the first expression shall be a glvalue. For
|
| 17 |
the second option (arrow) the first expression shall be a prvalue having
|
| 18 |
pointer type. The expression `E1->E2` is converted to the equivalent
|
| 19 |
form `(*(E1)).E2`; the remainder of [[expr.ref]] will address only the
|
| 20 |
first option (dot).[^13]
|
| 21 |
|
| 22 |
Abbreviating *postfix-expression*`.`*id-expression* as `E1.E2`, `E1` is
|
| 23 |
called the *object expression*. If the object expression is of scalar
|
| 24 |
type, `E2` shall name the pseudo-destructor of that same type (ignoring
|
| 25 |
+
cv-qualifications) and `E1.E2` is a prvalue of type “function of ()
|
| 26 |
returning `void`”.
|
| 27 |
|
| 28 |
+
[*Note 2*: This value can only be used for a notional function call
|
| 29 |
[[expr.prim.id.dtor]]. — *end note*]
|
| 30 |
|
| 31 |
Otherwise, the object expression shall be of class type. The class type
|
| 32 |
shall be complete unless the class member access appears in the
|
| 33 |
definition of that class.
|
| 34 |
|
| 35 |
+
[*Note 3*: The program is ill-formed if the result differs from that
|
| 36 |
+
when the class is complete [[class.member.lookup]]. — *end note*]
|
|
|
|
| 37 |
|
| 38 |
+
[*Note 4*: [[basic.lookup.qual]] describes how names are looked up
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
after the `.` and `->` operators. — *end note*]
|
| 40 |
|
| 41 |
If `E2` is a bit-field, `E1.E2` is a bit-field. The type and value
|
| 42 |
category of `E1.E2` are determined as follows. In the remainder of
|
| 43 |
[[expr.ref]], *cq* represents either `const` or the absence of `const`
|
| 44 |
and *vq* represents either `volatile` or the absence of `volatile`. *cv*
|
| 45 |
represents an arbitrary set of cv-qualifiers, as defined in
|
| 46 |
[[basic.type.qualifier]].
|
| 47 |
|
| 48 |
If `E2` is declared to have type “reference to `T`”, then `E1.E2` is an
|
| 49 |
+
lvalue of type `T`. If `E2` is a static data member, `E1.E2` designates
|
| 50 |
+
the object or function to which the reference is bound, otherwise
|
| 51 |
+
`E1.E2` designates the object or function to which the corresponding
|
| 52 |
+
reference member of `E1` is bound. Otherwise, one of the following rules
|
| 53 |
+
applies.
|
| 54 |
|
| 55 |
- If `E2` is a static data member and the type of `E2` is `T`, then
|
| 56 |
`E1.E2` is an lvalue; the expression designates the named member of
|
| 57 |
the class. The type of `E1.E2` is `T`.
|
| 58 |
- If `E2` is a non-static data member and the type of `E1` is “*cq1 vq1*
|
|
|
|
| 65 |
*cq12* stand for the “union” of *cq1* and *cq2*; that is, if *cq1* or
|
| 66 |
*cq2* is `const`, then *cq12* is `const`. If `E2` is declared to be a
|
| 67 |
`mutable` member, then the type of `E1.E2` is “*vq12* `T`”. If `E2` is
|
| 68 |
not declared to be a `mutable` member, then the type of `E1.E2` is
|
| 69 |
“*cq12* *vq12* `T`”.
|
| 70 |
+
- If `E2` is an overload set, function overload resolution
|
| 71 |
+
[[over.match]] is used to select the function to which `E2` refers.
|
| 72 |
+
The type of `E1.E2` is the type of `E2` and `E1.E2` refers to the
|
| 73 |
+
function referred to by `E2`.
|
| 74 |
- If `E2` refers to a static member function, `E1.E2` is an lvalue.
|
| 75 |
- Otherwise (when `E2` refers to a non-static member function),
|
| 76 |
`E1.E2` is a prvalue. The expression can be used only as the
|
| 77 |
left-hand operand of a member function call [[class.mfct]].
|
| 78 |
\[*Note 5*: Any redundant set of parentheses surrounding the
|
| 79 |
expression is ignored [[expr.prim.paren]]. — *end note*]
|
| 80 |
- If `E2` is a nested type, the expression `E1.E2` is ill-formed.
|
| 81 |
- If `E2` is a member enumerator and the type of `E2` is `T`, the
|
| 82 |
+
expression `E1.E2` is a prvalue of type `T` whose value is the value
|
| 83 |
+
of the enumerator.
|
| 84 |
|
| 85 |
+
If `E2` is a non-static member, the program is ill-formed if the class
|
| 86 |
+
of which `E2` is directly a member is an ambiguous base
|
| 87 |
+
[[class.member.lookup]] of the naming class [[class.access.base]] of
|
| 88 |
+
`E2`.
|
| 89 |
|
| 90 |
[*Note 6*: The program is also ill-formed if the naming class is an
|
| 91 |
ambiguous base of the class type of the object expression; see
|
| 92 |
[[class.access.base]]. — *end note*]
|
| 93 |
|
| 94 |
+
If `E2` is a non-static member and the result of `E1` is an object whose
|
| 95 |
+
type is not similar [[conv.qual]] to the type of `E1`, the behavior is
|
| 96 |
+
undefined.
|
| 97 |
+
|
| 98 |
+
[*Example 1*:
|
| 99 |
+
|
| 100 |
+
``` cpp
|
| 101 |
+
struct A { int i; };
|
| 102 |
+
struct B { int j; };
|
| 103 |
+
struct D : A, B {};
|
| 104 |
+
void f() {
|
| 105 |
+
D d;
|
| 106 |
+
static_cast<B&>(d).j; // OK, object expression designates the B subobject of d
|
| 107 |
+
reinterpret_cast<B&>(d).j; // undefined behavior
|
| 108 |
+
}
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
— *end example*]
|
| 112 |
+
|