void main() { uint a; float b = 0.1; a += b; } This program compiles no problem. This is obviously a problem and a very surprising behavior; I'm at the end of a 2-hours bug chasing and tried this only after I eliminated all other opportunities for error. For numeric types, It is ok for built-in += to perform narrowing conversion, but not truncating ones.
Hell yeah it is major. Thanks Don.
pull https://github.com/D-Programming-Language/dmd/pull/4643
pull https://github.com/D-Programming-Language/phobos/pull/3278
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/8558b22cfe818b48c6b5efdb1a0439cf6c7e9fa7 Remove a bad cast (issue 3841). Functional noop. https://github.com/D-Programming-Language/phobos/commit/4ba5fc4d581e577eb09c1ccf8604f40a02083651 Merge pull request #3278 from legrosbuffle/fix3841_phobos Remove a bad cast (Required for fixing issue 3841). Functional noop.
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/0109acf3a2452580e354fab182dd148d5f921d3d Avoid silent truncating conversions (issue 3841). https://github.com/D-Programming-Language/druntime/commit/254c8ee9371af2cd85a6f74fcfd583a370d31254 Merge pull request #1268 from legrosbuffle/explicit-truncating-conversions Avoid silent truncating conversions (issue 3841).
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bd259864438f9150d0eac592252978c48c09d533 Merge pull request #4643 from legrosbuffle/fix3841 Issue 3841: silent implicit cast from floating point to integral in += etc. operators
Commits pushed to stable at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/0109acf3a2452580e354fab182dd148d5f921d3d Avoid silent truncating conversions (issue 3841). https://github.com/D-Programming-Language/druntime/commit/254c8ee9371af2cd85a6f74fcfd583a370d31254 Merge pull request #1268 from legrosbuffle/explicit-truncating-conversions
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bd259864438f9150d0eac592252978c48c09d533 Merge pull request #4643 from legrosbuffle/fix3841
*** Issue 17600 has been marked as a duplicate of this issue. ***
Commits pushed to dmd-cxx at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/0109acf3a2452580e354fab182dd148d5f921d3d Avoid silent truncating conversions (issue 3841). https://github.com/dlang/druntime/commit/254c8ee9371af2cd85a6f74fcfd583a370d31254 Merge pull request #1268 from legrosbuffle/explicit-truncating-conversions
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8558b22cfe818b48c6b5efdb1a0439cf6c7e9fa7 Remove a bad cast (issue 3841). Functional noop. https://github.com/dlang/phobos/commit/4ba5fc4d581e577eb09c1ccf8604f40a02083651 Merge pull request #3278 from legrosbuffle/fix3841_phobos