Thread overview
[Issue 4791] New: Assigning a static array to itself should be allowed
Sep 03, 2010
David Simcha
Sep 03, 2010
David Simcha
September 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4791

           Summary: Assigning a static array to itself should be allowed
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2010-09-02 21:48:58 PDT ---
void main() {
    int[2] foo;
    foo = foo;
}

object.Exception: overlapping array copy

This is a ridiculous limitation and is bugs waiting to happen.  (For example, Bug 4789.)  Even if this requires a simple runtime check before calling memcpy() or whatever, IMHO it's worth it because the cost of a single pointer comparison is negligible in almost all cases and for tiny static arrays (where it might not be negligible) the compiler could just generate regular assignment instructions that are safe for the overlapping/identical case instead of using something like memcpy().

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4791


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2010-09-03 04:39:48 PDT ---
The only correct syntax to write that code is this, see bug 3971

void main() {
    int[2] foo;
    foo[] = foo[];
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4791



--- Comment #2 from David Simcha <dsimcha@yahoo.com> 2010-09-03 05:25:43 PDT ---
Yes, and this is a nightmare for generic code.

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