]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make layout_left(layout_stride) noexcept.
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Wed, 4 Jun 2025 14:58:53 +0000 (16:58 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 12 Jun 2025 09:56:02 +0000 (11:56 +0200)
[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 <luc.grosheintz@gmail.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/mdspan
libstdc++-v3/testsuite/23_containers/mdspan/layouts/ctors.cc

index fe182c35a558dca70fa4701343898dfbe14a2849..4a3e863bed5f3900e25293c509cc48b94bbc0b29 100644 (file)
@@ -561,10 +561,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        : mapping(__other.extents(), __mdspan::__internal_ctor{})
        { }
 
+      // noexcept for consistency with other layouts.
       template<typename _OExtents>
        requires is_constructible_v<extents_type, _OExtents>
        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); }
 
index 92507a8e769d0c281dbdbc39ed3b844ef83ab33a..23c0a55dae19c787178eb12b0f5697b22ccf50a6 100644 (file)
@@ -339,30 +339,24 @@ namespace from_stride
 
   template<typename Layout, typename Extents, typename OExtents>
     constexpr void
-    verify_convertible(OExtents oexts)
+    verify_nothrow_convertible(OExtents oexts)
     {
       using Mapping = typename Layout::mapping<Extents>;
       using OMapping = std::layout_stride::mapping<OExtents>;
 
       constexpr auto other = OMapping(oexts, strides(Mapping(Extents(oexts))));
-      if constexpr (std::is_same_v<Layout, std::layout_right>)
-       ::verify_nothrow_convertible<Mapping>(other);
-      else
-       ::verify_convertible<Mapping>(other);
+      ::verify_nothrow_convertible<Mapping>(other);
     }
 
   template<typename Layout, typename Extents, typename OExtents>
     constexpr void
-    verify_constructible(OExtents oexts)
+    verify_nothrow_constructible(OExtents oexts)
     {
       using Mapping = typename Layout::mapping<Extents>;
       using OMapping = std::layout_stride::mapping<OExtents>;
 
       constexpr auto other = OMapping(oexts, strides(Mapping(Extents(oexts))));
-      if constexpr (std::is_same_v<Layout, std::layout_right>)
-       ::verify_nothrow_constructible<Mapping>(other);
-      else
-       ::verify_constructible<Mapping>(other);
+      ::verify_nothrow_constructible<Mapping>(other);
     }
 
   template<typename Layout>
@@ -381,31 +375,32 @@ namespace from_stride
        typename Layout::mapping<std::extents<int, 2>>,
        std::layout_stride::mapping<std::extents<int, 1>>>();
 
-      verify_convertible<Layout, std::extents<int>>(std::extents<int>{});
+      verify_nothrow_convertible<Layout, std::extents<int>>(
+       std::extents<int>{});
 
-      verify_convertible<Layout, std::extents<unsigned int>>(
+      verify_nothrow_convertible<Layout, std::extents<unsigned int>>(
        std::extents<int>{});
 
       // Rank ==  0 doesn't check IndexType for convertibility.
-      verify_convertible<Layout, std::extents<int>>(
+      verify_nothrow_convertible<Layout, std::extents<int>>(
        std::extents<unsigned int>{});
 
-      verify_constructible<Layout, std::extents<int, 3>>(
+      verify_nothrow_constructible<Layout, std::extents<int, 3>>(
        std::extents<int, 3>{});
 
-      verify_constructible<Layout, std::extents<unsigned int, 3>>(
+      verify_nothrow_constructible<Layout, std::extents<unsigned int, 3>>(
        std::extents<int, 3>{});
 
-      verify_constructible<Layout, std::extents<int, 3>>(
+      verify_nothrow_constructible<Layout, std::extents<int, 3>>(
        std::extents<unsigned int, 3>{});
 
-      verify_constructible<Layout, std::extents<int, 3, 5>>(
+      verify_nothrow_constructible<Layout, std::extents<int, 3, 5>>(
        std::extents<int, 3, 5>{});
 
-      verify_constructible<Layout, std::extents<unsigned int, 3, 5>>(
+      verify_nothrow_constructible<Layout, std::extents<unsigned int, 3, 5>>(
        std::extents<int, 3, 5>{});
 
-      verify_constructible<Layout, std::extents<int, 3, 5>>(
+      verify_nothrow_constructible<Layout, std::extents<int, 3, 5>>(
        std::extents<unsigned int, 3, 5>{});
       return true;
     }