[llvm-bugs] [Bug 27566] New: shared_ptr of function type
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Apr 28 18:48:42 PDT 2016
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: unassignedclangbugs at nondot.org
Reporter: kaballo86 at hotmail.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160429/0327c95f/attachment-0001.html>
More information about the llvm-bugs
mailing list