зеркало из https://github.com/microsoft/STL.git
`<ranges>`: Check and test preconditions for `take_view` and `drop_view`'s constructors (#4551)
This commit is contained in:
Родитель
834626585c
Коммит
f5bccb8b4e
|
@ -2947,7 +2947,11 @@ namespace ranges {
|
|||
|
||||
constexpr explicit take_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, "Number of elements to take must be non-negative (N4971 [range.take.view]/1)");
|
||||
#endif // _CONTAINER_DEBUG_LEVEL > 0
|
||||
}
|
||||
|
||||
_NODISCARD constexpr _Vw base() const& noexcept(is_nothrow_copy_constructible_v<_Vw>) /* strengthened */
|
||||
requires copy_constructible<_Vw>
|
||||
|
@ -3365,7 +3369,7 @@ namespace ranges {
|
|||
is_nothrow_move_constructible_v<_Vw>) // strengthened
|
||||
: _Range(_STD move(_Range_)), _Count{_Count_} {
|
||||
#if _CONTAINER_DEBUG_LEVEL > 0
|
||||
_STL_VERIFY(_Count_ >= 0, "Number of elements to drop must be non-negative (N4950 [range.drop.view]/1");
|
||||
_STL_VERIFY(_Count_ >= 0, "Number of elements to drop must be non-negative (N4971 [range.drop.view]/1)");
|
||||
#endif // _CONTAINER_DEBUG_LEVEL > 0
|
||||
}
|
||||
|
||||
|
|
|
@ -480,6 +480,7 @@ tests\P0896R4_views_common
|
|||
tests\P0896R4_views_counted
|
||||
tests\P0896R4_views_counted_death
|
||||
tests\P0896R4_views_drop
|
||||
tests\P0896R4_views_drop_death
|
||||
tests\P0896R4_views_drop_while
|
||||
tests\P0896R4_views_drop_while_death
|
||||
tests\P0896R4_views_elements
|
||||
|
@ -495,6 +496,7 @@ tests\P0896R4_views_reverse
|
|||
tests\P0896R4_views_single
|
||||
tests\P0896R4_views_split
|
||||
tests\P0896R4_views_take
|
||||
tests\P0896R4_views_take_death
|
||||
tests\P0896R4_views_take_while
|
||||
tests\P0896R4_views_take_while_death
|
||||
tests\P0896R4_views_transform
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
RUNALL_INCLUDE ..\usual_20_matrix.lst
|
|
@ -0,0 +1,27 @@
|
|||
// 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;
|
||||
|
||||
constexpr int some_ints[] = {0, 1, 2, 3};
|
||||
|
||||
void test_constructor_negative_size() {
|
||||
(void) views::drop(some_ints, -3); // Number of elements to drop must be non-negative
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std_testing::death_test_executive exec;
|
||||
|
||||
#ifdef _DEBUG
|
||||
exec.add_death_tests({
|
||||
test_constructor_negative_size,
|
||||
});
|
||||
#endif // _DEBUG
|
||||
|
||||
return exec.run(argc, argv);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
RUNALL_INCLUDE ..\usual_20_matrix.lst
|
|
@ -0,0 +1,27 @@
|
|||
// 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;
|
||||
|
||||
constexpr int some_ints[] = {0, 1, 2, 3};
|
||||
|
||||
void test_constructor_negative_size() {
|
||||
(void) views::take(some_ints, -3); // Number of elements to take must be non-negative
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std_testing::death_test_executive exec;
|
||||
|
||||
#ifdef _DEBUG
|
||||
exec.add_death_tests({
|
||||
test_constructor_negative_size,
|
||||
});
|
||||
#endif // _DEBUG
|
||||
|
||||
return exec.run(argc, argv);
|
||||
}
|
Загрузка…
Ссылка в новой задаче