On Thursday, 24 January 2019 at 07:18:58 UTC, Mike Parker wrote:
Walter and Andrei have declined to accept DIP 1016, "ref T accepts r-values", on the grounds that it has two fundamental flaws that would open holes in the language. They are not opposed to the feature in principle and suggested that a proposal that closes those holes and covers all the bases will have a higher chance of getting accepted.

You can read a summary of the Formal Assessment at the bottom of the document:

https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1016.md

The second problem is the use of := (which the DIP Author defines as representing "the initial construction, and not a copy operation as would be expected if this code were written with an = expression"). This approach shows its deficiencies in the multiple arguments case; if the first constructor throws an exception, all remaining values will be destroyed in the void state as they never have the chance to become initialized.

Although not specified by the DIP, I think this could be easily remedied by saying that the order of construction is the same as if the temporaries were not bound to ref, i.e.

---
struct A {~this();} struct B{ ~this();}
A a();
B b();

void f(A a, B b);
void g(ref A a, ref B b);

f(a(),b());  //(1)
g(a(),b()); //(2)
---

and a() or b() may throw (and are pure), that (1) and (2) exhibit the same exception/destructor semantics.

Which is what I would expect to happen under no given specification (although specifying it is a good idea!). To put it another way, they should be constructed in place in the order they are used, and given they are a temporary, they can only be used once.

Reply via email to