this post was submitted on 25 Nov 2023
29 points (96.8% liked)

C++

1773 readers
9 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] QuadriLiteral@programming.dev 2 points 11 months ago (2 children)

I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

[–] DanielaKEngert@hachyderm.io 3 points 11 months ago (1 children)

@QuadriLiteral @lysdexic We've been looking at a paper just recently in Kona, where the author proposed to not penalize "unfortunate" uses of std::move. I think this is user friendly and you might imagine what I've been voting for.

[–] QuadriLiteral@programming.dev 1 points 11 months ago

That sounds great!

[–] lysdexic@programming.dev 1 points 11 months ago (2 children)

I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

These std::move invocations are harmless, as they only cast objects to their rvalue reference.

The destructive bit takes place in the type they are assigned to, as it invokes either a move constructor or a move assignment operator, and calling those implies that the object you just passed to std::move will be invalidated after the call and should not be used subsequently.

[–] QuadriLiteral@programming.dev 1 points 11 months ago

I mean harmless in a way that using std::move on the return type doesn't prevent RVO?

[–] DanielaKEngert@hachyderm.io 1 points 11 months ago (1 children)

@lysdexic @QuadriLiteral Eh, no. Really. Changing the value category disables RVO

[–] lysdexic@programming.dev 1 points 11 months ago (1 children)

RVO

I recommend you read the thread.

[–] DanielaKEngert@hachyderm.io 1 points 11 months ago (1 children)
[–] lysdexic@programming.dev 1 points 11 months ago (1 children)

It doesn't look like it, otherwise you'd be aware that the whole point of this submission is that casting return values with std::move disables RVO.

[–] DanielaKEngert@hachyderm.io 1 points 11 months ago (1 children)

@lysdexic You claimed otherwise:
"
These std::move invocations are harmless, as they only cast objects to their rvalue reference.
"
If you were right, we wouldn't have the motivation to look at this in EWG.

[–] lysdexic@programming.dev 1 points 11 months ago

If you were right, we wouldn’t have the motivation to look at this in EWG.

I am right. Not benefiting from RVO does not mean you're harming anyone.

Again, I recommend you read the submission and also the discussion.