[Issue 1974] New: overloaded assignment operators work on non-lvalues
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 5 10:55:33 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1974
Summary: overloaded assignment operators work on non-lvalues
Product: D
Version: unspecified
Platform: Other
OS/Version: Other
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: default_357-line at yahoo.de
Code:
module test; import std.stdio;
struct Foo { int y; void opAddAssign(int z) { y += z; } }
struct Bar { Foo fou; Foo test() { return fou; } }
void main() {
Bar x;
x.fou.y = 0;
x.test() += 1337;
writefln(x.fou.y);
}
The problem is that opAddAssign can be called even though the Foo it's being
called on is not an lvalue at all.
I see two solutions: either make this an error, or try to invoke opIndexAssign
to write the value back after the expression has been evaluated. The first is
probably easier.
--
More information about the Digitalmars-d-bugs
mailing list