From d24300e5b3c1b7fb5883fc8b4ff24463c54ffe11 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Sun, 27 Jul 2025 15:37:56 +0200 Subject: [PATCH] libstdc++: Refactor tests for mdspan related accessors. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Versions 1, 2 and 3 of the patch for adding aligned_accessor had a bug in the constraints that allowed conversion of aligned_accessor a = aligned_accessor{}; and prevented the reverse. The file mdspan/accessors/generic.cc already contains code that checks all variation of the constraint. This commit allows passing in two different accessors. Enabling it to be reused more widely. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/accessors/generic.cc: Refactor test_ctor. Reviewed-by: Tomasz Kamiński Signed-off-by: Luc Grosheintz --- .../23_containers/mdspan/accessors/generic.cc | 59 ++++++++++++------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/accessors/generic.cc b/libstdc++-v3/testsuite/23_containers/mdspan/accessors/generic.cc index c3350353aae..66009ad89c0 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/accessors/generic.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/accessors/generic.cc @@ -29,44 +29,59 @@ class Base class Derived : public Base { }; -template typename Accessor> +template + constexpr void + check_convertible() + { + RhsAccessor rhs; + [[maybe_unused]] LhsAccessor lhs(rhs); + static_assert(std::is_nothrow_constructible_v); + static_assert(std::is_convertible_v == ExpectConvertible); + } + +template typename LhsAccessor, + template typename RhsAccessor = LhsAccessor, + bool ExpectConvertible = true> constexpr bool test_ctor() { // T -> T - static_assert(std::is_nothrow_constructible_v, - Accessor>); - static_assert(std::is_convertible_v, Accessor>); + check_convertible, LhsAccessor, + ExpectConvertible>(); // T -> const T - static_assert(std::is_convertible_v, - Accessor>); - static_assert(std::is_convertible_v, - Accessor>); + check_convertible, LhsAccessor, + ExpectConvertible>(); + check_convertible, LhsAccessor, + ExpectConvertible>(); // const T -> T - static_assert(!std::is_constructible_v, - Accessor>); - static_assert(!std::is_constructible_v, - Accessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); // T <-> volatile T - static_assert(std::is_convertible_v, Accessor>); - static_assert(!std::is_constructible_v, - Accessor>); + check_convertible, LhsAccessor, + ExpectConvertible>(); + static_assert(!std::is_constructible_v, + RhsAccessor>); // size difference - static_assert(!std::is_constructible_v, Accessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); // signedness - static_assert(!std::is_constructible_v, - Accessor>); - static_assert(!std::is_constructible_v, - Accessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); // Derived <-> Base - static_assert(!std::is_constructible_v, Accessor>); - static_assert(!std::is_constructible_v, Accessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); + static_assert(!std::is_constructible_v, + RhsAccessor>); return true; } -- 2.47.2