tmp/tmpc32c0ybz/{from.md → to.md}
RENAMED
|
@@ -4,15 +4,17 @@ The assignment operator (`=`) and the compound assignment operators all
|
|
| 4 |
group right-to-left. All require a modifiable lvalue as their left
|
| 5 |
operand and return an lvalue referring to the left operand. The result
|
| 6 |
in all cases is a bit-field if the left operand is a bit-field. In all
|
| 7 |
cases, the assignment is sequenced after the value computation of the
|
| 8 |
right and left operands, and before the value computation of the
|
| 9 |
-
assignment expression.
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
lvalue-to-rvalue conversion and the side effect associated with any
|
| 13 |
-
single compound assignment operator.
|
| 14 |
|
| 15 |
``` bnf
|
| 16 |
assignment-expression:
|
| 17 |
conditional-expression
|
| 18 |
logical-or-expression assignment-operator initializer-clause
|
|
@@ -33,31 +35,33 @@ operand.
|
|
| 33 |
|
| 34 |
If the left operand is of class type, the class shall be complete.
|
| 35 |
Assignment to objects of a class is defined by the copy/move assignment
|
| 36 |
operator ([[class.copy]], [[over.ass]]).
|
| 37 |
|
| 38 |
-
For class objects, assignment is not in general the same as
|
| 39 |
initialization ([[dcl.init]], [[class.ctor]], [[class.init]],
|
| 40 |
-
[[class.copy]]).
|
| 41 |
|
| 42 |
-
When the left operand of an assignment operator
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
The behavior of an expression of the form `E1` *op*`=` `E2` is
|
| 47 |
equivalent to `E1 = E1` *op* `E2` except that `E1` is evaluated only
|
| 48 |
once. In `+=` and `-=`, `E1` shall either have arithmetic type or be a
|
| 49 |
pointer to a possibly cv-qualified completely-defined object type. In
|
| 50 |
all other cases, `E1` shall have arithmetic type.
|
| 51 |
|
| 52 |
-
If the value being stored in an object is
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
A *braced-init-list* may appear on the right-hand side of
|
| 61 |
|
| 62 |
- an assignment to a scalar, in which case the initializer list shall
|
| 63 |
have at most a single element. The meaning of `x = {v}`, where `T` is
|
|
@@ -66,14 +70,18 @@ A *braced-init-list* may appear on the right-hand side of
|
|
| 66 |
- an assignment to an object of class type, in which case the
|
| 67 |
initializer list is passed as the argument to the assignment operator
|
| 68 |
function selected by overload resolution ([[over.ass]],
|
| 69 |
[[over.match]]).
|
| 70 |
|
|
|
|
|
|
|
| 71 |
``` cpp
|
| 72 |
complex<double> z;
|
| 73 |
z = { 1,2 }; // meaning z.operator=({1,2\)}
|
| 74 |
z += { 1, 2 }; // meaning z.operator+=({1,2\)}
|
| 75 |
int a, b;
|
| 76 |
a = b = { 1 }; // meaning a=b=1;
|
| 77 |
a = { 1 } = b; // syntax error
|
| 78 |
```
|
| 79 |
|
|
|
|
|
|
|
|
|
| 4 |
group right-to-left. All require a modifiable lvalue as their left
|
| 5 |
operand and return an lvalue referring to the left operand. The result
|
| 6 |
in all cases is a bit-field if the left operand is a bit-field. In all
|
| 7 |
cases, the assignment is sequenced after the value computation of the
|
| 8 |
right and left operands, and before the value computation of the
|
| 9 |
+
assignment expression. The right operand is sequenced before the left
|
| 10 |
+
operand. With respect to an indeterminately-sequenced function call, the
|
| 11 |
+
operation of a compound assignment is a single evaluation.
|
| 12 |
+
|
| 13 |
+
[*Note 1*: Therefore, a function call shall not intervene between the
|
| 14 |
lvalue-to-rvalue conversion and the side effect associated with any
|
| 15 |
+
single compound assignment operator. — *end note*]
|
| 16 |
|
| 17 |
``` bnf
|
| 18 |
assignment-expression:
|
| 19 |
conditional-expression
|
| 20 |
logical-or-expression assignment-operator initializer-clause
|
|
|
|
| 35 |
|
| 36 |
If the left operand is of class type, the class shall be complete.
|
| 37 |
Assignment to objects of a class is defined by the copy/move assignment
|
| 38 |
operator ([[class.copy]], [[over.ass]]).
|
| 39 |
|
| 40 |
+
[*Note 2*: For class objects, assignment is not in general the same as
|
| 41 |
initialization ([[dcl.init]], [[class.ctor]], [[class.init]],
|
| 42 |
+
[[class.copy]]). — *end note*]
|
| 43 |
|
| 44 |
+
When the left operand of an assignment operator is a bit-field that
|
| 45 |
+
cannot represent the value of the expression, the resulting value of the
|
| 46 |
+
bit-field is *implementation-defined*.
|
| 47 |
|
| 48 |
The behavior of an expression of the form `E1` *op*`=` `E2` is
|
| 49 |
equivalent to `E1 = E1` *op* `E2` except that `E1` is evaluated only
|
| 50 |
once. In `+=` and `-=`, `E1` shall either have arithmetic type or be a
|
| 51 |
pointer to a possibly cv-qualified completely-defined object type. In
|
| 52 |
all other cases, `E1` shall have arithmetic type.
|
| 53 |
|
| 54 |
+
If the value being stored in an object is read via another object that
|
| 55 |
+
overlaps in any way the storage of the first object, then the overlap
|
| 56 |
+
shall be exact and the two objects shall have the same type, otherwise
|
| 57 |
+
the behavior is undefined.
|
| 58 |
+
|
| 59 |
+
[*Note 3*: This restriction applies to the relationship between the
|
| 60 |
+
left and right sides of the assignment operation; it is not a statement
|
| 61 |
+
about how the target of the assignment may be aliased in general. See
|
| 62 |
+
[[basic.lval]]. — *end note*]
|
| 63 |
|
| 64 |
A *braced-init-list* may appear on the right-hand side of
|
| 65 |
|
| 66 |
- an assignment to a scalar, in which case the initializer list shall
|
| 67 |
have at most a single element. The meaning of `x = {v}`, where `T` is
|
|
|
|
| 70 |
- an assignment to an object of class type, in which case the
|
| 71 |
initializer list is passed as the argument to the assignment operator
|
| 72 |
function selected by overload resolution ([[over.ass]],
|
| 73 |
[[over.match]]).
|
| 74 |
|
| 75 |
+
[*Example 1*:
|
| 76 |
+
|
| 77 |
``` cpp
|
| 78 |
complex<double> z;
|
| 79 |
z = { 1,2 }; // meaning z.operator=({1,2\)}
|
| 80 |
z += { 1, 2 }; // meaning z.operator+=({1,2\)}
|
| 81 |
int a, b;
|
| 82 |
a = b = { 1 }; // meaning a=b=1;
|
| 83 |
a = { 1 } = b; // syntax error
|
| 84 |
```
|
| 85 |
|
| 86 |
+
— *end example*]
|
| 87 |
+
|