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 Count>
14 //  constexpr span<element_type, Count> last() const;
15 //
16 // constexpr span<element_type, dynamic_extent> last(size_type count) const;
17 //
18 //  Requires: Count <= size().
19 
20 #include <span>
21 
22 #include "test_macros.h"
23 
24 constexpr int carr[] = {1, 2, 3, 4};
25 
main(int,char **)26 int main(int, char**) {
27   std::span<const int, 4> sp(carr);
28 
29   //  Count too large
30   {
31     [[maybe_unused]] auto s1 = sp.last<5>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}}
32   }
33 
34   //  Count numeric_limits
35   {
36     [[maybe_unused]] auto s1 = sp.last<std::size_t(-1)>(); // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Count out of range in span::last()"}}
37   }
38 
39   return 0;
40 }
41