Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libcxx/include/span
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ public:
# endif

_LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::front() on empty span");
static_assert(_Extent >= 1, "span<T, N>::front() on empty span");
return __data_[0];
}

_LIBCPP_HIDE_FROM_ABI constexpr reference back() const noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::back() on empty span");
static_assert(_Extent >= 1, "span<T, N>::back() on empty span");
return __data_[size() - 1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <span>
Expand All @@ -23,17 +24,13 @@
#include "check_assertion.h"

int main(int, char**) {
{
std::array<int, 3> array{0, 1, 2};
std::span<int> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.back(), "span<T>::back() on empty span");
}

{
std::array<int, 3> array{0, 1, 2};
std::span<int, 0> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.back(), "span<T, N>::back() on empty span");
}

return 0;
{
std::array<int, 3> array{0, 1, 2};
std::span<int> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.back(), "span<T>::back() on empty span");
}

// back() on a span with a static extent is caught statically and tested in front.verify.cpp

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <span>
Expand All @@ -23,17 +24,13 @@
#include "check_assertion.h"

int main(int, char**) {
{
std::array<int, 3> array{0, 1, 2};
std::span<int> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.front(), "span<T>::front() on empty span");
}

{
std::array<int, 3> array{0, 1, 2};
std::span<int, 0> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.front(), "span<T, N>::front() on empty span");
}

return 0;
{
std::array<int, 3> array{0, 1, 2};
std::span<int> const s(array.data(), 0);
TEST_LIBCPP_ASSERT_FAILURE(s.front(), "span<T>::front() on empty span");
}

// front() on a span with a static extent is caught statically and tested in front.verify.cpp

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// 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>
//
// constexpr reference back() const noexcept;

// Make sure that accessing a statically-sized span out-of-bounds triggers a
// compile-time error.

#include <array>
#include <span>

int main(int, char**) {
std::array<int, 3> array{0, 1, 2};
{
std::span<int, 0> const s(array.data(), 0);
s.back(); // expected-error@span:* {{span<T, N>::back() on empty span}}
}
{
std::span<int, 3> const s(array.data(), 3);
s.back(); // nothing
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// 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>
//
// constexpr reference front() const noexcept;

// Make sure that accessing a statically-sized span out-of-bounds triggers a
// compile-time error.

#include <array>
#include <span>

int main(int, char**) {
std::array<int, 3> array{0, 1, 2};
{
std::span<int, 0> const s(array.data(), 0);
s.front(); // expected-error@span:* {{span<T, N>::front() on empty span}}
}
{
std::span<int, 3> const s(array.data(), 3);
s.front(); // nothing
}

return 0;
}
Loading