D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4682 - [CTFE] Run-time Vs Compile-time of int.min % -1
Summary: [CTFE] Run-time Vs Compile-time of int.min % -1
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-08-19 14:34 UTC by bearophile_hugs
Modified: 2017-02-24 20:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-08-19 14:34:54 UTC
With dmd 2.048 this program gives (on Windows) a runtime error:

int foo(int x, int y) {
    return x % y;
}
void main() {
    int r = foo(int.min, -1);
}



But the same operation done at compile time gives no errors, and foo returns 0:

int foo(int x, int y) {
    return x % y;
}
static assert(foo(int.min, -1) == 0);
void main() {}


So one of the two cases is wrong (or both).

While floating point operations done at compile-time may give slightly different results, I'd like integral operations to give the same results at compile-time and run-time.
Comment 2 github-bugzilla 2017-02-11 23:55:59 UTC
Commit pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/a4cedfa2a50fdf899991e0b67a7acdbb2d872e88
add test case for Issue 4682
Comment 3 github-bugzilla 2017-02-24 20:34:39 UTC
Commit pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/a4cedfa2a50fdf899991e0b67a7acdbb2d872e88
add test case for Issue 4682