1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===---------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
11
12 // <span>
13
14 // template<class OtherElementType, ptrdiff_t OtherExtent>
15 // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
16 //
17 // Remarks: This constructor shall not participate in overload resolution unless:
18 // Extent == dynamic_extent || Extent == OtherExtent is true, and
19 // OtherElementType(*)[] is convertible to ElementType(*)[].
20
21
22 #include <span>
23 #include <cassert>
24 #include <string>
25
26 #include "test_macros.h"
27
checkCV()28 void checkCV ()
29 {
30 // std::span< int> sp;
31 std::span<const int> csp;
32 std::span< volatile int> vsp;
33 std::span<const volatile int> cvsp;
34
35 // std::span< int, 0> sp0;
36 std::span<const int, 0> csp0;
37 std::span< volatile int, 0> vsp0;
38 std::span<const volatile int, 0> cvsp0;
39
40 // Try to remove const and/or volatile (dynamic -> dynamic)
41 {
42 std::span< int> s1{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
43 std::span< int> s2{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
44 std::span< int> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
45
46 std::span<const int> s4{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
47 std::span<const int> s5{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
48
49 std::span< volatile int> s6{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
50 std::span< volatile int> s7{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
51 }
52
53 // Try to remove const and/or volatile (static -> static)
54 {
55 std::span< int, 0> s1{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
56 std::span< int, 0> s2{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
57 std::span< int, 0> s3{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
58
59 std::span<const int, 0> s4{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
60 std::span<const int, 0> s5{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
61
62 std::span< volatile int, 0> s6{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}
63 std::span< volatile int, 0> s7{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}
64 }
65
66 // Try to remove const and/or volatile (static -> dynamic)
67 {
68 std::span< int> s1{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
69 std::span< int> s2{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
70 std::span< int> s3{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
71
72 std::span<const int> s4{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
73 std::span<const int> s5{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
74
75 std::span< volatile int> s6{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
76 std::span< volatile int> s7{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
77 }
78
79 // Try to remove const and/or volatile (static -> static)
80 {
81 std::span< int, 0> s1{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
82 std::span< int, 0> s2{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
83 std::span< int, 0> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}}
84
85 std::span<const int, 0> s4{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
86 std::span<const int, 0> s5{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}}
87
88 std::span< volatile int, 0> s6{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}
89 std::span< volatile int, 0> s7{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}}
90 }
91 }
92
main()93 int main ()
94 {
95 std::span<int> sp;
96 std::span<int, 0> sp0;
97
98 std::span<float> s1{sp}; // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
99 std::span<float> s2{sp0}; // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
100 std::span<float, 0> s3{sp}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}}
101 std::span<float, 0> s4{sp0}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}}
102
103 checkCV();
104 }
105