digitalmars.D.bugs - [Issue 5958] New: const/immutable ignored passing to opAssign()
- d-bugmail puremagic.com (39/39) May 08 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5958
- d-bugmail puremagic.com (13/13) May 10 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5958
http://d.puremagic.com/issues/show_bug.cgi?id=5958
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
AssignedTo: nobody puremagic.com
ReportedBy: marcianx gmail.com
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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 08 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5958
Stewart Gordon <smjg iname.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|NEW |RESOLVED
CC| |smjg iname.com
Resolution| |DUPLICATE
*** This issue has been marked as a duplicate of issue 5493 ***
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10 2011








d-bugmail puremagic.com