Bug 3841 – silent implicit cast from floating point to integral in += etc. operators

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-02-22T10:28:00Z
Last change time
2017-07-19T17:43:20Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2010-02-22T10:28:45Z
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.
Comment #1 by andrei — 2010-04-27T11:53:59Z
Hell yeah it is major. Thanks Don.
Comment #2 by clem — 2015-05-10T19:10:02Z
Comment #3 by clem — 2015-05-13T18:23:39Z
Comment #4 by github-bugzilla — 2015-05-14T01:55:21Z
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.
Comment #5 by github-bugzilla — 2015-05-14T11:04:04Z
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).
Comment #6 by github-bugzilla — 2015-05-19T17:25:48Z
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
Comment #7 by github-bugzilla — 2015-06-17T21:02:44Z
Comment #8 by github-bugzilla — 2015-06-17T21:05:18Z
Comment #9 by dlang-bugzilla — 2017-07-05T12:57:21Z
*** Issue 17600 has been marked as a duplicate of this issue. ***
Comment #10 by github-bugzilla — 2017-07-19T17:41:38Z
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
Comment #11 by github-bugzilla — 2017-07-19T17:43:20Z
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