New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 3841: silent implicit cast from floating point to integral in += etc. operators #4643
Conversation
e58ccfe
to
b29f8f0
Compare
The large function being moved from one place to another in the file makes it very, very difficult to review. |
I've un-moved the function |
{ | ||
if ((type->isintegral() && t2->isfloating())) | ||
{ | ||
error("%s %s %s is undefined (refusing to perform truncating conversion)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be made a warning, because it will force people to change their code. The idea is warning, then deprecation, then finally error, after some major time has elapsed.
Thanks for undoing the code movement. Now I can see what changed! |
de2b848
to
01b3f92
Compare
// pragma(msg, LHS, " += ", RHS); | ||
LHS a; | ||
RHS b; | ||
a += b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but also need to test -=, *=, /=, %= and ^^=
thx!! please add the extra tests |
Done, thanks for the review. |
Auto-merge toggled on |
Issue 3841: silent implicit cast from floating point to integral in += etc. operators
Note that this might break some existing code that relies on bad behaviour, but I think it's important to fix. For example, there are three such instances in phobos, and one of them is obviously bogus:
int chunksize, extra, numchunks;
...
chunksize += extra / cast(double)numchunks;
(I'll send a pull request to phobos)