This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

4057. generator::iterator's operator* is not noexcept when it can be

Section: 26.8.6 [coro.generator.iterator] Status: New Submitter: S. B. Tam Opened: 2024-03-01 Last modified: 2024-03-03

Priority: Not Prioritized

View all other issues in [coro.generator.iterator].

View all issues with New status.

Discussion:

generator::iterator's operator* is specified to have the following noexcept-specifier:

noexcept(is_nothrow_copy_constructible_v<reference>)

When reference is an rvalue reference type, is_nothrow_copy_constructible_v<reference> is false (because reference is not copy constructible), which means operator* is not noexcept.

However, operator* doesn't perform any potentially-throwing operation in this case. It's effect is equivalent to return static_cast<reference>(*p.value_); (where the type of p.value_ is effectively add_pointer_t<reference>). Neither the dereference nor the cast to rvalue reference can throw an exception.

I think the expression inside the noexcept-specifier should be changed to noexcept(static_cast<reference>(*p.value_)).

Proposed resolution: