Thread overview
struct is not copyable because it is annotated with @disable bugs ?
Jul 27, 2019
Newbie2019
Jul 27, 2019
Adam D. Ruppe
Jul 27, 2019
Newbie2019
July 27, 2019
I think this is a bug.

If I return a struct more than one times,  will throw this error.
If I return once,  every thing is ok.

https://run.dlang.io/is/T4kWKM


	ref auto getList() return scope {
		if( i ) return NodeList(null); // remove this line will fix this error
		A* a;
		B* b;
		auto list = NodeList(a, b);
		return list;
	}
July 27, 2019
On Saturday, 27 July 2019 at 16:59:44 UTC, Newbie2019 wrote:
> 		auto list = NodeList(a, b);

If you change that to just plain `return NodeList(a, b);`, while keeping the first line, it will compile too.

The reason here is when you return and construct together, it constructs it in-place. But if you put it in a local variable first, it needs to copy it to the return value.

Removing the first line just lets the compiler optimize out the local variable, reducing it to the in-place one again.

But explicitly returning and constructing together works in either case.
July 27, 2019
On Saturday, 27 July 2019 at 17:13:45 UTC, Adam D. Ruppe wrote:
> If you change that to just plain `return NodeList(a, b);`, while keeping the first line, it will compile too.
>
> The reason here is when you return and construct together, it constructs it in-place. But if you put it in a local variable first, it needs to copy it to the return value.
>
> Removing the first line just lets the compiler optimize out the local variable, reducing it to the in-place one again.
>
> But explicitly returning and constructing together works in either case.

Thanks your for the very quick and good explain.

I thinks the DMD should report a more helpful error about this.