1 //===---------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===---------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <span>
11
12 // template <class It>
13 // constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
14 // If Extent is not equal to dynamic_extent, then count shall be equal to Extent.
15 //
16 // constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); // Since C++26
17
18 #include <span>
19 #include <cstddef>
20
21 #include "test_macros.h"
22
23 template <class T, std::size_t extent>
createImplicitSpan(T * ptr,std::size_t len)24 std::span<T, extent> createImplicitSpan(T* ptr, std::size_t len) {
25 return {ptr, len}; // expected-error {{chosen constructor is explicit in copy-initialization}}
26 }
27
test()28 void test() {
29 // explicit constructor necessary
30 int arr[] = {1, 2, 3};
31 createImplicitSpan<int, 1>(arr, 3);
32
33 // expected-error@+1 {{no matching constructor for initialization of 'std::span<int>'}}
34 std::span<int> sp = {0, 0};
35 // expected-error@+1 {{no matching constructor for initialization of 'std::span<int, 2>'}}
36 std::span<int, 2> sp2 = {0, 0};
37 #if TEST_STD_VER < 26
38 // expected-error@+1 {{no matching constructor for initialization of 'std::span<const int>'}}
39 std::span<const int> csp = {0, 0};
40 // expected-error@+1 {{no matching constructor for initialization of 'std::span<const int, 2>'}}
41 std::span<const int, 2> csp2 = {0, 0};
42 #endif
43 }
44