You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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(&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.
The text was updated successfully, but these errors were encountered:
Extended Description
The following snippet triggers a compilation error:
The error happens when
std::shared_ptr<Foo ()>
attempts to instantiatestd::allocator<Foo ()>
in a constructor that does not need that allocator: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.The text was updated successfully, but these errors were encountered: