Title
§[iterator.range] Missing noexcept for std::rbegin/rend for arrays and initializer_list
Status
new
Section
[iterator.range]
Submitter
Jiang An

Created on 2021-03-21.00:00:00 last changed 1 month ago

Messages

Date: 2021-04-15.00:00:00

[ 2021-04-20; Reflector poll ]

Priority set to 3.

Jonathan: This would create a strange situation where std::rbegin and std::crbegin on an initializer_list are noexcept but std::begin and std::cbegin aren't guaranteed to be (because an initializer_list uses the generic std::begin and std::cbegin overloads, which have no conditional noexcept).

Casey: I don't think we should mark these rbegin/rend overloads noexcept without making the pertinent reverse_iterator constructors conditionally noexcept.

Date: 2021-03-15.00:00:00

[ 2021-03-21; Daniel comments ]

There is intentionally no P/R provided at this point, but I'm volunteering to provide it if we got feedback whether adding conditional noexcept specifiers similar to those provided by LWG 2280 would be preferred or not.

Date: 2021-03-21.00:00:00

Overloads for std::rbegin/rend for built-in arrays and std::initializer_list's has no preconditions and never throw exceptions, thus should be noexcept. LWG 2280 addressed a similar issue for std::begin/end.

Suggestion: change these declarations in [iterator.range] (p10, 11, 12, 13) as indicated:

template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]) noexcept;

template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]) noexcept;

template<class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il) noexcept;

template<class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il) noexcept;

If this change is accepted, we may also specify conditional noexcept for std::crbegin/crend (in [iterator.range] p14, 15), by adding noexcept(noexcept(std::rbegin/crend(c))), like in LWG 2280.

Conditional noexcept for other functions in [iterator.range] (p2, 3, 7, 8, 16, 18, 20 22) may also be added for consistency.

History
Date User Action Args
2021-04-20 20:40:18adminsetmessages: + msg11776
2021-03-21 19:01:47adminsetmessages: + msg11754
2021-03-21 00:00:00admincreate