Skip to content

Commit cef24c8

Browse files
committed
[spec/expression] op= will not allow truncating conversions
1 parent 37a5d89 commit cef24c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

spec/expression.dd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,19 @@ $(H3 $(LNAME2 assignment_operator_expressions, Assignment Operator Expressions))
423423
$(LI the left operand of $(D >>>=) does not undergo $(INTEGER_PROMOTIONS) before shifting.)
424424
)
425425

426+
$(P Narrowing conversions are allowed. Truncating conversions will be an error.)
427+
428+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
429+
---
430+
void f(short s)
431+
{
432+
byte b;
433+
b += s; // OK, though it may overflow
434+
//b += 1.5F; // Deprecated, truncation
435+
}
436+
---
437+
)
438+
426439
$(P For user-defined types, assignment operator expressions are
427440
$(DDSUBLINK spec/operatoroverloading, op-assign, overloaded separately) from
428441
the binary operators. Still the left operand must be an lvalue.

0 commit comments

Comments
 (0)