This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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] |
This patch does three things: 1. Refactor std::enable_shared_from_this support code. Instead of several overloads of __enable_shared_from_this_helper that contain the same code but operating on slightly different types I've split it into two parts. Upcasting to an accessible+unambiguous enable_shared_from_this base class is done by new functions found by ADL, __enable_shared_from_this_base. That is called by a new template function __shared_ptr::_M_enable_shared_from_this_with() which actually does the enabling by calling _M_weak_assign. Calls to _M_enable_shared_from_this_with(p) closely match the wording from my https://wg21.link/p0033r1 paper ("enables shared_from_this with p") and are constrained so they don't give an error if the __enable_shared_from_this_base() call is ambiguous. We already gracefully handled ambiguous std::enable_shared_from_this bases (PR56383) but failed noisily if a type had a combination of std::enable_shared_from_this, std::__enable_shared_from_this and std::experimental::enable_shared_from_this bases. Now we treat those combinations gracefully. 2. Change std::experimental::enable_shared_from_this bases to be initialized independently of std::enable_shared_from_this bases. It's now possible to have both, and for both to be enabled. See enable_shared_from_this.cc which tests this. The standard says we have to enable shared_from_this for types with an accessible and unambiguous std::enable_shared_from_this base class, and we should be able to do that even if the class also has an experimental::enable_shared_from_this base class. Now we can. Potentially we could do the same for std::__enable_shared_from_this, but I'm happy for those bases to be considered ambiguous with std::enable_shared_from_this. 3. Don't enable shared_from_this for arrays stored in experimental::shared_ptr. This matches the boost::shared_ptr semantics, and I intend to propose this as a fix for C++17 too. It doesn't make sense to treat the first element of an array specially and enable shared_from_this for the first element only. * include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&)): Call _M_enable_shared_from_this_with instead of __enable_shared_from_this_helper. * include/bits/shared_ptr.h (__enable_shared_from_this_helper): Remove overload for std::enable_shared_from_this.. (__enable_shared_from_this_base): Define friend function to select a std::enable_shared_from_this base class. * include/bits/shared_ptr_base.h (__enable_shared_from_this_helper): Remove all overloads. (__shared_ptr): Change all relevant constructors to call _M_enable_shared_from_this_with instead of __enable_shared_from_this_helper. (__shared_ptr::__efst_base_t, __shared_ptr::__has_efst_base): Helpers to detect accessible and unambiguous enable_shared_from_this bases. (__shared_ptr::_M_enable_shared_from_this_with): New function to replace __enable_shared_from_this_helper overloads. (__enable_shared_from_this_helper): Remove overload for std::__enable_shared_from_this. (__enable_shared_from_this_base): Define friend function to select a std::__enable_shared_from_this base class. * include/experimental/bits/shared_ptr.h (experimental::shared_ptr): Change relevant constructors to call _M_enable_shared_from_this_with. (experimental::shared_ptr::__efst_base_t) (experimental::shared_ptr::__has_efst_base): Helpers to detect accessible and unambiguous enable_shared_from_this bases. (experimental::shared_ptr::_M_enable_shared_from_this_with): Define. (experimental::__enable_shared_from_this_helper): Remove overload for std::experimental::enable_shared_from_this. (experimental::__expt_enable_shared_from_this_base): Define friend function to select a std::experimental::enable_shared_from_this base. * testsuite/experimental/memory/shared_ptr/cons/ enable_shared_from_this.cc: New test. * testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc: Adjust expected behaviour for shared_ptr<A[]>. Tested powerpc64le-linux, comitted 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] |