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.

4073. concat_view::size may overflow

Section: 26.7.18.2 [range.concat.view] Status: New Submitter: Hewill Kang Opened: 2024-04-21 Last modified: 2024-04-21

Priority: Not Prioritized

View all issues with New status.

Discussion:

Currently, concat_view::size returns the sum of sizes of all underlying ranges, and the return type is specified to be the common type of all sizes, which may lead to potential overflow:

auto r = std::views::iota(0uz, SIZE_MAX);
std::print("{}\n", r.size());            // 18446744073709551615 (size_t)
std::print("{}\n", r.end() - r.begin()); // 18446744073709551615 (__int128)

auto c = std::views::concat(r, r);    
std::print("{}\n", c.size());            // 18446744073709551614 (size_t)
std::print("{}\n", c.end() - c.begin()); // 36893488147419103230 (__int128)

Proposed resolution: