Issue 2762: unique_ptr operator*() should be noexcept (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.
2762. unique_ptr operator*() should be noexcept
Section: 20.3.1.3.5 [unique.ptr.single.observers] Status: C++23 Submitter: Ville Voutilainen Opened: 2016-08-04 Last modified: 2023-11-22
Priority: 3
View other active issues in [unique.ptr.single.observers].
View all other issues in [unique.ptr.single.observers].
View all issues with C++23 status.
Discussion:
See LWG 2337(i). Since we aren't removing noexcept from shared_ptr'soperator*, we should consider adding noexcept to unique_ptr's operator*.
[2016-08 — Chicago]
Thurs PM: P3, and status to 'LEWG'
[2016-08-05 Chicago]
Ville provides an initial proposed wording.
[LEWG Kona 2017]
->Open: Believe these should be noexcept for consistency. We like these. We agree with the proposed resolution.operator->() already has noexcept.
Also adds optional::operator*
Alisdair points out that fancy pointers might intentionally throw from operator*, and we don't want to prohibit that.
Go forward with conditional noexcept(noexcept(*decltype())).
Previous resolution [SUPERSEDED]:
This wording is relative to N4606.
[Drafting note: since this issue is all about consistency,
optional's pointer-like operators are additionally included.]
- In 20.3.1.3 [unique.ptr.single] synopsis, edit as follows:
add_lvalue_reference_t operator*() const noexcept;
- Before 20.3.1.3.5 [unique.ptr.single.observers]/1, edit as follows:
add_lvalue_reference_t operator*() const noexcept;
- In 22.5.3 [optional.optional] synopsis, edit as follows:
constexpr T const operator->() const noexcept;
constexpr T operator->() noexcept;
constexpr T const &operator() const & noexcept;
constexpr T &operator() & noexcept;
constexpr T &&operator*() && noexcept;
constexpr const T &&operator*() const && noexcept;- Before [optional.object.observe]/1, edit as follows:
constexpr T const* operator->() const noexcept;
constexpr T* operator->() noexcept;- Before [optional.object.observe]/5, edit as follows:
constexpr T const& operator*() const & noexcept;
constexpr T& operator*() & noexcept;- Before [optional.object.observe]/9, edit as follows:
constexpr T&& operator*() && noexcept;
constexpr const T&& operator*() const && noexcept;
[2021-06-19 Tim updates wording]
[2021-06-23; Reflector poll]
Set status to Tentatively Ready after seven votes in favour during reflector poll.
[2021-10-14 Approved at October 2021 virtual plenary. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4892.
[Drafting note: since this issue is all about consistency,
optional's pointer-like operators are additionally included.]
- Edit 20.3.1.3.1 [unique.ptr.single.general], class template
unique_ptrsynopsis, as indicated:namespace std {
template<class T, class D = default_delete> class unique_ptr {
public:
[…]// 20.3.1.3.5 [unique.ptr.single.observers], observers
add_lvalue_reference_t operator*() const noexcept(see below);
[…]
};
} - Edit 20.3.1.3.5 [unique.ptr.single.observers] as indicated:
add_lvalue_reference_t operator*() const noexcept(noexcept(*declval()));
-1- Preconditions:
get() != nullptr.-2- Returns:
*get(). - Edit 22.5.3.1 [optional.optional.general], class template
optionalsynopsis, as indicated:namespace std {
template
class optional {
public:
[…]// 22.5.3.7 [optional.observe], observers
constexpr const T* operator->() const noexcept;
constexpr T* operator->() noexcept;
constexpr const T& operator*() const & noexcept;
constexpr T& operator*() & noexcept;
constexpr T&& operator*() && noexcept;
constexpr const T&& operator*() const && noexcept;[…]
};
} - Edit 22.5.3.7 [optional.observe] as indicated:
constexpr const T* operator->() const noexcept;
constexpr T* operator->() noexcept;-1- Preconditions:
*thiscontains a value.-2- Returns:
val.-3- Throws: Nothing.-4- Remarks: These functions are constexpr functions.
constexpr const T& operator*() const & noexcept;
constexpr T& operator*() & noexcept;-5- Preconditions:
*thiscontains a value.-6- Returns:
*val.-7- Throws: Nothing.-8- Remarks: These functions are constexpr functions.
constexpr T&& operator*() && noexcept;
constexpr const T&& operator*() const && noexcept;-9- Preconditions:
*thiscontains a value.-10- Effects: Equivalent to:
return std::move(*val);