<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - std::function copies movable objects when is SOO is used"
   href="https://bugs.llvm.org/show_bug.cgi?id=33125">33125</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::function copies movable objects when is SOO is used
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kibergus@yandex-team.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18487" name="attach_18487" title="Test case">attachment 18487</a> <a href="attachment.cgi?id=18487&action=edit" title="Test case">[details]</a></span>
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>