DIP 1016--ref T accepts r-values--Formal Assessment
Steven Schveighoffer
schveiguy at gmail.com
Thu Jan 31 21:57:21 UTC 2019
On 1/31/19 4:42 PM, Olivier FAURE wrote:
> On Thursday, 31 January 2019 at 16:38:42 UTC, Steven Schveighoffer wrote:
>> Yeah, that's already a thing that ref in D doesn't protect against:
>
> It took me a while to understand what the compiler was doing.
>
> This really feels like something that shouldn't compile.
The problem is that `this` is passed by reference EVEN for rvalues.
Knowing this, you can construct difficult situations, but normally these
don't appear in the wild.
If you've ever tried to make a simple math wrapper type, you would see
how this is weird. And it has been like this since the beginning of D2.
You get things like:
a + Foo(1); // error
Foo(1) + a; // OK!
That being said, you can look at the fact that most people don't even
know about this problem, even seasoned veterans, as a sign that it's
really not a big problem.
-Steve
More information about the Digitalmars-d-announce
mailing list