blob: 9c15ea58c9529071c563521013b8dfc248f800c2 [file] [log] [blame]
Marshall Clowfbd3e842018-07-24 03:01:02 +00001// -*- C++ -*-
2//===------------------------------ span ---------------------------------===//
3//
Chandler Carruth7c3769d2019-01-19 10:56:40 +00004// 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 Clowfbd3e842018-07-24 03:01:02 +00007//
8//===---------------------------------------------------------------------===//
Stephan T. Lavavej439de452018-11-14 03:06:06 +00009// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
Marshall Clowfbd3e842018-07-24 03:01:02 +000010
11// <span>
12
13// constexpr span(pointer first, pointer last);
Stephan T. Lavavej439de452018-11-14 03:06:06 +000014// Requires: [first, last) shall be a valid range.
Marshall Clowfbd3e842018-07-24 03:01:02 +000015// 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};
26const int carr[] = {4,5,6};
27 volatile int varr[] = {7,8,9};
28const volatile int cvarr[] = {1,3,5};
29
JF Bastiene15dd4e2019-02-04 20:31:13 +000030int main(int, char**)
Marshall Clowfbd3e842018-07-24 03:01:02 +000031{
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. Lavavej439de452018-11-14 03:06:06 +000040
Marshall Clowfbd3e842018-07-24 03:01:02 +000041// 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 Bastiene15dd4e2019-02-04 20:31:13 +000062
63 return 0;
Marshall Clowfbd3e842018-07-24 03:01:02 +000064}