[Bug c++/94008] New: "use of deleted function" error when using "std::unique_ptr", std::move() and lambda
xxhdx1985126 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Mar 3 02:55:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94008
Bug ID: 94008
Summary: "use of deleted function" error when using
"std::unique_ptr", std::move() and lambda
Product: gcc
Version: 8.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xxhdx1985126 at gmail dot com
Target Milestone: ---
the following code will trigger a "use of deleted function" error when
compiling:
------------------------------------------
#include <memory>
template<typename Func>
void test_lambda(Func f)
{
}
int main()
{
std::unique_ptr<int> test_uniq = std::make_unique<int>(0);
test_lambda([test_uniq = test_uniq.get()] () mutable {
test_lambda([test_uniq] {
});
});
test_lambda([test_uniq = std::move(test_uniq)] {
test_lambda([test_uniq = std::move(test_uniq)] {});
});
}
------------------------------------------
the error:
test_unique_ptr_lambda.cpp: In lambda function:
test_unique_ptr_lambda.cpp:16:19: error: use of deleted function
‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with
_Tp = int; _Dp = std::default_delete<int>]’
test_lambda([test_uniq = std::move(test_uniq)] {});
^
In file included from /opt/rh/devtoolset-8/root/usr/include/c++/8/memory:80,
from test_unique_ptr_lambda.cpp:1:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/unique_ptr.h:394:7: note:
declared here
unique_ptr(const unique_ptr&) = delete;
^~~~~~~~~~
system: CentOS 8
compile command: g++ -std=c++17 test_unique_ptr_lambda.cpp
More information about the Gcc-bugs
mailing list