www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13276] New: No overlap or length equality test in compiler

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

          Issue ID: 13276
           Summary: No overlap or length equality test in compiler
                    generated array operations
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: verylonglogin.reg gmail.com

Compiler generated array operations truncates second (and third if any) slice
length to the first slice length and has no overlap check.

This code should NOT run fine:
---
void main()
{
    alias T = short;

    T[] a2 = new T[2];
    T[] a3 = (new T[3])[] = 1;
    T[] b2 = new T[2];
    T[] b3 = new T[3];

//  a2[] += a3[]; // ok, throws as runtime function called

//  a3[] -= a2[];        // ok, throws
//  b3[] = a2[] - a3[];  // ok, throws
//  b3[] = a3[] - a2[];  // ok, throws

    // Should throw:
    // (same for '*', '/', '^', '&', and '|')
    a2[] -= a3[];
    a2[] -= a2[];
    b2[] = a2[] - a3[];
    b2[] = a3[] - a2[];
}
---

--
Aug 10 2014