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<class OtherElementType, size_t OtherExtent> 13 // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept; 14 // 15 // Remarks: This constructor shall not participate in overload resolution unless: 16 // Extent == dynamic_extent || Extent == OtherExtent is true, and 17 // OtherElementType(*)[] is convertible to ElementType(*)[]. 18 19 20 #include <span> 21 #include <cassert> 22 #include <string> 23 24 #include "test_macros.h" 25 26 template<class T, size_t extent, size_t otherExtent> 27 std::span<T, extent> createImplicitSpan(std::span<T, otherExtent> s) { 28 return {s}; // expected-error {{chosen constructor is explicit in copy-initialization}} 29 } 30 31 void checkCV () 32 { 33 // std::span< int> sp; 34 std::span<const int> csp; 35 std::span< volatile int> vsp; 36 std::span<const volatile int> cvsp; 37 38 // std::span< int, 0> sp0; 39 std::span<const int, 0> csp0; 40 std::span< volatile int, 0> vsp0; 41 std::span<const volatile int, 0> cvsp0; 42 43 // Try to remove const and/or volatile (dynamic -> dynamic) 44 { 45 std::span< int> s1{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 46 std::span< int> s2{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 47 std::span< int> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 48 49 std::span<const int> s4{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} 50 std::span<const int> s5{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} 51 52 std::span< volatile int> s6{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} 53 std::span< volatile int> s7{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} 54 } 55 56 // Try to remove const and/or volatile (static -> static) 57 { 58 std::span< int, 0> s1{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 59 std::span< int, 0> s2{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 60 std::span< int, 0> s3{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 61 62 std::span<const int, 0> s4{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}} 63 std::span<const int, 0> s5{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}} 64 65 std::span< volatile int, 0> s6{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}} 66 std::span< volatile int, 0> s7{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}} 67 } 68 69 // Try to remove const and/or volatile (static -> dynamic) 70 { 71 std::span< int> s1{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 72 std::span< int> s2{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 73 std::span< int> s3{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} 74 75 std::span<const int> s4{ vsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} 76 std::span<const int> s5{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} 77 78 std::span< volatile int> s6{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} 79 std::span< volatile int> s7{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} 80 } 81 82 // Try to remove const and/or volatile (static -> static) 83 { 84 std::span< int, 0> s1{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 85 std::span< int, 0> s2{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 86 std::span< int, 0> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<int, 0>'}} 87 88 std::span<const int, 0> s4{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}} 89 std::span<const int, 0> s5{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 0>'}} 90 91 std::span< volatile int, 0> s6{ csp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}} 92 std::span< volatile int, 0> s7{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 0>'}} 93 } 94 } 95 96 int main(int, char**) 97 { 98 std::span<int> sp; 99 std::span<int, 0> sp0; 100 101 std::span<float> s1{sp}; // expected-error {{no matching constructor for initialization of 'std::span<float>'}} 102 std::span<float> s2{sp0}; // expected-error {{no matching constructor for initialization of 'std::span<float>'}} 103 std::span<float, 0> s3{sp}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}} 104 std::span<float, 0> s4{sp0}; // expected-error {{no matching constructor for initialization of 'std::span<float, 0>'}} 105 106 checkCV(); 107 108 // explicit constructor necessary 109 { 110 createImplicitSpan<int, 1>(sp); 111 } 112 113 return 0; 114 } 115