The following code should not exhibit divide-by-zero errors because short circuit evaluation should not execute the divides: int test() { int x = 0; int a = x && 1 / x; int b = !x || 1 / x; int c = x ? 1 / x : 1; int d = !x ? 1 : 1 / x; return a | b | c; } This happens in the backend because the optimizer propagates the 0 value of x.
@WalterBright created dlang/dmd pull request #11252 "fix Issue 20906 - unnecessary divide-by-zero errors when constant fol…" fixing this issue: - fix Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits https://github.com/dlang/dmd/pull/11252
@WalterBright created dlang/druntime pull request #3130 "workaround Issue 20906 - unnecessary divide-by-zero errors when const…" mentioning this issue: - workaround Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits https://github.com/dlang/druntime/pull/3130
dlang/dmd pull request #11252 "fix Issue 20906 - unnecessary divide-by-zero errors when constant fol…" was merged into master: - 25e34d5edab438dfd31185c5f0619d145e335805 by Walter Bright: fix Issue 20906 - unnecessary divide-by-zero errors when constant folding short circuits https://github.com/dlang/dmd/pull/11252