1*a8cf78c7SLouis Dionne //===----------------------------------------------------------------------===//
2*a8cf78c7SLouis Dionne //
3*a8cf78c7SLouis Dionne // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*a8cf78c7SLouis Dionne // See https://llvm.org/LICENSE.txt for license information.
5*a8cf78c7SLouis Dionne // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*a8cf78c7SLouis Dionne //
7*a8cf78c7SLouis Dionne //===----------------------------------------------------------------------===//
8*a8cf78c7SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
9*a8cf78c7SLouis Dionne 
10*a8cf78c7SLouis Dionne // <span>
11*a8cf78c7SLouis Dionne 
12*a8cf78c7SLouis Dionne // template<size_t N>
13*a8cf78c7SLouis Dionne //     constexpr span(element_type (&arr)[N]) noexcept;
14*a8cf78c7SLouis Dionne // template<size_t N>
15*a8cf78c7SLouis Dionne //     constexpr span(array<value_type, N>& arr) noexcept;
16*a8cf78c7SLouis Dionne // template<size_t N>
17*a8cf78c7SLouis Dionne //     constexpr span(const array<value_type, N>& arr) noexcept;
18*a8cf78c7SLouis Dionne //
19*a8cf78c7SLouis Dionne // Remarks: These constructors shall not participate in overload resolution unless:
20*a8cf78c7SLouis Dionne //   — extent == dynamic_extent || N == extent is true, and
21*a8cf78c7SLouis Dionne //   — remove_pointer_t<decltype(data(arr))>(*)[] is convertible to ElementType(*)[].
22*a8cf78c7SLouis Dionne //
23*a8cf78c7SLouis Dionne 
24*a8cf78c7SLouis Dionne 
25*a8cf78c7SLouis Dionne #include <span>
26*a8cf78c7SLouis Dionne #include <cassert>
27*a8cf78c7SLouis Dionne #include <string>
28*a8cf78c7SLouis Dionne 
29*a8cf78c7SLouis Dionne #include "test_macros.h"
30*a8cf78c7SLouis Dionne 
31*a8cf78c7SLouis Dionne                int   arr[] = {1,2,3};
32*a8cf78c7SLouis Dionne const          int  carr[] = {4,5,6};
33*a8cf78c7SLouis Dionne       volatile int  varr[] = {7,8,9};
34*a8cf78c7SLouis Dionne const volatile int cvarr[] = {1,3,5};
35*a8cf78c7SLouis Dionne 
main(int,char **)36*a8cf78c7SLouis Dionne int main(int, char**)
37*a8cf78c7SLouis Dionne {
38*a8cf78c7SLouis Dionne //  Size wrong
39*a8cf78c7SLouis Dionne     {
40*a8cf78c7SLouis Dionne     std::span<int, 2>   s1(arr); // expected-error {{no matching constructor for initialization of 'std::span<int, 2>'}}
41*a8cf78c7SLouis Dionne     }
42*a8cf78c7SLouis Dionne 
43*a8cf78c7SLouis Dionne //  Type wrong
44*a8cf78c7SLouis Dionne     {
45*a8cf78c7SLouis Dionne     std::span<float>    s1(arr);   // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
46*a8cf78c7SLouis Dionne     std::span<float, 3> s2(arr);   // expected-error {{no matching constructor for initialization of 'std::span<float, 3>'}}
47*a8cf78c7SLouis Dionne     }
48*a8cf78c7SLouis Dionne 
49*a8cf78c7SLouis Dionne //  CV wrong (dynamically sized)
50*a8cf78c7SLouis Dionne     {
51*a8cf78c7SLouis Dionne     std::span<               int> s1{ carr};    // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
52*a8cf78c7SLouis Dionne     std::span<               int> s2{ varr};    // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
53*a8cf78c7SLouis Dionne     std::span<               int> s3{cvarr};    // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
54*a8cf78c7SLouis Dionne     std::span<const          int> s4{ varr};    // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
55*a8cf78c7SLouis Dionne     std::span<const          int> s5{cvarr};    // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
56*a8cf78c7SLouis Dionne     std::span<      volatile int> s6{ carr};    // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
57*a8cf78c7SLouis Dionne     std::span<      volatile int> s7{cvarr};    // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
58*a8cf78c7SLouis Dionne     }
59*a8cf78c7SLouis Dionne 
60*a8cf78c7SLouis Dionne //  CV wrong (statically sized)
61*a8cf78c7SLouis Dionne     {
62*a8cf78c7SLouis Dionne     std::span<               int,3> s1{ carr};  // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
63*a8cf78c7SLouis Dionne     std::span<               int,3> s2{ varr};  // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
64*a8cf78c7SLouis Dionne     std::span<               int,3> s3{cvarr};  // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
65*a8cf78c7SLouis Dionne     std::span<const          int,3> s4{ varr};  // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
66*a8cf78c7SLouis Dionne     std::span<const          int,3> s5{cvarr};  // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
67*a8cf78c7SLouis Dionne     std::span<      volatile int,3> s6{ carr};  // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
68*a8cf78c7SLouis Dionne     std::span<      volatile int,3> s7{cvarr};  // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
69*a8cf78c7SLouis Dionne     }
70*a8cf78c7SLouis Dionne 
71*a8cf78c7SLouis Dionne   return 0;
72*a8cf78c7SLouis Dionne }
73