@@ -458,23 +458,51 @@ void test()
458
458
$(DDSUBLINK spec/expression, assignment_operator_expressions, operator assignment)
459
459
is equivalent to `e = cast(E)(e + 4)`.)
460
460
461
- $(H3 $(LNAME2 disallowed-conversions, Preserving Bit Patterns))
461
+ $(H3 $(LEGACY_LNAME2 disallowed-conversions, integer-conversions, Integer Type Conversions))
462
+
463
+ $(P An integer of type `I` implicitly converts to another integer type `J` when
464
+ `J.sizeof >= I.sizeof`.)
465
+
466
+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
467
+ ---
468
+ void f(byte b, ubyte ub, short s)
469
+ {
470
+ b = ub; // OK, bit pattern same
471
+ ub = b; // OK, bit pattern same
472
+ s = b; // OK, widening conversion
473
+ b = s; // error, implicit narrowing
474
+ }
475
+ ---
476
+ )
462
477
463
478
$(P Integer values cannot be implicitly converted to another
464
- type that cannot represent the integer bit pattern after integral
465
- promotion. For example:)
479
+ type that cannot represent the integer bit pattern after
480
+ $(RELATIVE_LINK2 integer-promotions, integral promotion) . For example:)
466
481
467
482
$(SPEC_RUNNABLE_EXAMPLE_FAIL
468
483
---
469
- ubyte u1 = -1; // error, -1 cannot be represented in a ubyte
470
- ushort u2 = -1; // error, -1 cannot be represented in a ushort
471
- uint u3 = int(-1); // ok, -1 can be represented in an int, which can be converted to a uint
472
- ulong u4 = long(-1) ; // ok, -1 can be represented in a long, which can be converted to a ulong
484
+ ubyte u1 = -1; // error, -1 cannot be represented in a ubyte
485
+ ushort u2 = -1; // error, -1 cannot be represented in a ushort
486
+ uint u3 = -1; // ok, -1 can be represented in an int, which can be converted to a uint
487
+ ulong u4 = -1 ; // ok, -1 can be represented in a long, which can be converted to a ulong
473
488
---
474
489
)
475
490
476
- * Floating point types cannot be implicitly converted to
477
- integral types.
491
+ $(H3 $(LNAME2 floating-point-conversions, Floating Point Type Conversions))
492
+
493
+ * Integral types implicitly convert to floating point types.
494
+ * Floating point types cannot be implicitly converted to integral types.
495
+
496
+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
497
+ ---
498
+ void f(int i, float f)
499
+ {
500
+ f = i; // OK
501
+ i = f; // error
502
+ }
503
+ ---
504
+ )
505
+
478
506
* Complex or imaginary floating point types cannot be implicitly converted
479
507
to non-complex floating point types.
480
508
* Non-complex floating point types cannot be implicitly converted to imaginary floating
0 commit comments