Binding rvalues to ref parameters redux

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 27 14:52:31 UTC 2019


On 3/27/19 9:59 AM, Nicholas Wilson wrote:
> On Wednesday, 27 March 2019 at 11:13:02 UTC, Andrei Alexandrescu wrote:
>> One important realization working on this was that insertion of 
>> constructors and destructors cannot be realized via lambda lowering 
>> because lifetimes don't follow some natural scoping. For example, the 
>> temporaries created on the left-hand side of && survive through the 
>> end of the full expression, whereas those created on the right-hand 
>> side do not. The "?:" operator is a hot mess including additional 
>> hidden state variables, conditional destruction thus breaking the 
>> language rules etc. I'll make sure the document mentions why lowering 
>> is not the appropriate mechanism to describe insertion of constructors 
>> and destructors.
> 
> Well the way it is currently worded is _very_ confusing, it could do 
> with examples of whatever transformation is applied.

Thanks, yah, a few more examples will definitely help.

>> One other thing is that these temporary construction and destruction 
>> rules preexisted. In fact probably the nicest thing about the DIP is 
>> that no new rules are introduced - temporaries are created and 
>> destroyed exactly as if there was no "ref" for the parameter.
> 
> It should state that.

The current wording is kinda buried in a paragraph: "In expressions 
containing rvalues bound to ref parameters, the order of evaluation of 
expressions and the lifetime of temporaries thus generated remain the 
same as if the ref parameters would be value parameters of the same 
type." I'll work on expanding on it and make it more prominent. Thanks!


More information about the Digitalmars-d mailing list