Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S5500: mention std::ranges::move and rewrite RSPEC (CPP-5219) #3933

Merged
merged 15 commits into from
May 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update rules/S5500/cfamily/rule.adoc
Co-authored-by: Loïc Joly <loic.joly@sonarsource.com>
  • Loading branch information
commit 661508cc4cf0b70646b0ae69892a8e72479f2448
6 changes: 3 additions & 3 deletions rules/S5500/cfamily/rule.adoc
Original file line number Diff line number Diff line change
@@ -145,11 +145,11 @@ void DrawingStore::insertAllVisibleShapes(std::vector<Shape>&& shapes) {

// We purposely do not go into the details of "moved-from" states and the fact that `shapes` has still the same number of elements while some of them are in this "moved-from" state.

Notice that in this solution, the for-loop variable `s` remains an lvalue reference with a single `&`.
Furthermore, writing ``++for (Shape& s : std::move(shapes))++`` would not fix the issue because this call to `std::move` has no effect here.
Writing ``++for (Shape& s : std::move(shapes))++`` would not fix the issue because this call to `std::move` has no effect here.
The call to `std::move` has to be on `s`, not `shapes`.

Thankfully, {cpp}23 offers a new feature that makes the code more regular: with ``++std::ranges::views::as_rvalue++``, it is now possible to make `s` an rvalue too, making the intent of the code clearer.
Notice that in this solution, the for-loop variable `s` remains an lvalue reference with a single `&`.
In {cpp}23, it is possible to make it a rvalue too, with ``++std::ranges::views::as_rvalue++``, making the intent of the code clearer.

// We do not use the shorter form std::views::as_rvalue because libstdc++ does not support it yet.