1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9 
10 // <mdspan>
11 
12 // template<class OtherElementType, class OtherExtents,
13 //         class OtherLayoutPolicy, class OtherAccessor>
14 //  constexpr explicit(see below)
15 //    mdspan(const mdspan<OtherElementType, OtherExtents,
16 //                        OtherLayoutPolicy, OtherAccessor>& other);
17 //
18 // Constraints:
19 //   - is_constructible_v<mapping_type, const OtherLayoutPolicy::template mapping<OtherExtents>&> is true, and
20 //   - is_constructible_v<accessor_type, const OtherAccessor&> is true.
21 // Mandates:
22 //   - is_constructible_v<data_handle_type, const OtherAccessor::data_handle_type&> is
23 //   - is_constructible_v<extents_type, OtherExtents> is true.
24 //
25 // Preconditions:
26 //   - For each rank index r of extents_type, static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r) is true.
27 //   - [0, map_.required_span_size()) is an accessible range of ptr_ and acc_ for values of ptr_, map_, and acc_ after the invocation of this constructor.
28 //
29 // Effects:
30 //   - Direct-non-list-initializes ptr_ with other.ptr_,
31 //   - direct-non-list-initializes map_ with other.map_, and
32 //   - direct-non-list-initializes acc_ with other.acc_.
33 //
34 // Remarks: The expression inside explicit is equivalent to:
35 //   !is_convertible_v<const OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type>
36 //   || !is_convertible_v<const OtherAccessor&, accessor_type>
37 
38 #include <mdspan>
39 #include "CustomTestAccessors.h"
40 #include "../CustomTestLayouts.h"
41 
cant_construct_data_handle_type()42 void cant_construct_data_handle_type() {
43   int data;
44   std::mdspan<int, std::extents<int>, std::layout_right, convertible_accessor_but_not_handle<int>> m_nc(&data);
45   // expected-error-re@*:* {{{{.*}}no matching constructor for initialization of {{.*}} (aka 'not_const_convertible_handle<const int>')}}
46   // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: incompatible data_handle_type for mdspan construction}}
47   [[maybe_unused]] std::
48       mdspan<const int, std::extents<int>, std::layout_right, convertible_accessor_but_not_handle<const int>>
49           m_c(m_nc);
50 }
51 
mapping_constructible_despite_extents_compatibility()52 void mapping_constructible_despite_extents_compatibility() {
53   int data;
54   std::mdspan<int, std::extents<int>, always_convertible_layout> m(&data);
55   // expected-error-re@*:* {{static assertion failed {{.*}}mdspan: incompatible extents for mdspan construction}}
56   [[maybe_unused]] std::mdspan<int, std::extents<int, 5>, always_convertible_layout> m2(m);
57 }
58