Re: Unexpected copy constructor behavior

2020-07-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/20 3:31 AM, psycha0s wrote: On Thursday, 9 July 2020 at 22:18:59 UTC, Steven Schveighoffer wrote: Looking at the generated AST, it's because the compiler is adding an auto-generated opAssign, which accepts a Foo by value. It is that object that is being created and destroyed. Is

Re: Unexpected copy constructor behavior

2020-07-10 Thread psycha0s via Digitalmars-d-learn
On Thursday, 9 July 2020 at 22:18:59 UTC, Steven Schveighoffer wrote: Looking at the generated AST, it's because the compiler is adding an auto-generated opAssign, which accepts a Foo by value. It is that object that is being created and destroyed. Is there a reason the autogenerated opAssign

Re: Unexpected copy constructor behavior

2020-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/20 6:08 PM, psycha0s wrote: import std.stdio; struct Foo { int value; this(int n) {     value = n;     writeln("constuctor ", ); } ~this() {     writeln("destuctor ", ); } this(ref return scope Foo other) {     value =

Re: Unexpected copy constructor behavior

2020-07-09 Thread psycha0s via Digitalmars-d-learn
I just didn't expect that the address of a "this" reference may change.

Unexpected copy constructor behavior

2020-07-09 Thread psycha0s via Digitalmars-d-learn
I was learning copy constructors and got a really weird result. It looks like a copy constructor and a destuctor of two unknown objects are called. Could somebody please explain it to me? import std.stdio; struct Foo { int value; this(int n) { value =