<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - shared_ptr of function type"
   href="https://llvm.org/bugs/show_bug.cgi?id=27566">27566</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>shared_ptr of function type
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>kaballo86@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following snippet triggers a compilation error:

    #include <memory>

    struct Foo {};
    using FooFn = Foo ();
    using FooFnPtr = Foo (*)();
    using FooDel = void (*)(FooFnPtr);
    static_assert(std::is_same<FooFn*, FooFnPtr>::value, "");

    void del(FooFnPtr) {}
    Foo fun() { return {}; }

    int main() {
        std::shared_ptr<FooFn>(&fun, &del);
    }

The error happens when `std::shared_ptr<Foo ()>` attempts to instantiate
`std::allocator<Foo ()>` in a constructor that does not need that allocator:

<span class="quote">> In file included from prog.cc:1:
> /usr/local/libcxx-head/include/c++/v1/memory:1726:45: error: multiple overloads of 'address' instantiate to the same signature 'const_pointer (const_reference) const noexcept' (aka 'Foo (*(Foo (&)()) const noexcept)()')
>     _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
>                                             ^
> /usr/local/libcxx-head/include/c++/v1/memory:4185:44: note: in instantiation of template class 'std::__1::allocator<Foo ()>' requested here
>         __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
>                                            ^
> prog.cc:13:5: note: in instantiation of function template specialization 'std::__1::shared_ptr<Foo ()>::shared_ptr<Foo (), void (*)(Foo (*)())>' requested here
>     std::shared_ptr<FooFn>(&fun, &del);
>     ^</span >

The original use case leverages `std::shared_ptr` to bundle a dynamically
loaded function together with a deleter that unloads the dynamic library when
the function is no longer referenced. It is unclear whether this use case is
supported, but I did not spot anything in the standard that would forbid it.</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>