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 "test_macros.h"
25 
26 constexpr int carr[] = {1, 2, 3, 4};
27 
main(int,char **)28 int main(int, char**) {
29   std::span<const int, 4> sp(carr);
30 
31   //  Offset too large templatized
32   {
33     [[maybe_unused]] auto s1 = sp.subspan<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Offset out of range in span::subspan()"}}
34   }
35 
36   //  Count too large templatized
37   {
38     [[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()"}}
39   }
40 
41   //  Offset + Count too large templatized
42   {
43     [[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()"}}
44   }
45 
46   //  Offset + Count overflow templatized
47   {
48     [[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)}}}}
49   }
50 
51   return 0;
52 }
53