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 Offset, size_t Count = dynamic_extent>
14 //   constexpr span<element_type, see below> subspan() const;
15 //
16 // constexpr span<element_type, dynamic_extent> subspan(
17 //   size_type offset, size_type count = dynamic_extent) const;
18 //
19 //  Requires: offset <= size() &&
20 //            (count == dynamic_extent || count <= size() - offset)
21 
22 #include <span>
23 
24 #include <cstddef>
25 
26 #include "test_macros.h"
27 
28 constexpr int carr[] = {1, 2, 3, 4};
29 
main(int,char **)30 int main(int, char**) {
31   std::span<const int, 4> sp(carr);
32 
33   //  Offset too large templatized
34   {
35     [[maybe_unused]] auto s1 = sp.subspan<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset out of range in span::subspan()"}}
36   }
37 
38   //  Count too large templatized
39   {
40     [[maybe_unused]] auto s1 = sp.subspan<0, 5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}}
41   }
42 
43   //  Offset + Count too large templatized
44   {
45     [[maybe_unused]] auto s1 = sp.subspan<2, 3>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}}
46   }
47 
48   //  Offset + Count overflow templatized
49   {
50     [[maybe_unused]] auto s1 = sp.subspan<3, std::size_t(-2)>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset + count out of range in span::subspan()"}}, expected-error-re@span:* {{array is too large{{(.* elements)}}}}
51   }
52 
53   return 0;
54 }
55