[Bug c++/65354] New: Converting lambda to pointer results in double destruction
charlie at charliedyson dot net
gcc-bugzilla@gcc.gnu.org
Sun Mar 8 19:42:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65354
Bug ID: 65354
Summary: Converting lambda to pointer results in double
destruction
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: charlie at charliedyson dot net
In the following, the unique_ptr is deleted twice if the lambda is converted to
a function pointer (#if 1) but runs without error if left as a lambda.
Compiled with g++-4.8 test.cpp -o test -std=c++1y on Linux Mint 17 x64.
I get the following output in the function pointer case:
Bye
Bye
*** Error in `./test': double free or corruption (fasttop): 0x0000000001e5c010
***
Aborted
Here's the code:
#include <memory>
#include <iostream>
struct X
{
~X () { std::cout << "Bye" << std::endl; }
};
struct Y
{
explicit Y (std::unique_ptr<X> x)
: m_x (std::move (x))
{ }
std::unique_ptr<X> m_x;
};
int main ()
{
using F = Y (*) (std::unique_ptr<X>);
auto p = std::unique_ptr<X> {new X};
#if 1
F f =
#else
auto f =
#endif
[] (std::unique_ptr<X> x)
{
return Y (std::move (x));
};
f (std::move (p));
}
More information about the Gcc-bugs
mailing list