xref: /llvm-project/libcxx/test/libcxx/containers/views/mdspan/layout_left/assert.ctor.extents.pass.cpp (revision 74e70bae15b2e150d763f6b9035627b822891327)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // REQUIRES: has-unix-headers
10 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // UNSUPPORTED: libcpp-hardening-mode=none
12 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
13 
14 // <mdspan>
15 
16 // constexpr mapping(const extents_type& e) noexcept;
17 //
18 // Preconditions: The size of the multidimensional index space e is representable as a value of type index_type ([basic.fundamental]).
19 //
20 // Effects: Direct-non-list-initializes extents_ with e.
21 
22 #include <mdspan>
23 #include <cassert>
24 
25 #include "check_assertion.h"
26 
27 int main(int, char**) {
28   constexpr size_t D = std::dynamic_extent;
29 
30   // value out of range
31   {
32     // the extents are representable but the product is not, so we can't use it for layout_left
33     TEST_LIBCPP_ASSERT_FAILURE(
34         ([=] { std::layout_left::mapping<std::extents<signed char, D, 5>> m(std::extents<signed char, D, 5>(100)); }()),
35         "layout_left::mapping extents ctor: product of extents must be representable as index_type.");
36   }
37   return 0;
38 }
39