Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------------ span ---------------------------------===// |
| 3 | // |
Chandler Carruth | 7c3769d | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===---------------------------------------------------------------------===// |
Stephan T. Lavavej | 439de45 | 2018-11-14 03:06:06 +0000 | [diff] [blame] | 9 | // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 10 | |
| 11 | // <span> |
| 12 | |
| 13 | // constexpr span(pointer first, pointer last); |
Stephan T. Lavavej | 439de45 | 2018-11-14 03:06:06 +0000 | [diff] [blame] | 14 | // Requires: [first, last) shall be a valid range. |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 15 | // If extent is not equal to dynamic_extent, then last - first shall be equal to extent. |
| 16 | // |
| 17 | |
| 18 | #include <span> |
| 19 | #include <cassert> |
| 20 | #include <string> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | |
| 24 | |
| 25 | int arr[] = {1,2,3}; |
| 26 | const int carr[] = {4,5,6}; |
| 27 | volatile int varr[] = {7,8,9}; |
| 28 | const volatile int cvarr[] = {1,3,5}; |
| 29 | |
JF Bastien | e15dd4e | 2019-02-04 20:31:13 +0000 | [diff] [blame^] | 30 | int main(int, char**) |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 31 | { |
| 32 | // We can't check that the size doesn't match - because that's a runtime property |
| 33 | // std::span<int, 2> s1(arr, arr + 3); |
| 34 | |
| 35 | // Type wrong |
| 36 | { |
| 37 | std::span<float> s1(arr, arr + 3); // expected-error {{no matching constructor for initialization of 'std::span<float>'}} |
| 38 | std::span<float, 3> s2(arr, arr + 3); // expected-error {{no matching constructor for initialization of 'std::span<float, 3>'}} |
| 39 | } |
Stephan T. Lavavej | 439de45 | 2018-11-14 03:06:06 +0000 | [diff] [blame] | 40 | |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 41 | // CV wrong (dynamically sized) |
| 42 | { |
| 43 | std::span< int> s1{ carr, carr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} |
| 44 | std::span< int> s2{ varr, varr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} |
| 45 | std::span< int> s3{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int>'}} |
| 46 | std::span<const int> s4{ varr, varr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} |
| 47 | std::span<const int> s5{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int>'}} |
| 48 | std::span< volatile int> s6{ carr, carr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} |
| 49 | std::span< volatile int> s7{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int>'}} |
| 50 | } |
| 51 | |
| 52 | // CV wrong (statically sized) |
| 53 | { |
| 54 | std::span< int,3> s1{ carr, carr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}} |
| 55 | std::span< int,3> s2{ varr, varr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}} |
| 56 | std::span< int,3> s3{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<int, 3>'}} |
| 57 | std::span<const int,3> s4{ varr, varr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}} |
| 58 | std::span<const int,3> s5{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<const int, 3>'}} |
| 59 | std::span< volatile int,3> s6{ carr, carr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}} |
| 60 | std::span< volatile int,3> s7{cvarr, cvarr + 3}; // expected-error {{no matching constructor for initialization of 'std::span<volatile int, 3>'}} |
| 61 | } |
JF Bastien | e15dd4e | 2019-02-04 20:31:13 +0000 | [diff] [blame^] | 62 | |
| 63 | return 0; |
Marshall Clow | fbd3e84 | 2018-07-24 03:01:02 +0000 | [diff] [blame] | 64 | } |