DIP 1016--ref T accepts r-values--Formal Assessment

Steven Schveighoffer schveiguy at gmail.com
Thu Jan 31 22:01:03 UTC 2019

On 1/31/19 4:46 PM, Andrei Alexandrescu wrote:
> 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 proposal could actually disallow rvalues that have lvalue syntax, 
> such as "symbol", "symbol[expr]", "symbol.symbol", 
> "symbol.symbol[expr]", etc. Ugh. Gets hairy quickly.

No, because those calls might actually do something with side effects! 
rvalues can contain other references.

The only way to fix this would be to overload member functions on the 
lvalue-ness of `this`. I don't recommend this at all, as I see this as a 
weird but rare problem that doesn't affect most D code.


More information about the Digitalmars-d-announce mailing list