[llvm-bugs] [Bug 33125] New: std::function copies movable objects when is SOO is used

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 22 08:56:43 PDT 2017


            Bug ID: 33125
           Summary: std::function copies movable objects when is SOO is
           Product: libc++
           Version: 3.7
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kibergus at yandex-team.ru
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 18487
  --> https://bugs.llvm.org/attachment.cgi?id=18487&action=edit
Test case

Hi. Libc++ that comes with Xcode 8.2.1 has small object optimization
implemented for std::function. But move constructor of std::function always
uses copy constructor of the object. This results in unnecessary copies being
made and additional destructor calls.

In our use case this even leads to crashes because the object is a handle and
we rely that it will be destroyed on specific thread. But that extra copies,
created while the std::function is dispatched to the worker thread, result in
destructor being deleted at another time and from another thread.

It would be good if moving std::function object resulted in moving the
underlying functor if it is movable.

I've attached a test program, that demonstrates the problem.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170522/88878841/attachment.html>

More information about the llvm-bugs mailing list