[Bug c++/94008] "use of deleted function" error when using "std::unique_ptr", std::move() and lambda

2020-03-03 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94008

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Jonathan Wakely  ---
(In reply to Xuehan Xu from comment #0)
>   test_lambda([test_uniq = std::move(test_uniq)] {
>   test_lambda([test_uniq = std::move(test_uniq)] {});

The operator() of the closure object is a const member function, so test_uniq
is const and can't be moved. Attempting to move it will copy it, which fails
because unique_ptr is not copyable.

[Bug c++/94008] "use of deleted function" error when using "std::unique_ptr", std::move() and lambda

2020-03-03 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94008

--- Comment #2 from Jonathan Wakely  ---
(In reply to Nicholas Krause from comment #1)
> Your passing into std::move and then again. That's incorrect as your moving
> and moving again into the test_lamba.

No, that's not what the code does.

[Bug c++/94008] "use of deleted function" error when using "std::unique_ptr", std::move() and lambda

2020-03-02 Thread xerofoify at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94008

Nicholas Krause  changed:

   What|Removed |Added

 CC||xerofoify at gmail dot com

--- Comment #1 from Nicholas Krause  ---
I tried compiling this on both clang trunk and gcc trunk on godbolt. Your
problem seems to be this:
test_lambda([test_uniq = std::move(test_uniq)] {
  test_lambda([test_uniq = std::move(test_uniq)] {});
})

Your passing into std::move and then again. That's incorrect as your moving and
moving again into the test_lamba. I tried with:

test_lambda([test_uniq = test_uniq.get()]() mutable {
  test_lambda([test_uniq = std::move(test_uniq)] {});
});

And this does not miscompile due to test uniq getting the actual reference
rather than the r value and going back into another r value reference. This
therefore is not a bug.