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