Skip to content

Commit

Permalink
pw_function: Take forwarding reference instead of value
Browse files Browse the repository at this point in the history
Disable unhelpful GCC warnings for GCC only.

Change-Id: I095aeaa400060a954d23b6b996d6a3d34df1a54c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/95340
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
  • Loading branch information
255 authored and CQ Bot Account committed Jun 6, 2022
1 parent 3e85577 commit 29f0526
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pw_function/public/pw_function/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class Function<Return(Args...)> {
Function& operator=(const Function&) = delete;

template <typename Callable>
Function(Callable callable) {
Function(Callable&& callable) {
if (function_internal::IsNull(callable)) {
holder_.InitializeNullTarget();
} else {
holder_.InitializeInlineTarget(std::move(callable));
holder_.InitializeInlineTarget(std::forward<Callable>(callable));
}
}

Expand All @@ -89,12 +89,12 @@ class Function<Return(Args...)> {
}

template <typename Callable>
Function& operator=(Callable callable) {
Function& operator=(Callable&& callable) {
holder_.DestructTarget();
if (function_internal::IsNull(callable)) {
holder_.InitializeNullTarget();
} else {
holder_.InitializeInlineTarget(std::move(callable));
holder_.InitializeInlineTarget(std::forward<Callable>(callable));
}
return *this;
}
Expand Down
3 changes: 2 additions & 1 deletion pw_function/public/pw_function/internal/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ struct NullEq<T, decltype(std::declval<T>() == nullptr)> {
// nullptr. Silence this warning. (The compiler will optimize out the
// comparison.)
PW_MODIFY_DIAGNOSTICS_PUSH();
PW_MODIFY_DIAGNOSTIC(ignored, "-Waddress");
PW_MODIFY_DIAGNOSTIC_GCC(ignored, "-Waddress");
PW_MODIFY_DIAGNOSTIC_GCC(ignored, "-Wnonnull-compare");
static constexpr bool Test(const T& v) { return v == nullptr; }
PW_MODIFY_DIAGNOSTICS_POP();
};
Expand Down

0 comments on commit 29f0526

Please sign in to comment.