public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65354] New: Converting lambda to pointer results in double destruction
@ 2015-03-08 19:42 charlie at charliedyson dot net
  2015-03-08 22:30 ` [Bug c++/65354] " daniel.kruegler at googlemail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: charlie at charliedyson dot net @ 2015-03-08 19:42 UTC (permalink / raw)
  To: gcc-bugs

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));
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-09 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-08 19:42 [Bug c++/65354] New: Converting lambda to pointer results in double destruction charlie at charliedyson dot net
2015-03-08 22:30 ` [Bug c++/65354] " daniel.kruegler at googlemail dot com
2015-03-09  8:05 ` charlie at charliedyson dot net
2015-03-09 10:13 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).