Bug 22646 – [REG2.099] CT bounds checking ignores short circuit evaluation

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-03T17:56:17Z
Last change time
2024-05-25T03:55:46Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev
See also
https://issues.dlang.org/show_bug.cgi?id=18115, https://issues.dlang.org/show_bug.cgi?id=24566

Comments

Comment #0 by dlang-bugzilla — 2022-01-03T17:56:17Z
///////////////////////// test.d ///////////////////////// static template Bug(string name) { enum bool ok = name.length < 3 || name[0..3] != "pad"; } pragma(msg, Bug!"x".ok); pragma(msg, Bug!"foo".ok); pragma(msg, Bug!"pad".ok); pragma(msg, Bug!"pad123".ok); ////////////////////////////////////////////////////////// This now fails with: test.d(3): Error: in slice `"x"[0 .. 3]`, upper bound is greater than array length `1` test.d(6): Error: template instance `test.Bug!"x"` error instantiating test.d(6): while evaluating `pragma(msg, Bug!"x".ok)` Introduced in https://github.com/dlang/dmd/pull/13169
Comment #1 by dlang-bugzilla — 2022-01-03T18:00:15Z
Worth mentioning that this code also did not work in 2.078.0 through 2.080.0. Broken in: https://github.com/dlang/dmd/pull/7225 Fixed in: https://github.com/dlang/dmd/pull/8261 (and again broken in https://github.com/dlang/dmd/pull/13169)
Comment #2 by b2.temp — 2022-01-04T05:36:05Z
you might be interested by the explanations in the comments of https://issues.dlang.org/show_bug.cgi?id=18115. This was identical issue but with &&.
Comment #3 by dlang-bot — 2022-01-18T11:55:43Z
@RazvanN7 created dlang/dmd pull request #13542 "Fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation" fixing this issue: - Fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation https://github.com/dlang/dmd/pull/13542
Comment #4 by dlang-bot — 2022-01-18T13:15:30Z
dlang/dmd pull request #13542 "Fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation" was merged into master: - 8f193572300fd23c2e46459ee333cfc8cfd37652 by RazvanN7: Fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation https://github.com/dlang/dmd/pull/13542
Comment #5 by moonlightsentinel — 2022-01-18T14:21:37Z
The patch does not work for static arrays that are also affected by this regression: static template Bug(T, const T name) { enum bool ok = name.length < 3 || name[0..3] != "pad"; } pragma(msg, Bug!(char[1], "x").ok);
Comment #6 by b2.temp — 2022-01-18T21:57:03Z
that PR looks like a bad workaround.
Comment #7 by b2.temp — 2022-01-18T22:06:27Z
the real bug is in optimize(), where D does const fold
Comment #8 by dlang-bot — 2022-12-20T13:52:40Z
@ibuclaw created dlang/dmd pull request #14722 "fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation" fixing this issue: - fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation https://github.com/dlang/dmd/pull/14722
Comment #9 by dlang-bot — 2022-12-21T09:18:27Z
dlang/dmd pull request #14722 "fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation" was merged into stable: - 59d7cb9667a992c187e121615a224ba9b30d5f7b by Iain Buclaw: fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation https://github.com/dlang/dmd/pull/14722
Comment #10 by dlang-bot — 2023-01-01T06:25:06Z
dlang/dmd pull request #14765 "merge stable" was merged into master: - 57874f498053152ec18e4ebe5be95337ebf83b3b by Iain Buclaw: fix Issue 22646 - [REG2.099] CT bounds checking ignores short circuit evaluation https://github.com/dlang/dmd/pull/14765