[Issue 1974] overloaded assignment operators work on non-lvalues

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 08:36:28 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=1974

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
This is a bit problematic because there are 2 points of view on this:

1. From a high-level point of view, the bug report is valid, you are trying to
assign to an rvalue (x.test() = x.test() + 1337) which should an error.

2. From a lowering point of view you are basically calling the member function
of a temporary object (x.test.opAddAssign(1337)), which by the current rules is
valid behavior.

I guess that what could be implemented is something along the lines of: if the
opAssign/op*Assign function is pure, then you can error/warn because the call
has no effect, otherwise it is possible that the assign function has side
effects so calling it is correct. Anyhow, maybe I am over-engineering this?

--


More information about the Digitalmars-d-bugs mailing list