https://llvm.org/bugs/show_bug.cgi?id=27566
Bug ID: 27566 Summary: shared_ptr of function type Product: libc++ Version: unspecified Hardware: All OS: All Status: NEW Severity: normal Priority: P Component: All Bugs Assignee: unassignedclangb...@nondot.org Reporter: kaball...@hotmail.com CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com Classification: Unclassified 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: > 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); > ^ 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. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs