| Index: base/bind_internal.h
|
| diff --git a/base/bind_internal.h b/base/bind_internal.h
|
| index 17f78a3d67b37f07a87df2385c1dd5ca08fff6bf..d16109e4243d174528c26b372aa07b6eacd792e8 100644
|
| --- a/base/bind_internal.h
|
| +++ b/base/bind_internal.h
|
| @@ -422,6 +422,23 @@ struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
|
| }
|
| };
|
|
|
| +// Template helpers to detect using Bind() on a base::Callback without any
|
| +// additional arguments. In that case, the original base::Callback object should
|
| +// just be directly used.
|
| +template <typename Functor, typename... BoundArgs>
|
| +struct BindingCallbackWithNoArgs {
|
| + static constexpr bool value = false;
|
| +};
|
| +
|
| +template <typename Signature,
|
| + typename... BoundArgs,
|
| + CopyMode copy_mode,
|
| + RepeatMode repeat_mode>
|
| +struct BindingCallbackWithNoArgs<Callback<Signature, copy_mode, repeat_mode>,
|
| + BoundArgs...> {
|
| + static constexpr bool value = sizeof...(BoundArgs) == 0;
|
| +};
|
| +
|
| // BindState<>
|
| //
|
| // This stores all the state passed into Bind().
|
| @@ -439,7 +456,12 @@ struct BindState final : BindStateBase {
|
| : BindState(IsCancellable{},
|
| invoke_func,
|
| std::forward<ForwardFunctor>(functor),
|
| - std::forward<ForwardBoundArgs>(bound_args)...) {}
|
| + std::forward<ForwardBoundArgs>(bound_args)...) {
|
| + static_assert(!BindingCallbackWithNoArgs<Functor, BoundArgs...>::value,
|
| + "Attempting to bind a base::Callback with no additional "
|
| + "arguments: save a heap allocation and use the original "
|
| + "base::Callback object");
|
| + }
|
|
|
| Functor functor_;
|
| std::tuple<BoundArgs...> bound_args_;
|
|
|