[Issue 3550] New: array.dup violates const/invariant without a cast.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 24 19:47:31 PST 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 at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at 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: -------


More information about the Digitalmars-d-bugs mailing list