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 // constexpr span(pointer ptr, index_type count);
     15 // Requires: [ptr, ptr + count) shall be a valid range.
     16 //  If extent is not equal to dynamic_extent, then count shall be equal to extent.
     17 //
     18 
     19 #include <span>
     20 #include <cassert>
     21 #include <string>
     22 
     23 #include "test_macros.h"
     24 
     25 
     26                int   arr[] = {1,2,3};
     27 const          int  carr[] = {4,5,6};
     28       volatile int  varr[] = {7,8,9};
     29 const volatile int cvarr[] = {1,3,5};
     30 
     31 int main ()
     32 {
     33 //  We can't check that the size doesn't match - because that's a runtime property
     34 //  std::span<int, 2>   s1(arr, 3);
     35 
     36 //  Type wrong
     37     {
     38     std::span<float>    s1(arr, 3);   // expected-error {{no matching constructor for initialization of 'std::span<float>'}}
     39     std::span<float, 3> s2(arr, 3);   // expected-error {{no matching constructor for initialization of 'std::span<float, 3>'}}
     40     }
     41 
     42 //  CV wrong (dynamically sized)
     43     {
     44     std::span<               int> s1{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
     45     std::span<               int> s2{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
     46     std::span<               int> s3{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}}
     47     std::span<const          int> s4{ varr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
     48     std::span<const          int> s5{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}}
     49     std::span<      volatile int> s6{ carr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
     50     std::span<      volatile int> s7{cvarr, 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}}
     51     }
     52 
     53 //  CV wrong (statically sized)
     54     {
     55     std::span<               int,3> s1{ carr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
     56     std::span<               int,3> s2{ varr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
     57     std::span<               int,3> s3{cvarr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}}
     58     std::span<const          int,3> s4{ varr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
     59     std::span<const          int,3> s5{cvarr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}}
     60     std::span<      volatile int,3> s6{ carr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
     61     std::span<      volatile int,3> s7{cvarr, 3};   // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}}
     62     }
     63 }
     64