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.