Summary: const/immutable ignored passing to opAssign()
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-05-08 11:23:17 PDT ---
I saw examples in the D Programming Language book (Page 256) where opAssign()
took a ref argument instead of a const ref. Just to test, I made example below
which incorrectly compiles and runs with both gdc and dmd for D2. The example
also works with immutable replaced by const.

import std.stdio;

struct Foo
   auto ref opAssign(ref Foo s)
       s.x = 4; // modifying mutable object !!!
       x = s.x;
       return this;

   private int x = 0;

void main(string[] args)
   immutable(Foo) foo = Foo();
   auto foo2 = Foo();
   writefln("(immutable!) foo.x = %s", foo.x); // prints 0
   foo2 = foo; // allowed immutable RHS ???
   writefln("(immutable?) foo.x = %s", foo.x); // prints 4

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to