optional
/variant
/any
Section: 22.5.3.2 [optional.ctor], 22.5.3.4 [optional.assign], 22.6.3.2 [variant.ctor], 22.7.4.2 [any.cons], 22.7.4.4 [any.modifiers] Status: New Submitter: Tim Song Opened: 2016-10-29 Last modified: 2020-06-13
Priority: 3
View all other issues in [optional.ctor].
View all issues with New status.
Discussion:
Throughout optional
/variant
/any
's specification references are made to "the selected constructor
of T
". For example, 22.5.3.2 [optional.ctor]/16 says of the constructor from const T&
:
-16- Remarks: If
T
's selected constructor is aconstexpr
constructor, this constructor shall be aconstexpr
constructor.
Similarly, the in-place constructor has this wording (22.5.3.2 [optional.ctor]/25-26):
-25- Throws: Any exception thrown by the selected constructor of
-26- Remarks: IfT
.T
's constructor selected for the initialization is aconstexpr
constructor, this constructor shall be aconstexpr
constructor.
If T
is a scalar type, it has no constructor at all. Moreover, even for
class types, the in-place constructor wording ignores any implicit conversion done on the argument before the selected
constructor is called, which 1) may not be valid in constant expressions and 2) may throw an exception; such exceptions
aren't thrown "by the selected constructor of T
" but outside it.
[Issues Telecon 16-Dec-2016]
Priority 3; Jonathan to provide wording.
[2020-06-11; Nina Dinka Ranns comments and provides initial wording]
This wording depends on the current resolution for LWG 2833, which covers the constexpr
portion of this issue.
Proposed resolution:
This wording is relative to N4861.
Modify 22.5.3.2 [optional.ctor] as indicated:
constexpr optional(const optional& rhs);-3- […]
-4- […] -5- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
constexpr optional(optional&& rhs) noexcept(see below);-7- […]
[…] -10- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
template<class... Args> constexpr explicit optional(in_place_t, Args&&... args);-12- […]
[…] -15- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
template<class U, class... Args> constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);-17- […]
[…] -20- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
template<class U = T> constexpr explicit(see below) optional(U&& v);-22- […]
[…] -25- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
template<class U> explicit(see below) optional(const optional<U>& rhs);-27- […]
[…] -30- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
template<class U> explicit(see below) optional(optional<U>&& rhs);-32- […]
[…] -35- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.T
Modify 22.6.3.2 [variant.ctor] as indicated:
template<class T, class... Args> constexpr explicit variant(in_place_type_t<T>, Args&&... args);-20- […]
[…] -23- Throws: Any exception thrown bycalling the selected constructor ofthe initialization of the contained value.T
template<class T, class U, class... Args> constexpr explicit variant(in_place_type_t<T>, initializer_list<U> il, Args&&... args);-25- […]
[…] -28- Throws: Any exception thrown bycalling the selected constructor ofthe initialization of the contained value.T
template<size_t I, class... Args> constexpr explicit variant(in_place_index_t<I>, Args&&... args);-30 […]
[…] -33- Throws: Any exception thrown bycalling the selected constructor ofthe initialization of the contained value.TI
Modify 22.7.4.2 [any.cons] as indicated:
any(const any& other);[…]-2- Effects: […]
-3- Throws: Any exceptionsarising from calling the selected constructor forthrown by the initialization of the contained value.template<class T> any(T&& value);-5- […]
[…] -9- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.VT
template<class T, class... Args> explicit any(in_place_type_t<T>, Args&&... args);-10- […]
[…] -15- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.VT
template<class T, class U, class... Args> explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);-16- […]
[…] -21- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.VT
Modify 22.7.4.4 [any.modifiers] as indicated:
template<class T, class... Args> decay_t<T>& emplace(Args&&... args);-1- […]
[…] -7- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value. -8- […]VT
template<class T, class U, class... Args> decay_t<T>& emplace(initializer_list<U> il, Args&&... args);-9- […]
[…] -15- Throws: Any exception thrown by theselected constructor ofinitialization of the contained value.VT