From Jason Turner

[expr.assign]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp4y_k9y90/{from.md → to.md} +89 -0
tmp/tmp4y_k9y90/{from.md → to.md} RENAMED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Assignment and compound assignment operators <a id="expr.assign">[[expr.assign]]</a>
2
+
3
+ The assignment operator (`=`) and the compound assignment operators all
4
+ group right-to-left. All require a modifiable lvalue as their left
5
+ operand; their result is an lvalue of the type of the left operand,
6
+ referring to the left operand. The result in all cases is a bit-field if
7
+ the left operand is a bit-field. In all cases, the assignment is
8
+ sequenced after the value computation of the right and left operands,
9
+ and before the value computation of the assignment expression. The right
10
+ operand is sequenced before the left operand. With respect to an
11
+ indeterminately-sequenced function call, the operation of a compound
12
+ assignment is a single evaluation.
13
+
14
+ [*Note 1*: Therefore, a function call cannot intervene between the
15
+ lvalue-to-rvalue conversion and the side effect associated with any
16
+ single compound assignment operator. — *end note*]
17
+
18
+ ``` bnf
19
+ assignment-expression:
20
+ conditional-expression
21
+ yield-expression
22
+ throw-expression
23
+ logical-or-expression assignment-operator initializer-clause
24
+ ```
25
+
26
+ ``` bnf
27
+ assignment-operator: one of
28
+ '= *= /= %= += -= >>= <<= &= ^= |='
29
+ ```
30
+
31
+ In simple assignment (`=`), let `V` be the result of the right operand;
32
+ the object referred to by the left operand is modified [[defns.access]]
33
+ by replacing its value with `V` or, if the object is of integer type,
34
+ with the value congruent [[basic.fundamental]] to `V`.
35
+
36
+ If the right operand is an expression, it is implicitly converted
37
+ [[conv]] to the cv-unqualified type of the left operand.
38
+
39
+ When the left operand of an assignment operator is a bit-field that
40
+ cannot represent the value of the expression, the resulting value of the
41
+ bit-field is *implementation-defined*.
42
+
43
+ An assignment whose left operand is of a volatile-qualified type is
44
+ deprecated [[depr.volatile.type]] unless the (possibly parenthesized)
45
+ assignment is a discarded-value expression or an unevaluated operand
46
+ [[term.unevaluated.operand]].
47
+
48
+ The behavior of an expression of the form `E1 op= E2` is equivalent to
49
+ `E1 = E1 op E2` except that `E1` is evaluated only once.
50
+
51
+ [*Note 2*: The object designated by `E1` is accessed
52
+ twice. — *end note*]
53
+
54
+ For `+=` and `-=`, `E1` shall either have arithmetic type or be a
55
+ pointer to a possibly cv-qualified completely-defined object type. In
56
+ all other cases, `E1` shall have arithmetic type.
57
+
58
+ If the value being stored in an object is read via another object that
59
+ overlaps in any way the storage of the first object, then the overlap
60
+ shall be exact and the two objects shall have the same type, otherwise
61
+ the behavior is undefined.
62
+
63
+ [*Note 3*: This restriction applies to the relationship between the
64
+ left and right sides of the assignment operation; it is not a statement
65
+ about how the target of the assignment can be aliased in general. See 
66
+ [[basic.lval]]. — *end note*]
67
+
68
+ A *braced-init-list* B may appear on the right-hand side of
69
+
70
+ - an assignment to a scalar of type `T`, in which case B shall have at
71
+ most a single element. The meaning of `x = B` is `x = t`, where `t` is
72
+ an invented temporary variable declared and initialized as `T t = B`.
73
+ - an assignment to an object of class type, in which case B is passed as
74
+ the argument to the assignment operator function selected by overload
75
+ resolution [[over.assign]], [[over.match]].
76
+
77
+ [*Example 1*:
78
+
79
+ ``` cpp
80
+ complex<double> z;
81
+ z = { 1,2 }; // meaning z.operator=({1,2\)}
82
+ z += { 1, 2 }; // meaning z.operator+=({1,2\)}
83
+ int a, b;
84
+ a = b = { 1 }; // meaning a=b=1;
85
+ a = { 1 } = b; // syntax error
86
+ ```
87
+
88
+ — *end example*]
89
+