<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 - Cannot create shared_ptr of types with noexcept(false) destructor"
   href="https://bugs.llvm.org/show_bug.cgi?id=32978">32978</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cannot create shared_ptr of types with noexcept(false) destructor
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>marvin_schmidt@gmx.net
          </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=18422" name="attach_18422" title="patch to fix `make_shared<T>()` for types with noexcept(false) dtors">attachment 18422</a> <a href="attachment.cgi?id=18422&action=edit" title="patch to fix `make_shared<T>()` for types with noexcept(false) dtors">[details]</a></span>
patch to fix `make_shared<T>()` for types with noexcept(false) dtors

Hey folks,

I'm not sure if this is a bug in libc++ or not. But it's something, where
libstdc++ and libc++ behave differently. With libc++ calling
std::make_shared<T>() where T has a destructor marked `noexcept(false)` fails
to compile.

Test case:

#include <memory>

struct Foo
{
        Foo() = default;
        ~Foo() noexcept(false) { throw 42; }
};

int main()
{
        auto ptr = std::make_shared<Foo>();
        return 0;
}


fails to compile with the following error:

# clang++ -std=c++11 -stdlib=libc++ -Wall -pedantic -O0 -o test test.cc
In file included from test.cc:1:
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:3589:7: error: exception
specification of overriding function is more lax than base version
class __shared_ptr_emplace
      ^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:4228:26: note: in
instantiation of template class 'std::__1::__shared_ptr_emplace<Foo,
std::__1::allocator<Foo> >' requested here
    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
                         ^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:4598:29: note: in
instantiation of function template specialization
'std::__1::shared_ptr<Foo>::make_shared<>' requested here
    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
                            ^
test.cc:11:25: note: in instantiation of function template specialization
'std::__1::make_shared<Foo>' requested here
        auto ptr = std::make_shared<Foo>();
                        ^
/usr/x86_64-pc-linux-gnu/bin/../include/c++/v1/memory:3498:13: note: overridden
virtual function is here
    virtual ~__shared_weak_count();
            ^
1 error generated.


The attached patch fixes that by marking the destructors of
__shared_ptr_emplace, __shared_{,weak_}count with _NOEXCEPT, but I'm not sure,
if this is the way to go. It also is not a complete fix, since the
std::locale::facet for example is also derived from __shared_count and would
need to be adjusted accordingly as well.
I appreciate any insights on this</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>