[libcxx-commits] [libcxx] [libc++] Partially implement P2642R6: Padded mdspan layouts (PR #187873)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 21 11:00:00 PDT 2026


================
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+// <mdspan>
+
+// constexpr mapping(const layout_stride::mapping<OtherExtents>& other);
+// constexpr mapping(const LayoutLeftPaddedMapping& other);
+
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <mdspan>
+
+#include "check_assertion.h"
+
+int main() {
+#if 0
+  {
+    using Src = std::layout_left_padded<std::dynamic_extent>::mapping<std::extents<uint32_t, 1, 0>>;
+    using Dst = std::layout_left_padded<std::dynamic_extent>::mapping<std::extents<uint8_t, 1, 0>>;
+
+    Src src(std::extents<uint32_t, 1, 0>(), 256);
+
+    TEST_LIBCPP_ASSERT_FAILURE(
+        Dst(src),
+        "layout_left_padded::mapping from layout_left_padded ctor: source padded stride must be "
+        "representable as index_type.");
+  }
+
+  {
+    using Src = std::layout_stride::mapping<std::extents<uint32_t, 1, 0>>;
+    using Dst = std::layout_left_padded<std::dynamic_extent>::mapping<std::extents<uint8_t, 1, 0>>;
+
+    Src src(std::extents<uint32_t, 1, 0>(), std::array<uint32_t, 2>{1, 256});
+
+    TEST_LIBCPP_ASSERT_FAILURE(
+        Dst(src),
+        "layout_left_padded::mapping from layout_stride ctor: source padded stride must be "
+        "representable as index_type.");
+  }
+#endif
----------------
eiytoq wrote:

Test for [LWG4545](https://cplusplus.github.io/LWG/issue4545).

https://github.com/llvm/llvm-project/pull/187873


More information about the libcxx-commits mailing list