Files
clang-p2996/libcxx/test/std/containers/views/views.span/span.sub/last.verify.cpp
Mark de Wever 20b538fc64 [libc++] Addresses LWG3103.
LWG3103 Errors in taking subview of span should be ill-formed where possible

Note that the real work was already done before, including tests.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D143432
2023-03-04 13:24:44 +01:00

30 lines
963 B
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// <span>
// template<size_t Count>
// constexpr span<element_type, Count> last() const;
//
// Mandates: Count <= Extent is true.
#include <span>
#include <cstddef>
void f() {
int array[] = {1, 2, 3, 4};
std::span<const int, 4> sp(array);
// Count too large
[[maybe_unused]] auto s1 = sp.last<5>(); // expected-error@span:* {{span<T, N>::last<Count>(): Count out of range}}
// Count numeric_limits
[[maybe_unused]] auto s2 = sp.last<std::size_t(-1)>(); // expected-error@span:* {{span<T, N>::last<Count>(): Count out of range}}
}