Summary: | Integral promotion rules not being followed | ||
---|---|---|---|
Product: | D | Reporter: | Walter Bright <bugzilla> |
Component: | dmd | Assignee: | No Owner <nobody> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | eyal |
Priority: | P1 | ||
Version: | D2 | ||
Hardware: | All | ||
OS: | All | ||
See Also: |
https://issues.dlang.org/show_bug.cgi?id=16997 https://issues.dlang.org/show_bug.cgi?id=17633 https://issues.dlang.org/show_bug.cgi?id=5132 |
Johan Engelen reports: import core.stdc.stdio; void main() { uint total = 0; void add(int x) { total += x; } ubyte popCount() { return 5; } add(popCount()); add(-popCount()); printf("%u\n", total); // different result from C } The trouble is that -popCount() negates the ubyte before promoting to int, instead of after.
16997 has a more succint test case. *** This issue has been marked as a duplicate of issue 16997 ***