Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the slide_view constructor precondition added by LWG-3711 #2949

Merged
merged 5 commits into from
Sep 13, 2022
Merged
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
6 changes: 5 additions & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -6168,7 +6168,11 @@ namespace ranges {
public:
constexpr explicit slide_view(_Vw _Range_, const range_difference_t<_Vw> _Count_) noexcept(
is_nothrow_move_constructible_v<_Vw>) /* strengthened */
: _Range(_STD move(_Range_)), _Count{_Count_} {}
: _Range(_STD move(_Range_)), _Count{_Count_} {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_Count > 0, "The window size must be positive (N4917 [range.slide.view]/1)");
#endif // _CONTAINER_DEBUG_LEVEL > 0
}

// clang-format off
_NODISCARD constexpr auto begin() requires (!(_Simple_view<_Vw> && _Slide_caches_nothing<const _Vw>) ) {
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ tests\P2441R2_views_join_with
tests\P2442R1_views_chunk
tests\P2442R1_views_chunk_death
tests\P2442R1_views_slide
tests\P2442R1_views_slide_death
tests\P2443R1_views_chunk_by
tests\P2443R1_views_chunk_by_death
tests\P2445R1_forward_like
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2442R1_views_slide_death/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_latest_matrix.lst
32 changes: 32 additions & 0 deletions tests/std/tests/P2442R1_views_slide_death/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _CONTAINER_DEBUG_LEVEL 1

#include <ranges>

#include <test_death.hpp>

using namespace std;
using ranges::slide_view;

static constexpr int some_ints[] = {0, 1, 2, 3};

void test_view_negative_window_size() {
slide_view(some_ints, -1); // window size must be positive
}

void test_view_zero_window_size() {
slide_view(some_ints, 0); // window size must be positive
}

int main(int argc, char* argv[]) {
std_testing::death_test_executive exec;

exec.add_death_tests({
test_view_negative_window_size,
test_view_zero_window_size,
});

return exec.run(argc, argv);
}