Skip to content

Commit 1b408f8

Browse files
authored
Merge pull request #2132 from WalterBright/AssignExp-spec
Improve AssignExpression documentation
2 parents e3a49b3 + 38ad9a7 commit 1b408f8

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

spec/expression.dd

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ left-to-right order.)
2222
assert(text(++i, ++i) == "1415"); // left to right evaluation of arguments
2323
-------------
2424

25-
$(P But even though the order of evaluation is well defined, writing code that
26-
depends on it is rarely recommended.
27-
$(B Note that dmd currently does not comply with left to right evaluation of
28-
function arguments and AssignExpression.)
29-
)
25+
$(IMPLEMENTATION_DEFINED
26+
$(OL
27+
$(LI The order of evaluation of the operands of $(GLINK AssignExpression).)
28+
$(LI The order of evaluation of function arguments.)
29+
))
30+
31+
$(BEST_PRACTICE Even though the order of evaluation is well defined, writing code that
32+
depends on it is rarely recommended.)
3033

3134
$(H2 $(LEGACY_LNAME2 Expression, expression, Expressions))
3235

@@ -42,7 +45,7 @@ $(GNAME CommaExpression):
4245
$(P The left operand of the $(D ,) is evaluated, then the right operand
4346
is evaluated. The type of the expression is the type of the right
4447
operand, and the result is the result of the right operand. Using
45-
the result is derecated.
48+
the result is deprecated.
4649
)
4750

4851
$(H2 $(LNAME2 assign_expressions, Assign Expressions))
@@ -66,13 +69,41 @@ $(GNAME AssignExpression):
6669
$(GLINK ConditionalExpression) $(D ^^=) $(I AssignExpression)
6770
)
6871

69-
$(P The right operand is implicitly converted to the type of the
70-
left operand, and assigned to it. The result type is the type
71-
of the left operand, and the result value is the value of the left
72-
operand after the assignment.
72+
$(P For all assign expressions, the left operand must be a modifiable
73+
lvalue. The type of the assign expression is the type of the left
74+
operand, and the value is the value of the left operand after assignment
75+
occurs. The resulting expression is a modifiable lvalue.
76+
)
77+
78+
$(UNDEFINED_BEHAVIOR
79+
$(OL
80+
$(LI if the lvalue and rvalue have partially overlapping storage)
81+
$(LI if the lvalue and rvalue's storage overlaps exactly but the types are different)
82+
))
83+
84+
$(H3 $(LNAME2 simple_assignment_expressions, Simple Assignment Expression))
85+
86+
$(P If the operator is $(D =) then it is simple assignment.
87+
The right operand is implicitly converted to the type of the
88+
left operand, and assigned to it.)
89+
90+
$(P If the left and right operands are of the same struct type, and the struct
91+
type has a $(GLINK2 struct, Postblit), then the copy operation is
92+
as described in $(DDSUBLINK spec/struct, struct-postblit, Struct Postblit).
93+
)
94+
95+
$(P If the lvalue is the `.length` property of a dynamic array, the behavior is
96+
as described in $(DDSUBLINK spec/array, resize, Setting Dynamic Array Length).
7397
)
7498

75-
$(P The left operand must be an lvalue.)
99+
$(P If the lvalue is a static array or a slice, the behavior is as
100+
described in $(DDSUBLINK spec/array, array-copying, Array Copying) and
101+
$(DDSUBLINK spec/array, array-setting, Array Setting).
102+
)
103+
104+
$(P If the lvalue is a user-defined property, the behavior is as
105+
described in $(DDSUBLINK spec/function, property-functions, Property Functions).
106+
)
76107

77108
$(H3 $(LNAME2 assignment_operator_expressions, Assignment Operator Expressions))
78109

0 commit comments

Comments
 (0)