]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Revert changes to std::unique_ptr<T[]>::operator[] [PR 101271]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 2 Jul 2021 07:46:18 +0000 (08:46 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 2 Jul 2021 11:15:28 +0000 (12:15 +0100)
This reverts the changes in r12-1778 which added a noexcept-specifier to
std::unique_ptr<T[]>::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 <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/101271
* include/bits/unique_ptr.h (unique_ptr<T[],D>::operator[]):
Remove noexcept-specifier.
(unique_ptr<T[],D>::_S_nothrow_deref): Remove.
* testsuite/20_util/unique_ptr/lwg2762.cc: Remove checks for
operator[].

libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc

index e478056c755bcd99f6f93f699ee63b53e0161fdb..d483f13f2b0354401d9518f368f8d7b4e43a70cd 100644 (file)
@@ -491,20 +491,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          = __and_< is_base_of<_Tp, _Up>,
                    __not_<is_same<__remove_cv<_Tp>, __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<T[], D>, but we try to support it anyway (PR 101236).
-      template<typename _Ptr, typename _Elt>
-       static constexpr auto
-       _S_nothrow_deref(size_t __n)
-       -> decltype(sizeof(_Elt) != 0) // PR c++/101239
-       { return noexcept(std::declval<_Ptr>()[__n]); }
-
-      template<typename _Ptr, typename _Elt>
-       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<element_type>::type
       operator[](size_t __i) const
-      noexcept(_S_nothrow_deref<pointer, element_type>(0))
       {
        __glibcxx_assert(get() != pointer());
        return get()[__i];
index c88237dd9ea1ed74a949b14bbaa7016765a595e3..ea067eb3af3b2bbb0adcbb8f0eb9ab9094075ac6 100644 (file)
@@ -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<std::unique_ptr<long>>().operator->()),
               "operator-> is always noexcept" );
 static_assert( noexcept(std::declval<UPtr<int, false>&>().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<std::unique_ptr<long[]>>()[0]), "QoI" );
-static_assert( noexcept(std::declval<UPtr<int[], true>&>()[0]), "QoI" );
-static_assert( ! noexcept(std::declval<UPtr<int[], false>&>()[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<UPtr<Incomplete[], true>>()[0]),
-              "this would be noexcept if the type was complete");
-static_assert( ! noexcept(std::declval<UPtr<Incomplete[], false>>()[0]),
-              "this would still be noexcept(false) if the type was complete");