From 2e9058ced9f154b972e0caac99bc20f284161250 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 11 Apr 2023 17:44:58 +0100 Subject: [PATCH] [libc++][NFC] Update precondition comments when testing subspan assertions --- .../views.span/span.sub/assert.subspan.pass.cpp | 14 +++++++++----- .../views/views.span/span.sub/subspan.verify.cpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libcxx/test/libcxx/containers/views/views.span/span.sub/assert.subspan.pass.cpp b/libcxx/test/libcxx/containers/views/views.span/span.sub/assert.subspan.pass.cpp index 10e54c1983ea9a..a66ca5402f0785 100644 --- a/libcxx/test/libcxx/containers/views/views.span/span.sub/assert.subspan.pass.cpp +++ b/libcxx/test/libcxx/containers/views/views.span/span.sub/assert.subspan.pass.cpp @@ -9,11 +9,15 @@ // // +// template +// constexpr span subspan() const; +// +// Requires: Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset) +// // constexpr span subspan( // size_type offset, size_type count = dynamic_extent) const; // -// Requires: (0 <= Offset && Offset <= size()) -// && (Count == dynamic_extent || Count >= 0 && Offset + Count <= size()) +// Requires: offset <= size() && (count == dynamic_extent || count <= size() - offset) // Make sure that creating a sub-span with an incorrect number of elements triggers an assertion. @@ -44,13 +48,13 @@ int main(int, char**) { std::array array{0, 1, 2}; std::span const s(array.data(), array.size()); TEST_LIBCPP_ASSERT_FAILURE(s.subspan(4), "span::subspan(offset, count): offset out of range"); - // s.subspan<4>() caught at compile-time (tested elsewhere) + // s.subspan<4>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp) TEST_LIBCPP_ASSERT_FAILURE(s.subspan(0, 4), "span::subspan(offset, count): count out of range"); - // s.subspan<0, 4>() caught at compile-time (tested elsewhere) + // s.subspan<0, 4>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp) TEST_LIBCPP_ASSERT_FAILURE(s.subspan(1, 3), "span::subspan(offset, count): offset + count out of range"); - // s.subspan<1, 3>() caught at compile-time (tested elsewhere) + // s.subspan<1, 3>() caught at compile-time (tested in libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp) } return 0; diff --git a/libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp b/libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp index e74674e800fffa..d6bc21197098a4 100644 --- a/libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp +++ b/libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp @@ -14,7 +14,7 @@ // // template -// constexpr span subspan() const; +// constexpr span subspan() const; // // Mandates: Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset) is true.