From: Luc Grosheintz Date: Wed, 4 Jun 2025 14:58:53 +0000 (+0200) Subject: libstdc++: Make layout_left(layout_stride) noexcept. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1620e1ac8f5654678245f9f0eda876d0dec0b567;p=thirdparty%2Fgcc.git libstdc++: Make layout_left(layout_stride) noexcept. [mdspan.layout.left.cons] of N4950 states that this ctor is not noexcept. Since, all other ctors of layout_left, layout_right or layout_stride are noexcept, the choice was made, based on [res.on.exception.handling], to make this ctor noexcept. Two other major standard library implementations make the same choice. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_left): Strengthen the exception guarantees of layout_left::mapping(layout_stride::mapping). * testsuite/23_containers/mdspan/layouts/ctors.cc: Simplify tests to reflect the change. Signed-off-by: Luc Grosheintz Reviewed-by: Tomasz KamiƄski --- diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index fe182c35a55..4a3e863bed5 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -561,10 +561,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : mapping(__other.extents(), __mdspan::__internal_ctor{}) { } + // noexcept for consistency with other layouts. template requires is_constructible_v constexpr explicit(extents_type::rank() > 0) - mapping(const layout_stride::mapping<_OExtents>& __other) + mapping(const layout_stride::mapping<_OExtents>& __other) noexcept : mapping(__other.extents(), __mdspan::__internal_ctor{}) { __glibcxx_assert(*this == __other); } diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc index 92507a8e769..23c0a55dae1 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc @@ -339,30 +339,24 @@ namespace from_stride template constexpr void - verify_convertible(OExtents oexts) + verify_nothrow_convertible(OExtents oexts) { using Mapping = typename Layout::mapping; using OMapping = std::layout_stride::mapping; constexpr auto other = OMapping(oexts, strides(Mapping(Extents(oexts)))); - if constexpr (std::is_same_v) - ::verify_nothrow_convertible(other); - else - ::verify_convertible(other); + ::verify_nothrow_convertible(other); } template constexpr void - verify_constructible(OExtents oexts) + verify_nothrow_constructible(OExtents oexts) { using Mapping = typename Layout::mapping; using OMapping = std::layout_stride::mapping; constexpr auto other = OMapping(oexts, strides(Mapping(Extents(oexts)))); - if constexpr (std::is_same_v) - ::verify_nothrow_constructible(other); - else - ::verify_constructible(other); + ::verify_nothrow_constructible(other); } template @@ -381,31 +375,32 @@ namespace from_stride typename Layout::mapping>, std::layout_stride::mapping>>(); - verify_convertible>(std::extents{}); + verify_nothrow_convertible>( + std::extents{}); - verify_convertible>( + verify_nothrow_convertible>( std::extents{}); // Rank == 0 doesn't check IndexType for convertibility. - verify_convertible>( + verify_nothrow_convertible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); - verify_constructible>( + verify_nothrow_constructible>( std::extents{}); return true; }