[libcxx-commits] [libcxx] [libc++][test] Merge test files for `mdspan::at` (PR #199330)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 23 01:26:04 PDT 2026


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/199330

`libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp` caused build bot failures for
- sanitizer-aarch64-linux-bootstrap-asan
- sanitizer-aarch64-linux-bootstrap-hwasan
- sanitizer-aarch64-linux-bootstrap-msan

It's not yet clear why current mechanisms don't work for these builds. `TEST_HAS_NO_EXCEPTIONS` should have been working.

Also remove one unnecessary `static` and use `std::string_view(e.what()) == "mdspan"`.

>From cf13ba8b800f2cfe9e054ec0195ad46d0f2230fa Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 23 May 2026 16:20:45 +0800
Subject: [PATCH] [libc++][test] Merge test files for `mdspan::at`

`libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp`
caused build bot failures for
- sanitizer-aarch64-linux-bootstrap-asan
- sanitizer-aarch64-linux-bootstrap-hwasan
- sanitizer-aarch64-linux-bootstrap-msan

It's not yet clear why current mechanisms don't work for these builds.
`TEST_HAS_NO_EXCEPTIONS` should have been working.

Also remove one unnecessary `static` and use
`std::string_view(e.what()) == "mdspan"`.
---
 .../views/mdspan/mdspan/assert.at.pass.cpp    | 112 ------------------
 .../views/mdspan/mdspan/at.pass.cpp           |  74 +++++++++++-
 2 files changed, 73 insertions(+), 113 deletions(-)
 delete mode 100644 libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp

diff --git a/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp b/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp
deleted file mode 100644
index 53bc50addae1b..0000000000000
--- a/libcxx/test/libcxx/containers/views/mdspan/mdspan/assert.at.pass.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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: has-unix-headers
-// REQUIRES: std-at-least-c++26
-// UNSUPPORTED: no-exceptions
-
-// <mdspan>
-
-// template<class... OtherIndexTypes>
-//   constexpr reference at(OtherIndexTypes... indices) const;
-//
-// Constraints:
-//   - (is_convertible_v<OtherIndexTypes, index_type> && ...) is true,
-//   - (is_nothrow_constructible_v<index_type, OtherIndexTypes> && ...) is true, and
-//   - sizeof...(OtherIndexTypes) == rank() is true.
-//
-// template<class OtherIndexType>
-//   constexpr reference at(span<OtherIndexType, rank()> indices) const;
-//
-// template<class OtherIndexType>
-//   constexpr reference at(const array<OtherIndexType, rank()>& indices) const;
-//
-// Constraints:
-//   - is_convertible_v<const OtherIndexType&, index_type> is true, and
-//   - is_nothrow_constructible_v<index_type, const OtherIndexType&> is true.
-//
-// Throws:
-//   - std::out_of_range if extents_type::index-cast(indices) is not a multidimensional index in extents_.
-
-#include <mdspan>
-#include <string_view>
-#include <cassert>
-
-#include "test_macros.h"
-
-template <typename F>
-void test(F&& f) {
-  try {
-    f();
-    assert(false && "Unexpected");
-  } catch (const std::out_of_range& e) {
-    LIBCPP_ASSERT(std::string_view(e.what()).contains("mdspan"));
-  } catch (...) {
-    assert(false && "Unexpected");
-  }
-}
-
-int main() {
-  float data[1024];
-  // value out of range
-  {
-    std::mdspan m(data, std::extents<unsigned char, 5>());
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-130); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(256); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(1000); });
-  }
-  {
-    std::mdspan m(data, std::extents<signed char, 5>());
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-130); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(128); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(1000); });
-  }
-  {
-    std::mdspan m(data, std::dextents<unsigned char, 1>(5));
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-130); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(256); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(1000); });
-  }
-  {
-    std::mdspan m(data, std::dextents<signed char, 1>(5));
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-130); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(128); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(1000); });
-  }
-  {
-    std::mdspan m(data, std::dextents<int, 3>(5, 7, 9));
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1, -1, -1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1, 0, 0); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(0, -1, 0); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(0, 0, -1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5, 3, 3); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(3, 7, 3); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(3, 3, 9); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5, 7, 9); });
-  }
-  {
-    std::mdspan m(data, std::dextents<unsigned, 3>(5, 7, 9));
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1, -1, -1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(-1, 0, 0); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(0, -1, 0); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(0, 0, -1); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5, 3, 3); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(3, 7, 3); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(3, 3, 9); });
-    test([&] { TEST_IGNORE_NODISCARD m.at(5, 7, 9); });
-  }
-  return 0;
-}
diff --git a/libcxx/test/std/containers/views/mdspan/mdspan/at.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan/at.pass.cpp
index d52923cd4b133..ee029b4af8bc1 100644
--- a/libcxx/test/std/containers/views/mdspan/mdspan/at.pass.cpp
+++ b/libcxx/test/std/containers/views/mdspan/mdspan/at.pass.cpp
@@ -35,6 +35,7 @@
 #include <cassert>
 #include <mdspan>
 #include <span>
+#include <string_view>
 #include <vector>
 
 #include "assert_macros.h"
@@ -297,7 +298,7 @@ constexpr bool test_cast() {
   return true;
 }
 
-static void test_throws() {
+void test_throws() {
   std::array<int, 100> data{};
   std::mdspan m(data.data(), 10, 10);
 
@@ -312,6 +313,77 @@ static void test_throws() {
 
   [[maybe_unused]] std::array bad_col{0, 10};
   TEST_THROWS_TYPE(std::out_of_range, m.at(std::span{bad_col}));
+
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  auto verify_exception_message = [](auto&& f) {
+    try {
+      f();
+      assert(false && "Unexpected");
+    } catch (const std::out_of_range& e [[maybe_unused]]) {
+      LIBCPP_ASSERT(std::string_view(e.what()) == "mdspan");
+    } catch (...) {
+      assert(false && "Unexpected");
+    }
+  };
+  {
+    float data[1024];
+    // value out of range
+    {
+      std::mdspan m(data, std::extents<unsigned char, 5>());
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-130); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(256); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(1000); });
+    }
+    {
+      std::mdspan m(data, std::extents<signed char, 5>());
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-130); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(128); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(1000); });
+    }
+    {
+      std::mdspan m(data, std::dextents<unsigned char, 1>(5));
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-130); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(256); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(1000); });
+    }
+    {
+      std::mdspan m(data, std::dextents<signed char, 1>(5));
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-130); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(128); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(1000); });
+    }
+    {
+      std::mdspan m(data, std::dextents<int, 3>(5, 7, 9));
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1, -1, -1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1, 0, 0); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(0, -1, 0); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(0, 0, -1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5, 3, 3); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(3, 7, 3); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(3, 3, 9); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5, 7, 9); });
+    }
+    {
+      std::mdspan m(data, std::dextents<unsigned, 3>(5, 7, 9));
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1, -1, -1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(-1, 0, 0); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(0, -1, 0); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(0, 0, -1); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5, 3, 3); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(3, 7, 3); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(3, 3, 9); });
+      verify_exception_message([&] { TEST_IGNORE_NODISCARD m.at(5, 7, 9); });
+    }
+  }
+#endif
 }
 
 int main(int, char**) {



More information about the libcxx-commits mailing list