From f1c446ccdc0c611d1aeec4a6266a77693ae48c92 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 2 Oct 2020 10:53:21 +0100 Subject: [PATCH] Fix instances of bugprone-move-forwarding-reference 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 --- include/marl/finally.h | 8 ++++---- include/marl/ticket.h | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/marl/finally.h b/include/marl/finally.h index 7bdd510..b8b00a5 100644 --- a/include/marl/finally.h +++ b/include/marl/finally.h @@ -77,13 +77,13 @@ FinallyImpl::~FinallyImpl() { } template -MARL_NO_EXPORT inline FinallyImpl make_finally(F&& f) { - return FinallyImpl(std::move(f)); +inline FinallyImpl make_finally(F&& f) { + return FinallyImpl(std::forward(f)); } template -MARL_NO_EXPORT inline std::shared_ptr make_shared_finally(F&& f) { - return std::make_shared>(std::move(f)); +inline std::shared_ptr make_shared_finally(F&& f) { + return std::make_shared>(std::forward(f)); } } // namespace marl diff --git a/include/marl/ticket.h b/include/marl/ticket.h index afc7e8e..e99cdcb 100644 --- a/include/marl/ticket.h +++ b/include/marl/ticket.h @@ -148,7 +148,7 @@ template void Ticket::onCall(Function&& f) const { marl::lock lock(record->shared->mutex); if (record->isCalled) { - marl::schedule(std::move(f)); + marl::schedule(std::forward(f)); return; } if (record->onCall) { @@ -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(f)}); } else { - record->onCall = std::move(f); + record->onCall = std::forward(f); } }