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