tmp/tmp6czboaxm/{from.md → to.md}
RENAMED
|
@@ -1,32 +1,41 @@
|
|
| 1 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 2 |
|
| 3 |
The unary `*` operator performs *indirection*. Its operand shall be a
|
| 4 |
prvalue of type “pointer to `T`”, where `T` is an object or function
|
| 5 |
-
type. The operator yields an lvalue of type `T`
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
[*Note 1*:
|
|
|
|
|
|
|
|
|
|
| 9 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 10 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 11 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 12 |
|
| 13 |
Each of the following unary operators yields a prvalue.
|
| 14 |
|
| 15 |
The operand of the unary `&` operator shall be an lvalue of some type
|
| 16 |
-
`T`.
|
| 17 |
|
| 18 |
-
- If the operand is a *qualified-id*
|
| 19 |
-
member `m`
|
| 20 |
-
function,
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
- Otherwise, the result has type “pointer to `T`” and points to the
|
| 23 |
designated object [[intro.memory]] or function [[basic.compound]]. If
|
| 24 |
-
the operand
|
| 25 |
-
operand shall be a *qualified-id*
|
| 26 |
-
|
| 27 |
-
“pointer to cv `T`”. — *end note*]
|
| 28 |
|
| 29 |
[*Example 1*:
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
struct A { int i; };
|
|
@@ -38,18 +47,19 @@ int* p2 = p1 + 1; // defined behavior
|
|
| 38 |
bool b = p2 > p1; // defined behavior, with value true
|
| 39 |
```
|
| 40 |
|
| 41 |
— *end example*]
|
| 42 |
|
| 43 |
-
[*Note
|
| 44 |
member [[dcl.stc]] does not reflect the `mutable` specifier associated
|
| 45 |
with the non-static data member. — *end note*]
|
| 46 |
|
| 47 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 48 |
-
operand is a *qualified-id* not enclosed in
|
|
|
|
| 49 |
|
| 50 |
-
[*Note
|
| 51 |
*qualified-id* is enclosed in parentheses, does not form an expression
|
| 52 |
of type “pointer to member”. Neither does `qualified-id`, because there
|
| 53 |
is no implicit conversion from a *qualified-id* for a non-static member
|
| 54 |
function to the type “pointer to member function” as there is from an
|
| 55 |
lvalue of function type to the type “pointer to function” [[conv.func]].
|
|
@@ -59,52 +69,54 @@ the *unqualified-id*’s class. — *end note*]
|
|
| 59 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 60 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 61 |
the built-in meaning or the operator function is called. The operand of
|
| 62 |
`&` shall not be a bit-field.
|
| 63 |
|
| 64 |
-
[*Note
|
| 65 |
a context that uniquely determines which function is referred to (see
|
| 66 |
[[over.over]]). Since the context can affect whether the operand is a
|
| 67 |
static or non-static member function, the context can also affect
|
| 68 |
whether the expression has type “pointer to function” or “pointer to
|
| 69 |
member function”. — *end note*]
|
| 70 |
|
| 71 |
-
The operand of the unary `+` operator shall
|
| 72 |
-
enumeration, or pointer type and the result is the value of the
|
| 73 |
argument. Integral promotion is performed on integral or enumeration
|
| 74 |
operands. The type of the result is the type of the promoted operand.
|
| 75 |
|
| 76 |
-
The operand of the unary `-` operator shall
|
| 77 |
-
enumeration type and the result is the negative of its
|
| 78 |
-
promotion is performed on integral or enumeration
|
| 79 |
-
of an unsigned quantity is computed by
|
| 80 |
-
where n is the number of bits in the
|
| 81 |
-
result is the type of the promoted
|
|
|
|
| 82 |
|
| 83 |
-
[*Note
|
| 84 |
operand and result are considered as unsigned). — *end note*]
|
| 85 |
|
| 86 |
The operand of the logical negation operator `!` is contextually
|
| 87 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 88 |
operand is `false` and `false` otherwise. The type of the result is
|
| 89 |
`bool`.
|
| 90 |
|
| 91 |
-
The operand of the `~` operator shall
|
| 92 |
-
enumeration type. Integral promotions are performed. The type
|
| 93 |
-
result is the type of the promoted operand. Given the
|
| 94 |
-
of the base-2 representation [[basic.fundamental]] of
|
| 95 |
-
operand `x`, the coefficient `rᵢ` of the base-2
|
| 96 |
-
result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
|
| 97 |
|
| 98 |
-
[*Note
|
| 99 |
operand and result are considered as unsigned). — *end note*]
|
| 100 |
|
| 101 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 102 |
-
*type-name* or *
|
| 103 |
treating `~` as the operator rather than as the start of an
|
| 104 |
*unqualified-id* naming a destructor.
|
| 105 |
|
| 106 |
-
[*Note
|
| 107 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 108 |
-
*
|
| 109 |
-
unambiguously parsed as a destructor
|
|
|
|
| 110 |
|
|
|
|
| 1 |
#### Unary operators <a id="expr.unary.op">[[expr.unary.op]]</a>
|
| 2 |
|
| 3 |
The unary `*` operator performs *indirection*. Its operand shall be a
|
| 4 |
prvalue of type “pointer to `T`”, where `T` is an object or function
|
| 5 |
+
type. The operator yields an lvalue of type `T`. If the operand points
|
| 6 |
+
to an object or function, the result denotes that object or function;
|
| 7 |
+
otherwise, the behavior is undefined except as specified in
|
| 8 |
+
[[expr.typeid]].
|
| 9 |
|
| 10 |
+
[*Note 1*: Indirection through a pointer to an out-of-lifetime object
|
| 11 |
+
is valid [[basic.life]]. — *end note*]
|
| 12 |
+
|
| 13 |
+
[*Note 2*: Indirection through a pointer to an incomplete type (other
|
| 14 |
than cv `void`) is valid. The lvalue thus obtained can be used in
|
| 15 |
limited ways (to initialize a reference, for example); this lvalue must
|
| 16 |
not be converted to a prvalue, see [[conv.lval]]. — *end note*]
|
| 17 |
|
| 18 |
Each of the following unary operators yields a prvalue.
|
| 19 |
|
| 20 |
The operand of the unary `&` operator shall be an lvalue of some type
|
| 21 |
+
`T`.
|
| 22 |
|
| 23 |
+
- If the operand is a *qualified-id* or *splice-expression* designating
|
| 24 |
+
a non-static member `m`, other than an explicit object member
|
| 25 |
+
function, `m` shall be a direct member of some class `C` that is not
|
| 26 |
+
an anonymous union. The result has type “pointer to member of class
|
| 27 |
+
`C` of type `T`” and designates `C::m`. \[*Note 3*: A *qualified-id*
|
| 28 |
+
that names a member of a namespace-scope anonymous union is considered
|
| 29 |
+
to be a class member access expression [[expr.prim.id.general]] and
|
| 30 |
+
cannot be used to form a pointer to member. — *end note*]
|
| 31 |
- Otherwise, the result has type “pointer to `T`” and points to the
|
| 32 |
designated object [[intro.memory]] or function [[basic.compound]]. If
|
| 33 |
+
the operand designates an explicit object member function [[dcl.fct]],
|
| 34 |
+
the operand shall be a *qualified-id* or a *splice-expression*.
|
| 35 |
+
\[*Note 4*: In particular, taking the address of a variable of type
|
| 36 |
+
“cv `T`” yields a pointer of type “pointer to cv `T`”. — *end note*]
|
| 37 |
|
| 38 |
[*Example 1*:
|
| 39 |
|
| 40 |
``` cpp
|
| 41 |
struct A { int i; };
|
|
|
|
| 47 |
bool b = p2 > p1; // defined behavior, with value true
|
| 48 |
```
|
| 49 |
|
| 50 |
— *end example*]
|
| 51 |
|
| 52 |
+
[*Note 5*: A pointer to member formed from a `mutable` non-static data
|
| 53 |
member [[dcl.stc]] does not reflect the `mutable` specifier associated
|
| 54 |
with the non-static data member. — *end note*]
|
| 55 |
|
| 56 |
A pointer to member is only formed when an explicit `&` is used and its
|
| 57 |
+
operand is a *qualified-id* or *splice-expression* not enclosed in
|
| 58 |
+
parentheses.
|
| 59 |
|
| 60 |
+
[*Note 6*: That is, the expression `&(qualified-id)`, where the
|
| 61 |
*qualified-id* is enclosed in parentheses, does not form an expression
|
| 62 |
of type “pointer to member”. Neither does `qualified-id`, because there
|
| 63 |
is no implicit conversion from a *qualified-id* for a non-static member
|
| 64 |
function to the type “pointer to member function” as there is from an
|
| 65 |
lvalue of function type to the type “pointer to function” [[conv.func]].
|
|
|
|
| 69 |
If `&` is applied to an lvalue of incomplete class type and the complete
|
| 70 |
type declares `operator&()`, it is unspecified whether the operator has
|
| 71 |
the built-in meaning or the operator function is called. The operand of
|
| 72 |
`&` shall not be a bit-field.
|
| 73 |
|
| 74 |
+
[*Note 7*: The address of an overload set [[over]] can be taken only in
|
| 75 |
a context that uniquely determines which function is referred to (see
|
| 76 |
[[over.over]]). Since the context can affect whether the operand is a
|
| 77 |
static or non-static member function, the context can also affect
|
| 78 |
whether the expression has type “pointer to function” or “pointer to
|
| 79 |
member function”. — *end note*]
|
| 80 |
|
| 81 |
+
The operand of the unary `+` operator shall be a prvalue of arithmetic,
|
| 82 |
+
unscoped enumeration, or pointer type and the result is the value of the
|
| 83 |
argument. Integral promotion is performed on integral or enumeration
|
| 84 |
operands. The type of the result is the type of the promoted operand.
|
| 85 |
|
| 86 |
+
The operand of the unary `-` operator shall be a prvalue of arithmetic
|
| 87 |
+
or unscoped enumeration type and the result is the negative of its
|
| 88 |
+
operand. Integral promotion is performed on integral or enumeration
|
| 89 |
+
operands. The negative of an unsigned quantity is computed by
|
| 90 |
+
subtracting its value from 2ⁿ, where n is the number of bits in the
|
| 91 |
+
promoted operand. The type of the result is the type of the promoted
|
| 92 |
+
operand.
|
| 93 |
|
| 94 |
+
[*Note 8*: The result is the two’s complement of the operand (where
|
| 95 |
operand and result are considered as unsigned). — *end note*]
|
| 96 |
|
| 97 |
The operand of the logical negation operator `!` is contextually
|
| 98 |
converted to `bool` [[conv]]; its value is `true` if the converted
|
| 99 |
operand is `false` and `false` otherwise. The type of the result is
|
| 100 |
`bool`.
|
| 101 |
|
| 102 |
+
The operand of the `~` operator shall be a prvalue of integral or
|
| 103 |
+
unscoped enumeration type. Integral promotions are performed. The type
|
| 104 |
+
of the result is the type of the promoted operand. Given the
|
| 105 |
+
coefficients `xᵢ` of the base-2 representation [[basic.fundamental]] of
|
| 106 |
+
the promoted operand `x`, the coefficient `rᵢ` of the base-2
|
| 107 |
+
representation of the result `r` is 1 if `xᵢ` is 0, and 0 otherwise.
|
| 108 |
|
| 109 |
+
[*Note 9*: The result is the ones’ complement of the operand (where
|
| 110 |
operand and result are considered as unsigned). — *end note*]
|
| 111 |
|
| 112 |
There is an ambiguity in the grammar when `~` is followed by a
|
| 113 |
+
*type-name* or *computed-type-specifier*. The ambiguity is resolved by
|
| 114 |
treating `~` as the operator rather than as the start of an
|
| 115 |
*unqualified-id* naming a destructor.
|
| 116 |
|
| 117 |
+
[*Note 10*: Because the grammar does not permit an operator to follow
|
| 118 |
the `.`, `->`, or `::` tokens, a `~` followed by a *type-name* or
|
| 119 |
+
*computed-type-specifier* in a member access expression or
|
| 120 |
+
*qualified-id* is unambiguously parsed as a destructor
|
| 121 |
+
name. — *end note*]
|
| 122 |
|