From: Luc Grosheintz Date: Tue, 23 Sep 2025 13:10:03 +0000 (+0200) Subject: libstdc++: Prepare mapping layout tests for padded layouts. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=181e7bea46ceb0ee2c5ee2d95dab7ff97158d7b3;p=thirdparty%2Fgcc.git libstdc++: Prepare mapping layout tests for padded layouts. Using the existing tests for padded layouts requires the following changes: * The padded layouts are template classes. In order to be able to use partially specialized templates, functions need to be converted to structs. * The layout mapping tests include a check that only applies if is_exhaustive is static. This commit introduces a concept to check if is_exhaustive is a static member function. * Fix a test to not use a hard-coded layout_left. The test empty.cc contains indentation mistakes that are fixed. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/layouts/empty.cc: Fix indent. * testsuite/23_containers/mdspan/layouts/mapping.cc (test_stride_1d): Fix test. (test_stride_2d): Rewrite using a struct. (test_stride_3d): Ditto. (has_static_is_exhaustive): New concept. (test_mapping_properties): Update test. Reviewed-by: Tomasz KamiƄski Reviewed-by: Jonathan Wakely Signed-off-by: Luc Grosheintz --- diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc index 655b9b6d6c3..cbc425f6c15 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc @@ -30,96 +30,96 @@ template } template -constexpr void -test_static_overflow() -{ - constexpr Int n1 = std::numeric_limits::max(); - constexpr size_t n2 = std::dynamic_extent - 1; - constexpr size_t n = std::cmp_less(n1, n2) ? size_t(n1) : n2; - - verify_all(typename Layout::mapping>{}); - verify_all(typename Layout::mapping>{}); - verify_all(typename Layout::mapping>{}); - verify_all(typename Layout::mapping>{}); - verify_all(typename Layout::mapping>{}); -} + constexpr void + test_static_overflow() + { + constexpr Int n1 = std::numeric_limits::max(); + constexpr size_t n2 = std::dynamic_extent - 1; + constexpr size_t n = std::cmp_less(n1, n2) ? size_t(n1) : n2; + + verify_all(typename Layout::mapping>{}); + verify_all(typename Layout::mapping>{}); + verify_all(typename Layout::mapping>{}); + verify_all(typename Layout::mapping>{}); + verify_all(typename Layout::mapping>{}); + } template -constexpr std::array -make_strides() -{ - std::array strides; - std::ranges::fill(strides, Int(1)); - return strides; -} + constexpr std::array + make_strides() + { + std::array strides; + std::ranges::fill(strides, Int(1)); + return strides; + } template -constexpr typename Layout::mapping -make_mapping(Extents exts) -{ - using IndexType = typename Extents::index_type; - constexpr auto rank = Extents::rank(); - constexpr auto strides = make_strides(); - - if constexpr (std::same_as) - return typename Layout::mapping(exts, strides); - else - return typename Layout::mapping(exts); -} + constexpr typename Layout::mapping + make_mapping(Extents exts) + { + using IndexType = typename Extents::index_type; + constexpr auto rank = Extents::rank(); + constexpr auto strides = make_strides(); + + if constexpr (std::same_as) + return typename Layout::mapping(exts, strides); + else + return typename Layout::mapping(exts); + } template -constexpr void -test_dynamic_overflow() -{ - constexpr Int n1 = std::numeric_limits::max(); - constexpr size_t n2 = std::dynamic_extent - 1; - constexpr Int n = std::cmp_less(n1, n2) ? n1 : Int(n2); + constexpr void + test_dynamic_overflow() + { + constexpr Int n1 = std::numeric_limits::max(); + constexpr size_t n2 = std::dynamic_extent - 1; + constexpr Int n = std::cmp_less(n1, n2) ? n1 : Int(n2); - verify_all(make_mapping( - std::extents{n, n, n, n})); + verify_all(make_mapping( + std::extents{n, n, n, n})); - verify_all(make_mapping( - std::extents{n, n, 0, n, n})); + verify_all(make_mapping( + std::extents{n, n, 0, n, n})); - verify_all(make_mapping( - std::extents{n, n, n})); + verify_all(make_mapping( + std::extents{n, n, n})); - verify_all(make_mapping( - std::extents{n, n, n, 0})); + verify_all(make_mapping( + std::extents{n, n, n, 0})); - verify_all(make_mapping( - std::extents{n, n, n})); + verify_all(make_mapping( + std::extents{n, n, n})); - verify_all(make_mapping( - std::extents{0, n, n, n})); -} + verify_all(make_mapping( + std::extents{0, n, n, n})); + } template -constexpr void -test_overflow() -{ - test_static_overflow(); - test_dynamic_overflow(); -} + constexpr void + test_overflow() + { + test_static_overflow(); + test_dynamic_overflow(); + } template -constexpr bool -test_all() -{ - test_overflow(); - test_overflow(); - test_overflow(); - test_overflow(); - test_overflow(); - - test_overflow(); - test_overflow(); - test_overflow(); - test_overflow(); - test_overflow(); - test_overflow(); - return true; -} + constexpr bool + test_all() + { + test_overflow(); + test_overflow(); + test_overflow(); + test_overflow(); + test_overflow(); + + test_overflow(); + test_overflow(); + test_overflow(); + test_overflow(); + test_overflow(); + test_overflow(); + return true; + } int main() diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc index 58bce514435..db15e2a48f3 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc @@ -7,6 +7,15 @@ constexpr size_t dyn = std::dynamic_extent; +template + concept has_static_is_exhaustive = requires + { + { Mapping::is_exhaustive() } -> std::same_as; + }; + +static_assert(has_static_is_exhaustive>>); +static_assert(!has_static_is_exhaustive>>); + template constexpr bool test_mapping_properties() @@ -32,7 +41,7 @@ template static_assert(M::is_always_unique() && M::is_unique()); static_assert(M::is_always_strided() && M::is_strided()); - if constexpr (!std::is_same_v) + if constexpr (has_static_is_exhaustive) static_assert(M::is_always_exhaustive() && M::is_exhaustive()); return true; } @@ -306,7 +315,7 @@ template constexpr void test_stride_1d() { - std::layout_left::mapping> m; + typename Layout::mapping> m; VERIFY(m.stride(0) == 1); } @@ -321,73 +330,104 @@ template<> } template - constexpr void - test_stride_2d(); +struct TestStride2D; template<> - constexpr void - test_stride_2d() - { - std::layout_left::mapping> m; - VERIFY(m.stride(0) == 1); - VERIFY(m.stride(1) == 3); - } + struct TestStride2D + { + static constexpr void + run() + { + std::layout_left::mapping> m; + VERIFY(m.stride(0) == 1); + VERIFY(m.stride(1) == 3); + } + }; template<> - constexpr void - test_stride_2d() - { - std::layout_right::mapping> m; - VERIFY(m.stride(0) == 5); - VERIFY(m.stride(1) == 1); - } + struct TestStride2D + { + static constexpr void + run() + { + std::layout_right::mapping> m; + VERIFY(m.stride(0) == 5); + VERIFY(m.stride(1) == 1); + } + }; template<> + struct TestStride2D + { + static constexpr void + run() + { + std::array strides{13, 2}; + std::layout_stride::mapping m(std::extents{}, strides); + VERIFY(m.stride(0) == strides[0]); + VERIFY(m.stride(1) == strides[1]); + VERIFY(m.strides() == strides); + } + }; + +template constexpr void - test_stride_2d() + test_stride_2d() { - std::array strides{13, 2}; - std::layout_stride::mapping m(std::extents{}, strides); - VERIFY(m.stride(0) == strides[0]); - VERIFY(m.stride(1) == strides[1]); - VERIFY(m.strides() == strides); + TestStride2D::run(); } template - constexpr void - test_stride_3d(); +struct TestStride3D; template<> - constexpr void - test_stride_3d() - { - std::layout_left::mapping m(std::dextents(3, 5, 7)); - VERIFY(m.stride(0) == 1); - VERIFY(m.stride(1) == 3); - VERIFY(m.stride(2) == 3*5); - } + struct TestStride3D + { + static constexpr void + run() + { + std::layout_left::mapping m(std::dextents(3, 5, 7)); + VERIFY(m.stride(0) == 1); + VERIFY(m.stride(1) == 3); + VERIFY(m.stride(2) == 3*5); + } + }; + template<> - constexpr void - test_stride_3d() - { - std::layout_right::mapping m(std::dextents(3, 5, 7)); - VERIFY(m.stride(0) == 5*7); - VERIFY(m.stride(1) == 7); - VERIFY(m.stride(2) == 1); - } + struct TestStride3D + { + static constexpr void + run() + { + std::layout_right::mapping m(std::dextents(3, 5, 7)); + VERIFY(m.stride(0) == 5*7); + VERIFY(m.stride(1) == 7); + VERIFY(m.stride(2) == 1); + } + }; template<> + struct TestStride3D + { + static constexpr void + run() + { + std::dextents exts(3, 5, 7); + std::array strides{11, 2, 41}; + std::layout_stride::mapping> m(exts, strides); + VERIFY(m.stride(0) == strides[0]); + VERIFY(m.stride(1) == strides[1]); + VERIFY(m.stride(2) == strides[2]); + VERIFY(m.strides() == strides); + } + }; + +template constexpr void - test_stride_3d() + test_stride_3d() { - std::dextents exts(3, 5, 7); - std::array strides{11, 2, 41}; - std::layout_stride::mapping> m(exts, strides); - VERIFY(m.stride(0) == strides[0]); - VERIFY(m.stride(1) == strides[1]); - VERIFY(m.stride(2) == strides[2]); - VERIFY(m.strides() == strides); + TestStride3D::run(); } template