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

3948. possibly-const-range and as-const-pointer should be noexcept

Section: 26.2 [ranges.syn], 26.3.14 [range.prim.cdata] Status: WP Submitter: Jiang An Opened: 2023-06-20 Last modified: 2023-11-22

Priority: Not Prioritized

View other active issues in [ranges.syn].

View all other issues in [ranges.syn].

View all issues with WP status.


As of P2278R4, several range access CPOs are specified with possibly-const-range and as-const-pointer. These helper functions never throw exceptions, but are not marked with noexcept. As a result, implementations are currently allowed to make a call to ranges::ccpo potentially throwing while the underlying ranges::cpo call is non-throwing, which doesn't seem to be intended.

[2023-10-27; Reflector poll]

Set status to Tentatively Ready after five votes in favour during reflector poll.

[2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4950.

  1. Modify 26.2 [ranges.syn], header <ranges> synopsis, as indicated:

    // 26.7.22 [], as const view
    template<input_range R>
      constexpr auto& possibly-const-range(R& r) noexcept {      // exposition only
        if constexpr (constant_range<const R> && !constant_range<R>) {
          return const_cast<const R&>(r);
        } else {
          return r;
  2. Modify 26.3.14 [range.prim.cdata] before p1 as indicated:

    template<class T>
    constexpr auto as-const-pointer(const T* p) noexcept { return p; }    // exposition only