From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id B0B663853809; Fri, 2 Jul 2021 11:15:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0B663853809 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-1976] libstdc++: Revert changes to std::unique_ptr::operator[] [PR 101271] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 496e1d6a1f973b3952a37163441f9149501dfb26 X-Git-Newrev: bc8f0ed7042280282035168428f6afc839997cf0 Message-Id: <20210702111536.B0B663853809@sourceware.org> Date: Fri, 2 Jul 2021 11:15:36 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jul 2021 11:15:36 -0000 https://gcc.gnu.org/g:bc8f0ed7042280282035168428f6afc839997cf0 commit r12-1976-gbc8f0ed7042280282035168428f6afc839997cf0 Author: Jonathan Wakely Date: Fri Jul 2 08:46:18 2021 +0100 libstdc++: Revert changes to std::unique_ptr::operator[] [PR 101271] This reverts the changes in r12-1778 which added a noexcept-specifier to std::unique_ptr::operator[], and the changes in r12-1844 which tried to make it work with incomplete types (for PR 101236). The noexcept-specifier is not required by the standard, and is causing regressions, so just remove it. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101271 * include/bits/unique_ptr.h (unique_ptr::operator[]): Remove noexcept-specifier. (unique_ptr::_S_nothrow_deref): Remove. * testsuite/20_util/unique_ptr/lwg2762.cc: Remove checks for operator[]. Diff: --- libstdc++-v3/include/bits/unique_ptr.h | 15 --------------- libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc | 18 ------------------ 2 files changed, 33 deletions(-) diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index e478056c755..d483f13f2b0 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -491,20 +491,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = __and_< is_base_of<_Tp, _Up>, __not_, __remove_cv<_Up>>> >; - // This checks whether p[n] is noexcept, but fails gracefully when - // element_type is incomplete. The standard requires a complete type - // for unique_ptr, but we try to support it anyway (PR 101236). - template - static constexpr auto - _S_nothrow_deref(size_t __n) - -> decltype(sizeof(_Elt) != 0) // PR c++/101239 - { return noexcept(std::declval<_Ptr>()[__n]); } - - template - static constexpr bool - _S_nothrow_deref(...) - { return false; } - public: using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; using element_type = _Tp; @@ -669,7 +655,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Access an element of owned array. typename std::add_lvalue_reference::type operator[](size_t __i) const - noexcept(_S_nothrow_deref(0)) { __glibcxx_assert(get() != pointer()); return get()[__i]; diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc index c88237dd9ea..ea067eb3af3 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc @@ -12,11 +12,6 @@ struct deleter int& operator*() && noexcept(B); // this is used by unique_ptr int& operator*() const& = delete; // this should not be - int& operator[](std::size_t) && noexcept(B); // this is used by unique_ptr - int& operator[](std::size_t) const& = delete; // should not be used - int& operator[](int) && = delete; // should not be used - int& operator[](double) && = delete; // should not be used - int* operator->() noexcept(false); // noexcept here doesn't affect anything // Needed for NullablePointer requirements @@ -40,16 +35,3 @@ static_assert( noexcept(std::declval>().operator->()), "operator-> is always noexcept" ); static_assert( noexcept(std::declval&>().operator->()), "operator-> is always noexcept" ); - -// This is not required by the standard, but we make it depend on the pointer. -static_assert( noexcept(std::declval>()[0]), "QoI" ); -static_assert( noexcept(std::declval&>()[0]), "QoI" ); -static_assert( ! noexcept(std::declval&>()[0]), "QoI" ); - -// This is forbidden by the standard ("T shall be a complete type") -// but we try to support it anyway, see PR libstdc++/101236. -struct Incomplete; -static_assert( ! noexcept(std::declval>()[0]), - "this would be noexcept if the type was complete"); -static_assert( ! noexcept(std::declval>()[0]), - "this would still be noexcept(false) if the type was complete");