www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13112] New: Ignore constness when copying dynamic array

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

          Issue ID: 13112
           Summary: Ignore constness when copying dynamic array argument
                    to static array parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P4
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com

void f(char[1] arr) {}

void main()
{
    string s;
    f(s);
}

This program currently doesn't compile:

test.d(6): Error: function test.f (char[1] arr) is not callable using argument
types (string)

However, the conversion is safe, because a copy is implicitly created during
dynamic->static conversion, and the array type (char) has no indirections.

Note that this limitation only seems to apply to function parameters, as the
following works fine:

string s; char[1] arr = s;

--
Jul 12 2014