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

<ranges>: Diagnose the precondition added by LWG-3597 #3731

Merged
merged 7 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,12 @@ namespace ranges {

constexpr explicit iota_view(_Wi _Value_) noexcept(
is_nothrow_move_constructible_v<_Wi>&& is_nothrow_default_constructible_v<_Bo>) // strengthened
: _Value(_STD move(_Value_)) {}
: _Value(_STD move(_Value_)) {
if constexpr (totally_ordered_with<_Wi, _Bo>) {
_STL_ASSERT(_Value_ <= _Bound, "Per N4950 [range.iota.view]/6, the first argument must precede the "
"value-initialized bound when their types are totally ordered.");
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
}
}

constexpr explicit iota_view(type_identity_t<_Wi> _Value_, type_identity_t<_Bo> _Bound_) noexcept(
is_nothrow_move_constructible_v<_Wi>&& is_nothrow_move_constructible_v<_Bo>) // strengthened
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ tests\P0896R4_views_filter
tests\P0896R4_views_filter_death
tests\P0896R4_views_filter_iterator
tests\P0896R4_views_iota
tests\P0896R4_views_iota_death
tests\P0896R4_views_join
tests\P0896R4_views_lazy_split
tests\P0896R4_views_reverse
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P0896R4_views_iota_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 ..\strict_concepts_20_matrix.lst
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved
68 changes: 68 additions & 0 deletions tests/std/tests/P0896R4_views_iota_death/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#define _CONTAINER_DEBUG_LEVEL 1
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved

#include <cassert>
#include <cstddef>
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
#include <ranges>
#include <vector>

#include <test_death.hpp>
using namespace std;

template <class I>
void test_misordered_start_bound_int() {
ranges::iota_view{I{42}, I{1}};
}

template <class UI>
void test_misordered_start_bound_uint_value_init() {
ranges::iota_view<UI, UI>{UI{42}};
}

template <class T>
void test_misordered_start_bound_ptr() {
T arr[1]{};
ranges::iota_view{arr + 1, arr + 0};
}

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

#ifdef _DEBUG
struct S {};

exec.add_death_tests({
test_misordered_start_bound_int<signed char>, test_misordered_start_bound_int<unsigned char>,
test_misordered_start_bound_int<short>, test_misordered_start_bound_int<unsigned short>,
test_misordered_start_bound_int<int>, test_misordered_start_bound_int<unsigned int>,
test_misordered_start_bound_int<long>, test_misordered_start_bound_int<unsigned long>,
test_misordered_start_bound_int<long long>, test_misordered_start_bound_int<unsigned long long>,

test_misordered_start_bound_int<char>,
#if __cpp_char8_t
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved
test_misordered_start_bound_int<char8_t>,
#endif // __cpp_char8_t
test_misordered_start_bound_int<char16_t>, test_misordered_start_bound_int<char32_t>,
test_misordered_start_bound_int<wchar_t>,

test_misordered_start_bound_uint_value_init<unsigned char>,
test_misordered_start_bound_uint_value_init<unsigned short>,
test_misordered_start_bound_uint_value_init<unsigned int>,
test_misordered_start_bound_uint_value_init<unsigned long>,
test_misordered_start_bound_uint_value_init<unsigned long long>,
test_misordered_start_bound_uint_value_init<unsigned long long>,
#if __cpp_char8_t
test_misordered_start_bound_uint_value_init<char8_t>,
#endif // __cpp_char8_t
test_misordered_start_bound_uint_value_init<char16_t>,
test_misordered_start_bound_uint_value_init<char32_t>, test_misordered_start_bound_uint_value_init<wchar_t>,

test_misordered_start_bound_ptr<char>, test_misordered_start_bound_ptr<int>,
test_misordered_start_bound_ptr<S>,
});
#endif // _DEBUG

return exec.run(argc, argv);
}