Title
Default constructor of std::layout_XX::mapping misses precondition
Status
c++23
Section
[mdspan.layout]
Submitter
Christian Trott

Created on 2023-02-09.00:00:00 last changed 12 months ago

Messages

Date: 2023-02-13.11:31:32

Proposed resolution:

This wording is relative to n4928.

  1. Modify [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 [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 [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.

Date: 2023-02-13.00:00:00

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

Date: 2023-02-10.18:05:30

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

Move to Immediate for C++23

Date: 2023-02-10.18:05:30

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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 11:31:32adminsetmessages: + msg13401
2023-02-13 11:31:32adminsetstatus: immediate -> wp
2023-02-10 18:05:30adminsetmessages: + msg13339
2023-02-10 18:05:30adminsetstatus: new -> immediate
2023-02-09 18:21:26adminsetmessages: + msg13312
2023-02-09 00:00:00admincreate