Thread overview
[Issue 3550] New: array.dup violates const/invariant without a cast.
Aug 03, 2010
Sobirari Muhomori
Jul 09, 2011
yebblies
Oct 03, 2011
Walter Bright
November 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3550

           Summary: array.dup violates const/invariant without a cast.
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2009-11-24 19:47:31 PST ---
simple test case:

import std.stdio;

class C { int x; }

void foo(const(C)[] arg)
{
  auto arg2 = arg.dup;
  foreach(c; arg2) c.x = 5;
}

void main()
{
  C[] arr;
  arr ~= new C;
  foo(arr);
  writefln("%d", arr[0].x);
}

This compiles and outputs 5.

I believe dup should statically fail if the element type has any references in it and the type is const or invariant.

Likewise, I think idup should fail if the element type has any references in it.  These properties are not supposed to be "you're on your own" territory IMO.

This is related to bug 1339

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 25, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3550



--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2009-11-24 20:02:10 PST ---
I should clarify:

I think idup should fail if the element has any *non-immutable* references in it.

Note this leaves us with no ways to dup a const array with references in it! Should we have cdup?  A workaround to both would be to always allow dup when an explicit cast is involved.

i.e.:

auto arg2 = cast(const(C)[])arg.dup;

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


Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |2573


--- Comment #2 from Sobirari Muhomori <dfj1esp02@sneakemail.com> 2010-08-03 13:25:17 PDT ---
Just thought, there must be this bug...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3550


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies@gmail.com


--- Comment #3 from yebblies <yebblies@gmail.com> 2011-07-09 13:47:59 EST ---
https://github.com/D-Programming-Language/dmd/pull/219

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


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2011-10-02 22:33:46 PDT ---
https://github.com/D-Programming-Language/dmd/commit/f6fe4cc94d3210e260905ddf4c56a332c3d4f961

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