bc8f0ed704
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[].
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
// { dg-do compile { target c++11 } }
|
|
#include <memory>
|
|
|
|
// 2762. unique_ptr operator*() should be noexcept
|
|
static_assert( noexcept(*std::declval<std::unique_ptr<long>>()), "LWG 2762" );
|
|
|
|
template<bool B>
|
|
struct deleter
|
|
{
|
|
struct pointer
|
|
{
|
|
int& operator*() && noexcept(B); // this is used by unique_ptr
|
|
int& operator*() const& = delete; // this should not be
|
|
|
|
int* operator->() noexcept(false); // noexcept here doesn't affect anything
|
|
|
|
// Needed for NullablePointer requirements
|
|
pointer(int* = nullptr);
|
|
bool operator==(const pointer&) const noexcept;
|
|
bool operator!=(const pointer&) const noexcept;
|
|
};
|
|
|
|
void operator()(pointer) const noexcept { }
|
|
};
|
|
|
|
template<typename T, bool Nothrow>
|
|
using UPtr = std::unique_ptr<T, deleter<Nothrow>>;
|
|
|
|
// noexcept-specifier depends on the pointer type
|
|
static_assert( noexcept(*std::declval<UPtr<int, true>&>()), "LWG 2762" );
|
|
static_assert( ! noexcept(*std::declval<UPtr<int, false>&>()), "LWG 2762" );
|
|
|
|
// This has always been required, even in C++11.
|
|
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" );
|