[libcxx-commits] [libcxx] 4f82841 - [libc++][test] Merge test files for `mdspan::at` (#199330)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 23 06:57:33 PDT 2026
Author: A. Jiang
Date: 2026-05-23T21:57:28+08:00
New Revision: 4f828412ee1821a937913019df40bb1e6f22b3dd
URL: https://github.com/llvm/llvm-project/commit/4f828412ee1821a937913019df40bb1e6f22b3dd
DIFF: https://github.com/llvm/llvm-project/commit/4f828412ee1821a937913019df40bb1e6f22b3dd.diff
LOG: [libc++][test] Merge test files for `mdspan::at` (#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"`.
Added:
Modified:
libcxx/test/std/containers/views/mdspan/mdspan/at.pass.cpp
Removed:
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..3897ad52228fe 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 arr[1024];
+ // value out of range
+ {
+ std::mdspan mds(arr, std::extents<unsigned char, 5>());
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-130); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(256); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(1000); });
+ }
+ {
+ std::mdspan mds(arr, std::extents<signed char, 5>());
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-130); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(128); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(1000); });
+ }
+ {
+ std::mdspan mds(arr, std::dextents<unsigned char, 1>(5));
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-130); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(256); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(1000); });
+ }
+ {
+ std::mdspan mds(arr, std::dextents<signed char, 1>(5));
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-130); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(128); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(1000); });
+ }
+ {
+ std::mdspan mds(arr, std::dextents<int, 3>(5, 7, 9));
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1, -1, -1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1, 0, 0); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(0, -1, 0); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(0, 0, -1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5, 3, 3); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(3, 7, 3); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(3, 3, 9); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5, 7, 9); });
+ }
+ {
+ std::mdspan mds(arr, std::dextents<unsigned, 3>(5, 7, 9));
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1, -1, -1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(-1, 0, 0); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(0, -1, 0); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(0, 0, -1); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5, 3, 3); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(3, 7, 3); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(3, 3, 9); });
+ verify_exception_message([&] { TEST_IGNORE_NODISCARD mds.at(5, 7, 9); });
+ }
+ }
+#endif
}
int main(int, char**) {
More information about the libcxx-commits
mailing list