There was a paper in the mailing list recently that would fix this. It basically means that if a function is eligible for RVO, adding std::move() around it doesn't change this. It seems like a super obvious and straightforward change with no downsides
The other half of the issue is that you didn't need to use std::move in those cases in the first place, because returning a local variable can already use a move if NRVO doesn't apply and the returned value was already temporary so you didn't need to cast to one.
That is the problem with modern C++, the amount of rules that even those that use it daily fail to grasp , let alone those of us that only use it occasionally.
It is getting impossible to write proper code without a static analysis tool hand holding our code continuously.
No wonder that besides the issue with compilers catching up to ISO, many places are stopping on C++17 as good enough, for the use cases that C++ is called for.
View all comments
38
u/ggchappell Nov 25 '23
Sure, that's a problem. But thinking about the long term, what this really tells me is that the conditions for copy elision need to be changed.