tmp/tmpy5nh1rdd/{from.md → to.md}
RENAMED
|
@@ -2,61 +2,79 @@
|
|
| 2 |
|
| 3 |
The unary `*` operator performs *indirection*: the expression to which
|
| 4 |
it is applied shall be a pointer to an object type, or a pointer to a
|
| 5 |
function type and the result is an lvalue referring to the object or
|
| 6 |
function to which the expression points. If the type of the expression
|
| 7 |
-
is “pointer to `T`
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
to a
|
|
|
|
| 12 |
|
| 13 |
The result of each of the following unary operators is a prvalue.
|
| 14 |
|
| 15 |
The result of the unary `&` operator is a pointer to its operand. The
|
| 16 |
operand shall be an lvalue or a *qualified-id*. If the operand is a
|
| 17 |
-
*qualified-id* naming a non-static member `m` of some class
|
| 18 |
-
type `T`, the result has type “pointer to member of class `C`
|
| 19 |
-
`T`” and is a prvalue designating `C::m`. Otherwise, if the type
|
| 20 |
-
expression is `T`, the result has type “pointer to `T`” and is a
|
| 21 |
-
that is the address of the designated object ([[intro.memory]])
|
| 22 |
-
pointer to the designated function.
|
| 23 |
-
|
| 24 |
-
cv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
``` cpp
|
| 27 |
struct A { int i; };
|
| 28 |
struct B : A { };
|
| 29 |
... &B::i ... // has type int A::*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 37 |
-
operand is a *qualified-id* not enclosed in parentheses.
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
to the type “pointer to function”
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 48 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 49 |
the built-in meaning or the operator function is called. The operand of
|
| 50 |
`&` shall not be a bit-field.
|
| 51 |
|
| 52 |
The address of an overloaded function (Clause [[over]]) can be taken
|
| 53 |
only in a context that uniquely determines which version of the
|
| 54 |
-
overloaded function is referred to (see [[over.over]]).
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
The operand of the unary `+` operator shall have arithmetic, unscoped
|
| 60 |
enumeration, or pointer type and the result is the value of the
|
| 61 |
argument. Integral promotion is performed on integral or enumeration
|
| 62 |
operands. The type of the result is the type of the promoted operand.
|
|
@@ -72,12 +90,17 @@ The operand of the logical negation operator `!` is contextually
|
|
| 72 |
converted to `bool` (Clause [[conv]]); its value is `true` if the
|
| 73 |
converted operand is `false` and `false` otherwise. The type of the
|
| 74 |
result is `bool`.
|
| 75 |
|
| 76 |
The operand of `~` shall have integral or unscoped enumeration type; the
|
| 77 |
-
result is the
|
| 78 |
performed. The type of the result is the type of the promoted operand.
|
| 79 |
-
There is an ambiguity in the
|
| 80 |
-
*class-name* or *decltype-specifier*. The ambiguity is resolved
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
|
|
|
| 2 |
|
| 3 |
The unary `*` operator performs *indirection*: the expression to which
|
| 4 |
it is applied shall be a pointer to an object type, or a pointer to a
|
| 5 |
function type and the result is an lvalue referring to the object or
|
| 6 |
function to which the expression points. If the type of the expression
|
| 7 |
+
is “pointer to `T`”, the type of the result is “`T`”.
|
| 8 |
+
|
| 9 |
+
[*Note 1*: Indirection through a pointer to an incomplete type (other
|
| 10 |
+
than *cv* `void`) is valid. The lvalue thus obtained can be used in
|
| 11 |
+
limited ways (to initialize a reference, for example); this lvalue must
|
| 12 |
+
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 13 |
|
| 14 |
The result of each of the following unary operators is a prvalue.
|
| 15 |
|
| 16 |
The result of the unary `&` operator is a pointer to its operand. The
|
| 17 |
operand shall be an lvalue or a *qualified-id*. If the operand is a
|
| 18 |
+
*qualified-id* naming a non-static or variant member `m` of some class
|
| 19 |
+
`C` with type `T`, the result has type “pointer to member of class `C`
|
| 20 |
+
of type `T`” and is a prvalue designating `C::m`. Otherwise, if the type
|
| 21 |
+
of the expression is `T`, the result has type “pointer to `T`” and is a
|
| 22 |
+
prvalue that is the address of the designated object ([[intro.memory]])
|
| 23 |
+
or a pointer to the designated function.
|
| 24 |
+
|
| 25 |
+
[*Note 2*: In particular, the address of an object of type “cv `T`” is
|
| 26 |
+
“pointer to cv `T`”, with the same cv-qualification. — *end note*]
|
| 27 |
+
|
| 28 |
+
For purposes of pointer arithmetic ([[expr.add]]) and comparison (
|
| 29 |
+
[[expr.rel]], [[expr.eq]]), an object that is not an array element whose
|
| 30 |
+
address is taken in this way is considered to belong to an array with
|
| 31 |
+
one element of type `T`.
|
| 32 |
+
|
| 33 |
+
[*Example 1*:
|
| 34 |
|
| 35 |
``` cpp
|
| 36 |
struct A { int i; };
|
| 37 |
struct B : A { };
|
| 38 |
... &B::i ... // has type int A::*
|
| 39 |
+
int a;
|
| 40 |
+
int* p1 = &a;
|
| 41 |
+
int* p2 = p1 + 1; // defined behavior
|
| 42 |
+
bool b = p2 > p1; // defined behavior, with value true
|
| 43 |
```
|
| 44 |
|
| 45 |
+
— *end example*]
|
| 46 |
+
|
| 47 |
+
[*Note 3*: A pointer to member formed from a `mutable` non-static data
|
| 48 |
+
member ([[dcl.stc]]) does not reflect the `mutable` specifier
|
| 49 |
+
associated with the non-static data member. — *end note*]
|
| 50 |
|
| 51 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 52 |
+
operand is a *qualified-id* not enclosed in parentheses.
|
| 53 |
+
|
| 54 |
+
[*Note 4*: That is, the expression `&(qualified-id)`, where the
|
| 55 |
+
*qualified-id* is enclosed in parentheses, does not form an expression
|
| 56 |
+
of type “pointer to member”. Neither does `qualified-id`, because there
|
| 57 |
+
is no implicit conversion from a *qualified-id* for a non-static member
|
| 58 |
+
function to the type “pointer to member function” as there is from an
|
| 59 |
+
lvalue of function type to the type “pointer to function” (
|
| 60 |
+
[[conv.func]]). Nor is `&unqualified-id` a pointer to member, even
|
| 61 |
+
within the scope of the *unqualified-id*’s class. — *end note*]
|
| 62 |
|
| 63 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 64 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 65 |
the built-in meaning or the operator function is called. The operand of
|
| 66 |
`&` shall not be a bit-field.
|
| 67 |
|
| 68 |
The address of an overloaded function (Clause [[over]]) can be taken
|
| 69 |
only in a context that uniquely determines which version of the
|
| 70 |
+
overloaded function is referred to (see [[over.over]]).
|
| 71 |
+
|
| 72 |
+
[*Note 5*: Since the context might determine whether the operand is a
|
| 73 |
+
static or non-static member function, the context can also affect
|
| 74 |
+
whether the expression has type “pointer to function” or “pointer to
|
| 75 |
+
member function”. — *end note*]
|
| 76 |
|
| 77 |
The operand of the unary `+` operator shall have arithmetic, unscoped
|
| 78 |
enumeration, or pointer type and the result is the value of the
|
| 79 |
argument. Integral promotion is performed on integral or enumeration
|
| 80 |
operands. The type of the result is the type of the promoted operand.
|
|
|
|
| 90 |
converted to `bool` (Clause [[conv]]); its value is `true` if the
|
| 91 |
converted operand is `false` and `false` otherwise. The type of the
|
| 92 |
result is `bool`.
|
| 93 |
|
| 94 |
The operand of `~` shall have integral or unscoped enumeration type; the
|
| 95 |
+
result is the ones’ complement of its operand. Integral promotions are
|
| 96 |
performed. The type of the result is the type of the promoted operand.
|
| 97 |
+
There is an ambiguity in the grammar when `~` is followed by a
|
| 98 |
+
*class-name* or *decltype-specifier*. The ambiguity is resolved by
|
| 99 |
+
treating `~` as the unary complement operator rather than as the start
|
| 100 |
+
of an *unqualified-id* naming a destructor.
|
| 101 |
+
|
| 102 |
+
[*Note 6*: Because the grammar does not permit an operator to follow
|
| 103 |
+
the `.`, `->`, or `::` tokens, a `~` followed by a *class-name* or
|
| 104 |
+
*decltype-specifier* in a member access expression or *qualified-id* is
|
| 105 |
+
unambiguously parsed as a destructor name. — *end note*]
|
| 106 |
|