News for hackers. Stuff that matters.
Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by mehrdadn on Thursday April 11, 2019 @07:22PM (#19640317)
No, lack of good code analysis is not the problem. If the compiler was to only do a move in cases where it could prove variable independence then it would be operating under the as-if rule -- which it is already allowed to do -- and hence your code wouldn't behave any differently than if it hadn't done that. Automatic moves OTOH change the semantics of the code, which is kind of the point -- the compiler can't do an automatic move without permission unless the language specification says so, and unlike with the case of copy elision, it doesn't permit the compiler to change the semantics like this, as RAII has multiple use cases as I mentioned above that would break if this was permitted.
Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by Rusky on Thursday April 11, 2019 @07:57PM (#19640529)
Yes, we're discussing an alternative design here. An automatic move should change the semantics of the program, rendering later uses invalid.

This does not break RAII- it merely changes the defaults. It should be copies that are marked in the program source, not moves- this is unfortunately not backwards compatible, but it's also not a problem for how RAII gets used.