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