possibly-const-range and as-const-pointer should be noexcept
Jiang An

Created on 2023-06-20.00:00:00 last changed 2 months ago


Date: 2023-06-25.08:39:56

Proposed resolution:

This wording is relative to N4950.

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

    // [range.as.const], 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 [range.prim.cdata] before p1 as indicated:

    template<class T>
    constexpr auto as-const-pointer(const T* p) noexcept { return p; }    // exposition only
Date: 2023-06-20.00:00:00

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.

Date User Action Args
2023-06-25 08:39:56adminsetmessages: + msg13662
2023-06-20 00:00:00admincreate