New issue
Advanced search Search tips

Issue 759362 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Sep 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Forgetting std::move when using a move-only type with BindOnce breaks

Project Member Reported by dcheng@chromium.org, Aug 27 2017

Issue description

Simple test case:
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index 99aaa76ed302..f5c48f898cbf 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -1410,5 +1410,13 @@ TEST(BindDeathTest, NullCallback) {
   EXPECT_DCHECK_DEATH(base::Bind(null_cb, 42));
 }
 
+void TakesMoveOnly(std::unique_ptr<int> x) {}
+
+TEST(BindFailTest, BindIncompatible) {
+  auto x = std::make_unique<int>(8);
+  // auto cb = base::Bind(&TakesMoveOnly, std::move(x));
+  auto cb2 = base::BindOnce(&TakesMoveOnly, x);
+}
+
 }  // namespace
 }  // namespace base


This doesn't hit the static assert, but it causes a failure later:
../../base/bind_internal.h:451:9: error: no matching constructor for initialization of 'std::tuple<u
nique_ptr<int, default_delete<int> > >'                                                             
        bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {                                
        ^           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                     
../../base/bind_internal.h:421:9: note: in instantiation of function template specialization 'base::
internal::BindState<void (*)(std::__1::unique_ptr<int, std::__1::default_delete<int> >), std::__1::u
nique_ptr<int, std::__1::default_delete<int> > >::BindState<void (*)(std::__1::unique_ptr<int, std::
__1::default_delete<int> >), std::__1::unique_ptr<int, std::__1::default_delete<int> > &>' requested
 here                                                                                               
      : BindState(IsCancellable{},                                                                  
        ^ 
 
Project Member

Comment 1 by bugdroid1@chromium.org, Aug 30 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a09cb607e97ab6e4041919ce7b7d5a5dcbb7e033

commit a09cb607e97ab6e4041919ce7b7d5a5dcbb7e033
Author: Daniel Cheng <dcheng@chromium.org>
Date: Wed Aug 30 13:46:19 2017

Provide clearer errors for common mistakes with Bind and move-only types

Bug:  759254 ,  759362 
Change-Id: I5de6c40c6ab3fbc816ccef031aa5e0fbc78593cc
Reviewed-on: https://chromium-review.googlesource.com/636886
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#498444}
[modify] https://crrev.com/a09cb607e97ab6e4041919ce7b7d5a5dcbb7e033/base/bind.h
[modify] https://crrev.com/a09cb607e97ab6e4041919ce7b7d5a5dcbb7e033/base/bind_unittest.nc

Status: Fixed (was: Started)

Sign in to add a comment