Commit 99bbf7de authored by George Burgess IV's avatar George Burgess IV Committed by Commit Bot

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.

The fix to the not-copy_constructible definition is... I assume a nop,
but it doesn't seem harmful to change it anyway?

Bug: 1134310
Change-Id: I6a40c714c6f9e393a984665c1a82e198d7a8fbcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443403Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813222}
parent d3f41954
......@@ -54,9 +54,10 @@ template <size_t I,
typename Tuple,
std::enable_if_t<std::is_copy_constructible<Tuple>::value, int> = 0>
auto RunOnceCallbackImpl(Tuple&& tuple) {
return [tuple = std::move(tuple)](auto&&... args) -> decltype(auto) {
return RunImpl(std::move(internal::get<I>(args...)), tuple);
};
return
[tuple = std::forward<Tuple>(tuple)](auto&&... args) -> decltype(auto) {
return RunImpl(std::move(internal::get<I>(args...)), tuple);
};
}
// Invoked when the arguments to a OnceCallback are not copy constructible. In
......@@ -68,8 +69,8 @@ template <size_t I,
auto RunOnceCallbackImpl(Tuple&& tuple) {
// Mock actions need to be copyable, but `tuple` is not. Wrap it in in a
// `scoped_refptr` to allow it to be copied.
auto tuple_ptr =
base::MakeRefCounted<base::RefCountedData<Tuple>>(std::move(tuple));
auto tuple_ptr = base::MakeRefCounted<base::RefCountedData<Tuple>>(
std::forward<Tuple>(tuple));
return [tuple_ptr =
std::move(tuple_ptr)](auto&&... args) mutable -> decltype(auto) {
// Since running the action will move out of the arguments, `tuple_ptr` is
......@@ -85,9 +86,10 @@ auto RunOnceCallbackImpl(Tuple&& tuple) {
// multiple times. Move-only arguments are not supported.
template <size_t I, typename Tuple>
auto RunRepeatingCallbackImpl(Tuple&& tuple) {
return [tuple = std::move(tuple)](auto&&... args) -> decltype(auto) {
return RunImpl(internal::get<I>(args...), tuple);
};
return
[tuple = std::forward<Tuple>(tuple)](auto&&... args) -> decltype(auto) {
return RunImpl(internal::get<I>(args...), tuple);
};
}
} // namespace internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment