Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4643 from legrosbuffle/fix3841
Issue 3841: silent implicit cast from floating point to integral in += etc. operators
- Loading branch information
Showing
4 changed files
with
121 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// PERMUTE_ARGS: | ||
// REQUIRED_ARGS: -w -o- | ||
|
||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/b3841.d-mixin-31(31): Warning: char += float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: int += float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: long += double is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: char -= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: int -= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: long -= double is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: char *= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: int *= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: long *= double is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: char /= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: int /= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: long /= double is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: char %= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: int %= float is performing truncating conversion | ||
fail_compilation/b3841.d-mixin-31(31): Warning: long %= double is performing truncating conversion | ||
--- | ||
*/ | ||
|
||
|
||
void f(string op, LHS, RHS)() | ||
{ | ||
// pragma(msg, LHS, " += ", RHS); | ||
LHS a; | ||
RHS b; | ||
mixin("a "~op~" b;"); | ||
} | ||
|
||
template Ops(T...) | ||
{ | ||
alias Ops = T; | ||
} | ||
|
||
void main() | ||
{ | ||
foreach (string op; Ops!("+=", "-=", "*=", "/=", "%=")) | ||
{ | ||
// OK | ||
f!(op, int, int)(); | ||
f!(op, long, int)(); | ||
f!(op, long, short)(); | ||
f!(op, float, long)(); | ||
f!(op, cfloat, long)(); | ||
f!(op, double, float)(); | ||
|
||
// Should that really be OK ? | ||
f!(op, short, int)(); | ||
f!(op, float, double)(); | ||
|
||
// Not OK, truncating conversion. | ||
f!(op, char, float)(); | ||
f!(op, int, float)(); | ||
f!(op, long, double)(); | ||
} | ||
|
||
foreach (string op; Ops!("+=", "-=")) | ||
{ | ||
// OK | ||
f!(op, idouble, ifloat)(); | ||
|
||
// Should that really be OK ? | ||
f!(op, ifloat, idouble)(); | ||
} | ||
|
||
// OK | ||
f!("^^=", int, int)(); | ||
f!("^^=", long, int)(); | ||
f!("^^=", long, short)(); | ||
f!("^^=", float, long)(); | ||
f!("^^=", double, float)(); | ||
// Should that really be OK ? | ||
f!("^^=", float, double)(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters