Bug 17600 – implicit float->int cast using += operator
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-07-05T12:54:00Z
Last change time
2017-07-06T12:36:00Z
Assigned to
nobody
Creator
simon.buerger
Comments
Comment #0 by simon.buerger — 2017-07-05T12:54:36Z
The following code should not compile but it does, using an implicit cast that should not be allowed.
void main()
{
int x;
float y;
x += y; // implicitly casts y to int !
}
Comment #1 by dlang-bugzilla — 2017-07-05T12:57:21Z
This is a warning since 2.068.0 (implemented in https://github.com/dlang/dmd/pull/4643). Please update your compiler or enable warnings with the -w switch.
*** This issue has been marked as a duplicate of issue 3841 ***
Comment #2 by simon.buerger — 2017-07-06T12:36:00Z
I expected "x += y" to be equivalent to "x = x + y" (in which case an error is generated). Sorry I didn't check the spec, everything is actually correct. (but really surprising behavior IMHO). My bad.