www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6286] New: Static arrays can not be assigned from const(T)[N] to T[N]

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286

           Summary: Static arrays can not be assigned from const(T)[N] to
                    T[N]
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ludwig informatik.uni-luebeck.de



01:52:55 PDT ---
The following snipped worked up to DMD 2.053 but fails on 2.054:

---
void test()
{
    const(int)[4] src = [1, 2, 3, 4];
    int[4] dst;
    dst = src; // Error: cannot implicitly convert expression (src) of type
const(int[4u]) to int[]
    dst[] = src[]; // still works
}
---

The assignment "T[N] = const(T)[N]" should work as long as "T = const(T)" works
as there is no aliasing goind on but just a plain copy.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
I don't think that this is a bug but rather than dmd used to be buggy with
regards to this case.

dst = src;

is assigning src to dst. And assigning a dynamic array to a static one isn't
legal. If

dst = src;

were allowed, then it would be inconsistent with the case where both dst and
src are dynamic arrays.

dst[] = src[];

on the other hand is specifically copying the elements of src to the elements
of dst. So, it's possible that this is a regression and that

dst = src;

is supposed to just translate to

dst[] = src[];

when dst is a static array, but I think that it's far more likely that this is
a case where a long-standing bug was fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286




04:09:49 PDT ---
Note that in the test case both, the source and the destination are static
arrays of the same size. There is no reason why a direct assignment should not
work here. I think the compiler mistakes the left side here as a dynamic array.

In the case of really assigning a dynamic array to a static one, the decision
is definitely not so obvious as it could lead to a hidden runtime error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
                 CC|                            |yebblies gmail.com
            Summary|Static arrays can not be    |Regression(2.054): Static
                   |assigned from const(T)[N]   |arrays can not be assigned
                   |to T[N]                     |from const(T)[N] to T[N]



I fear this one was my fault!

https://github.com/D-Programming-Language/dmd/pull/232

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286




PDT ---
Ah yes. I didn't read carefully enough. If both src and dst are static arrays,
then

dst = src;

should work. It's when one is a dynamic array that it shouldn't.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 11 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6286


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



12:34:48 PDT ---
https://github.com/D-Programming-Language/dmd/commit/d29588f3410b85625559c6af5118fce484fd05af

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