Movatterモバイル変換


[0]ホーム

URL:



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

3919.enumerate_view may invoke UB for sized common non-forward underlying ranges

Section: 25.7.24[range.enumerate]Status:WPSubmitter: Patrick PalkaOpened: 2023-04-07Last modified: 2024-04-02

Priority:3

View all issues withWP status.

Discussion:

For a sized common range,enumerate_view::end() is specified to callranges::distance. Butranges::distance is not necessarily well-definedfor a sized non-forward range after callingranges::begin (according to25.4.4[range.sized]).

So for a sized common non-forward underlying range, it seems callingenumerate_view::begin() followed byenumerate_view::end() may invoke UBand thus makeenumerate_view potentially unusable for such ranges.

I suppose we might need to instead call and cache the result ofranges::distance fromenumerate_view::begin() for such ranges.

[2022-04-12; Patrick Palka provides wording]

The proposed wording follows the suggestion provided by Tim Song, to simply makeenumerate non-common for this case.

[2023-05-24; Reflector poll]

Set priority to 3 after reflector poll.

[Kona 2023-11-10; move to Ready]

[Tokyo 2024-03-23; Status changed: Voting → WP.]

Proposed resolution:

This wording is relative toN4944.

  1. Modify 25.7.24.2[range.enumerate.view], class template classenumerate_view synopsis, as indicated:

    […]constexpr auto end() requires (!simple-view<V>) {  if constexpr (forward_range<V> && common_range<V> && sized_range<V>)    returniterator<false>(ranges::end(base_), ranges::distance(base_));  else    returnsentinel<false>(ranges::end(base_));}constexpr auto end() const requiresrange-with-movable-references<const V> {  if constexpr (forward_range<const V> && common_range<const V> && sized_range<const V>)    returniterator<true>(ranges::end(base_), ranges::distance(base_));  else    returnsentinel<true>(ranges::end(base_));}[…]

[8]ページ先頭

©2009-2026 Movatter.jp