From: Luc Grosheintz Date: Wed, 4 Jun 2025 14:58:50 +0000 (+0200) Subject: libstdc++: Add tests for layout_right. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b9edf2d37df44eb7e0ffa3bb7f33c32788b1b11;p=thirdparty%2Fgcc.git libstdc++: Add tests for layout_right. Adds tests for layout_right and for the parts of layout_left that depend on layout_right. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Add tests for layout_right. * testsuite/23_containers/mdspan/layouts/ctors.cc: Add tests for layout_right and the interaction with layout_left. * testsuite/23_containers/mdspan/layouts/empty.cc: ditto. * testsuite/23_containers/mdspan/layouts/mapping.cc: ditto. Signed-off-by: Luc Grosheintz Reviewed-by: Tomasz KamiƄski --- diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc index c6c55bdd4bc..ce721277435 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc @@ -30,7 +30,10 @@ template }; A a_left; // { dg-error "required from" } +A a_right; // { dg-error "required from" } B<1, std::layout_left, std::layout_left> b0; // { dg-error "required here" } +B<3, std::layout_right, std::layout_right> b2; // { dg-error "required here" } + // { dg-prune-output "must be representable as index_type" } diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc index d634fa867cc..6c428c4b111 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc @@ -261,6 +261,66 @@ namespace from_same_layout } } +// ctor: mapping(layout_{right,left}::mapping) +namespace from_left_or_right +{ + template + constexpr void + verify_ctor(OExtents oexts) + { + using SMapping = typename SLayout::mapping; + using OMapping = typename OLayout::mapping; + + constexpr bool expected = std::is_convertible_v; + if constexpr (expected) + verify_nothrow_convertible(OMapping(oexts)); + else + verify_nothrow_constructible(OMapping(oexts)); + } + + template + constexpr bool + test_ctor() + { + assert_not_constructible< + typename SLayout::mapping>, + typename OLayout::mapping>>(); + + verify_ctor>( + std::extents{}); + + verify_ctor>( + std::extents{}); + + assert_not_constructible< + typename SLayout::mapping>, + typename OLayout::mapping>>(); + + verify_ctor>( + std::extents{}); + + verify_ctor>( + std::extents{}); + + verify_ctor>( + std::extents{}); + + assert_not_constructible< + typename SLayout::mapping>, + typename OLayout::mapping>>(); + return true; + } + + template + constexpr void + test_all() + { + test_ctor(); + static_assert(test_ctor()); + } +} + template constexpr void test_all() @@ -274,5 +334,9 @@ int main() { test_all(); + test_all(); + + from_left_or_right::test_all(); + from_left_or_right::test_all(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc index 9c2ae363da0..d89fe293cdb 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/empty.cc @@ -108,5 +108,6 @@ int main() { static_assert(test_all()); + static_assert(test_all()); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc index a5be1166617..4dc0db66865 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/mapping.cc @@ -293,6 +293,15 @@ template<> 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); + } + template constexpr void test_stride_3d(); @@ -307,6 +316,16 @@ template<> 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); + } + template constexpr bool test_stride_all() @@ -381,24 +400,59 @@ template { m2 != m1 } -> std::same_as; }; -template - constexpr bool +template + constexpr void test_has_op_eq() { + static_assert(has_op_eq< + typename SLayout::mapping>, + typename OLayout::mapping>> == Expected); + static_assert(!has_op_eq< - typename Layout::mapping>, - typename Layout::mapping>>); + typename SLayout::mapping>, + typename OLayout::mapping>>); static_assert(has_op_eq< - typename Layout::mapping>, - typename Layout::mapping>>); + typename SLayout::mapping>, + typename OLayout::mapping>> == Expected); static_assert(has_op_eq< - typename Layout::mapping>, - typename Layout::mapping>>); - return true; + typename SLayout::mapping>, + typename OLayout::mapping>> == Expected); + + static_assert(!has_op_eq< + typename SLayout::mapping>, + typename OLayout::mapping>>); + + static_assert(has_op_eq< + typename SLayout::mapping>, + typename OLayout::mapping>> == Expected); + + static_assert(has_op_eq< + typename SLayout::mapping>, + typename OLayout::mapping>> == Expected); + + static_assert(!has_op_eq< + typename SLayout::mapping>, + typename OLayout::mapping>>); } +constexpr void +test_has_op_eq_peculiar() +{ + static_assert(has_op_eq< + std::layout_right::mapping>, + std::layout_left::mapping>>); + + static_assert(has_op_eq< + std::layout_right::mapping>, + std::layout_left::mapping>>); + + static_assert(!has_op_eq< + std::layout_right::mapping>, + std::layout_left::mapping>>); +} + template constexpr bool test_mapping_all() @@ -426,12 +480,16 @@ template test_has_stride_0d(); test_has_stride_1d(); test_has_stride_2d(); - test_has_op_eq(); + test_has_op_eq(); } int main() { test_all(); + test_all(); + + test_has_op_eq(); + test_has_op_eq_peculiar(); return 0; }