[Issue 3066] New: Array operation without a slice as the lvalue accepted, bad codegen

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 13 06:50:27 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3066

           Summary: Array operation without a slice as the lvalue
                    accepted, bad codegen
           Product: D
           Version: 1.045
          Platform: x86_64
               URL: http://www.digitalmars.com/d/1.0/arrays.html
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid, diagnostic, spec, wrong-code
          Severity: major
          Priority: P3
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: matti.niemenmaa+dbugzilla at iki.fi


The below code compiles, but shouldn't: array operations can't be used as
initializers according to the spec, they need a slice as the lvalue.

void main() {
    auto x = [2,3,4];
    auto y = [1,1,1];
    auto z = x[] - y[];
    assert (z == [1,2,3]);
}

The assertion fails: z becomes a dynamic array with length 0 and an invalid
pointer.

A similarly incorrect array results with most other operators. Using +,
however, gives the following strange diagnostic:

foo.d(5): Error: Array operation x[] + y[] not implemented

This makes no sense, since x[] + y[] itself is perfectly fine as well as
implemented.

Replacing 'auto z' with 'int[3] z' makes all cases succeed, but that
contradicts the spec. IMHO there's no reason why using array operations as
initializers should be invalid but that's what the spec currently says; added
the 'spec' keyword to this in the hopes that this is legalized.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list