www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22646] New: [REG2.099] CT bounds checking ignores short

https://issues.dlang.org/show_bug.cgi?id=22646

          Issue ID: 22646
           Summary: [REG2.099] CT bounds checking ignores short circuit
                    evaluation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

///////////////////////// 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

--
Jan 03 2022