Skip to content

Commit

Permalink
Fix instances of bugprone-move-forwarding-reference
Browse files Browse the repository at this point in the history
Unless it's guaranteed that `std::forward` always turns into an rvalue ref, using `std::move(x)`, where `x`'s type is a universal reference, is generally unsafe.
`std::forward` is preferred for these cases.

This is upstreaming a fix made by George Burgess from https://swiftshader-review.googlesource.com/c/SwiftShader/+/48868.

Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1134310
  • Loading branch information
ben-clayton committed Oct 2, 2020
1 parent 8719a54 commit f1c446c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions include/marl/finally.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ FinallyImpl<F>::~FinallyImpl() {
}

template <typename F>
MARL_NO_EXPORT inline FinallyImpl<F> make_finally(F&& f) {
return FinallyImpl<F>(std::move(f));
inline FinallyImpl<F> make_finally(F&& f) {
return FinallyImpl<F>(std::forward<F>(f));
}

template <typename F>
MARL_NO_EXPORT inline std::shared_ptr<Finally> make_shared_finally(F&& f) {
return std::make_shared<FinallyImpl<F>>(std::move(f));
inline std::shared_ptr<Finally> make_shared_finally(F&& f) {
return std::make_shared<FinallyImpl<F>>(std::forward<F>(f));
}

} // namespace marl
Expand Down
7 changes: 4 additions & 3 deletions include/marl/ticket.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ template <typename Function>
void Ticket::onCall(Function&& f) const {
marl::lock lock(record->shared->mutex);
if (record->isCalled) {
marl::schedule(std::move(f));
marl::schedule(std::forward<Function>(f));
return;
}
if (record->onCall) {
Expand All @@ -159,9 +159,10 @@ void Ticket::onCall(Function&& f) const {
}
OnCall a, b;
};
record->onCall = std::move(Joined{std::move(record->onCall), std::move(f)});
record->onCall =
std::move(Joined{std::move(record->onCall), std::forward<Function>(f)});
} else {
record->onCall = std::move(f);
record->onCall = std::forward<Function>(f);
}
}

Expand Down

0 comments on commit f1c446c

Please sign in to comment.