This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
My recent refactoring of enable_shared_from_this broke support for an obscure use case, where shared_ptr "owns" a pointer to function (and the deleter does something with it, like unregister a callback from a plugin). The problem is simply that I made the new _M_enable_shared_from_this_with overloads take a const _Yp* parameter, so that _Yp would be deduced as the non-const type. That was just laziness, to save using remove_const on the type. But that breaks function pointers, because const _Yp* won't deduce a type like void(*)(), and so there is no viable overload of _M_enable_shared_from_this_with. The fix is just to use a parameter of _Yp* and then use remove_cv<_Yp> to get the unqualified type. I'm also adjusting a test which uses const_pointer_cast<X> to cast a shared_ptr<const X> to shared_ptr<X>, but the object it owns was born const so casting it away and accessing it as non-const is undefined. PR libstdc++/80229 * include/bits/shared_ptr_base.h (__shared_ptr::_M_enable_shared_from_this_with): Change parameters to non-const and then use remove_cv to get unqualified type. * testsuite/20_util/enable_shared_from_this/members/const.cc: Don't cast away constness on object created const. * testsuite/20_util/shared_ptr/cons/80229.cc: New test. Tested powerpc64le-linux, committed to trunk.
Attachment:
patch.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |