[libcxx-commits] [libcxx] [libc++][mdspan] LWG3974: `mdspan::operator[]` should not copy `OtherIndexTypes` (PR #195814)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed May 6 23:06:24 PDT 2026
================
@@ -196,9 +196,27 @@ constexpr void test_layout_large() {
test_iteration(construct_mapping(Layout(), std::extents<int64_t, D, 4, 1, D>(3, 6)));
}
+struct Index {
+ Index() = default;
+ Index(const Index&) = delete;
+ constexpr operator int() const noexcept { return 0; }
+};
+
// mdspan::operator[] casts to index_type before calling mapping
// mapping requirements only require the index operator to mixed integer types not anything convertible to index_type
-constexpr void test_index_cast_happens() {}
+constexpr void test_index_cast_happens() {
+ int data[1]{};
+ std::mdspan m(data, std::extents<int, 1>{1});
+
+ // Index i;
+ std::array<Index, 1> a{};
+ std::span s(a);
+
+ // LWG3995: Issue with custom index conversion in <mdspan>
+ // TEST_IGNORE_NODISCARD m[i];
+ TEST_IGNORE_NODISCARD m[a];
+ TEST_IGNORE_NODISCARD m[s];
----------------
frederick-vs-ja wrote:
I think it's better to verify that `m[a]` and `m[s]` correctly refer to the desired element (`data[0]`). Perhaps it would make more sense to make the length of `data` greater than 1.
----
The CI failure was unrelated and should have been fixed by #195786.
https://github.com/llvm/llvm-project/pull/195814
More information about the libcxx-commits
mailing list