Issue 1974 - What's your opinion?

jmh530 john.michael.hall at
Thu Oct 24 10:30:28 UTC 2019

On Thursday, 24 October 2019 at 08:02:28 UTC, RazvanN wrote:
> [snip]

D1 operators are deprecated, so at the very least the example 
should be updated to reflect that ( did not give me 
a message about them being deprecated when I ran it 
though...maybe older version of DMD?). Also, I was getting an 
error with writefln because there is no format string, so I 
replaced that with writeln.

With those changes (below), the writeln prints 0, rather than 
1337. So if it is adding to the temporary, then it seems to then 
throw it away. Is that what was expected to happen?

import std.stdio;
struct Foo
     int y;
     void opOpAssign(string op)(int z)
         if (op == "+")
         y += z;
struct Bar {
     Foo fou;
     Foo test()
         return fou;
void main() {
     Bar x;
     x.fou.y = 0;
     x.test() += 1337;
     writeln(x.fou.y); //prints 0

More information about the Digitalmars-d mailing list