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

3876. Default constructor of std::layout_XX::mapping misses precondition

Section: 24.7.3.4 [mdspan.layout] Status: C++23 Submitter: Christian Trott Opened: 2023-02-09 Last modified: 2023-11-22

Priority: Not Prioritized

View all issues with C++23 status.

Discussion:

As shortly discussed during the LWG review of a layout_stride defect, there is currently no protection against creating layout mappings with all static extents where the product of those extents exceeds the representable value range of the index_type.

For example, the following statement does not violate any preconditions or mandates:

layout_left::mapping<extents<int, 100000, 100000>> a{};

But a.required_span_size() would overflow since the implied span size is 10B and thus exceeds what int can represent.

This is only a problem for all static extents, since with any dynamic extent in the mix the implied span size is 0. Hence we can check for this via a mandates check on the class.

The paper P2798R0 has been provided with the proposed wording as shown below.

[Issaquah 2023-02-10; LWG issue processing]

Move to Immediate for C++23

[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP.]

Proposed resolution:

This wording is relative to N4928.

  1. Modify 24.7.3.4.5.1 [mdspan.layout.left.overview] as indicated:

    -2- If Extents is not a specialization of extents, then the program is ill-formed.

    -3- layout_left::mapping<E> is a trivially copyable type that models regular for each E.

    -?- Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.

  2. Modify 24.7.3.4.6.1 [mdspan.layout.right.overview] as indicated:

    -2- If Extents is not a specialization of extents, then the program is ill-formed.

    -3- layout_right::mapping<E> is a trivially copyable type that models regular for each E.

    -?- Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.

  3. Modify 24.7.3.4.7.1 [mdspan.layout.stride.overview] as indicated:

    -2- If Extents is not a specialization of extents, then the program is ill-formed.

    -3- layout_stride::mapping<E> is a trivially copyable type that models regular for each E.

    -?- Mandates: If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() is representable as a value of type typename Extents::index_type.