libstdc++: Implement LWG 2762 for std::unique_ptr::operator*
authorJonathan Wakely <jwakely@redhat.com>
Thu, 24 Jun 2021 11:56:20 +0000 (12:56 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 24 Jun 2021 13:04:02 +0000 (14:04 +0100)
commit17bc3848e065c0980523e1a1592f2f03b24b4f1c
tree0149b4f6b118bc81b9423c4f634c74b678f7d430
parenta21dc9d1529b8a8071e36b22b6e8492fc2ce7d5a
libstdc++: Implement LWG 2762 for std::unique_ptr::operator*

The LWG issue proposes to add a conditional noexcept-specifier to
std::unique_ptr's dereference operator. The issue is currently in
Tentatively Ready status, but even if it isn't voted into the draft, we
can do it as a conforming extensions. This commit also adds a similar
noexcept-specifier to operator[] for the unique_ptr<T[], D> partial
specialization.

Also ensure that all dereference operators for shared_ptr are noexcept,
and adds tests for the std::optional accessors modified by the issue,
which were already noexcept in our implementation.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_base.h (__shared_ptr_access::operator[]):
Add noexcept.
* include/bits/unique_ptr.h (unique_ptr::operator*): Add
conditional noexcept as per LWG 2762.
* testsuite/20_util/shared_ptr/observers/array.cc: Check that
dereferencing cannot throw.
* testsuite/20_util/shared_ptr/observers/get.cc: Likewise.
* testsuite/20_util/optional/observers/lwg2762.cc: New test.
* testsuite/20_util/unique_ptr/lwg2762.cc: New test.
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/bits/unique_ptr.h
libstdc++-v3/testsuite/20_util/optional/observers/lwg2762.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/shared_ptr/observers/array.cc
libstdc++-v3/testsuite/20_util/shared_ptr/observers/get.cc
libstdc++-v3/testsuite/20_util/unique_ptr/lwg2762.cc [new file with mode: 0644]