Skip to content

Commit 5ad5043

Browse files
committed
Fix throwing assumptions and equality checks
1 parent ff03a50 commit 5ad5043

File tree

7 files changed

+32
-39
lines changed
  • stl/inc
  • tests/std/tests
    • P0896R4_ranges_alg_uninitialized_default_construct_n
    • P0896R4_ranges_alg_uninitialized_default_construct
    • P0896R4_ranges_alg_uninitialized_fill_n
    • P0896R4_ranges_alg_uninitialized_fill
    • P0896R4_ranges_alg_uninitialized_value_construct_n
    • P0896R4_ranges_alg_uninitialized_value_construct

7 files changed

+32
-39
lines changed

stl/inc/memory

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ namespace ranges {
731731
using _Ty = iter_value_t<_It>;
732732
_Algorithm_int_t<iter_difference_t<_It>> _Count = _Count_raw;
733733
if (_Count > 0) {
734-
auto _UFirst = _Get_unwrapped_n(_STD move(_First));
734+
auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count);
735735
if constexpr (_Use_memset_value_construct_v<_It>) {
736736
_Seek_wrapped(_First, _RANGES _Zero_range(_UFirst, _UFirst + _Count));
737737
} else if constexpr (is_nothrow_default_constructible_v<_Ty>) {

tests/std/tests/P0896R4_ranges_alg_uninitialized_default_construct/test.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct int_wrapper {
2525
destructions = 0;
2626
}
2727

28-
static constexpr int magic_throwing_val = 2;
28+
static constexpr int magic_throwing_val = 4;
2929
int val;
3030

3131
int_wrapper() {
@@ -60,8 +60,6 @@ void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy
6060
}
6161

6262
struct instantiator {
63-
static constexpr int expected[3] = {0, 0, 0};
64-
6563
template <ranges::forward_range Write>
6664
static void call() {
6765
using ranges::uninitialized_default_construct, ranges::equal, ranges::equal_to, ranges::iterator_t;
@@ -75,7 +73,6 @@ struct instantiator {
7573
assert(int_wrapper::constructions == 3);
7674
assert(int_wrapper::destructions == 0);
7775
assert(result == wrapped_input.end());
78-
assert(equal(wrapped_input, expected, equal_to{}, &int_wrapper::val));
7976
not_ranges_destroy(wrapped_input);
8077
assert(int_wrapper::constructions == 3);
8178
assert(int_wrapper::destructions == 3);
@@ -91,7 +88,6 @@ struct instantiator {
9188
assert(int_wrapper::constructions == 3);
9289
assert(int_wrapper::destructions == 0);
9390
assert(result == wrapped_input.end());
94-
assert(equal(wrapped_input, expected, equal_to{}, &int_wrapper::val));
9591
not_ranges_destroy(wrapped_input);
9692
assert(int_wrapper::constructions == 3);
9793
assert(int_wrapper::destructions == 3);
@@ -103,7 +99,7 @@ struct throwing_test {
10399
template <ranges::forward_range Write>
104100
static void call() {
105101
// Validate only range overload (one is plenty since they both use the same backend)
106-
holder<int_wrapper, 3> mem;
102+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
107103
Write wrapped_input{mem.as_span()};
108104

109105
int_wrapper::clear_counts();
@@ -115,8 +111,8 @@ struct throwing_test {
115111
} catch (...) {
116112
assert(false);
117113
}
118-
assert(int_wrapper::constructions == 2);
119-
assert(int_wrapper::destructions == 1);
114+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
115+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
120116
}
121117
};
122118

tests/std/tests/P0896R4_ranges_alg_uninitialized_default_construct_n/test.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct int_wrapper {
2222
destructions = 0;
2323
}
2424

25-
static constexpr int magic_throwing_val = 2;
25+
static constexpr int magic_throwing_val = 4;
2626
int val;
2727

2828
int_wrapper() {
@@ -57,8 +57,6 @@ void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy
5757
}
5858

5959
struct instantiator {
60-
static constexpr int expected[3] = {0, 0, 0};
61-
6260
template <ranges::forward_range Write>
6361
static void call() {
6462
using ranges::uninitialized_default_construct_n, ranges::equal, ranges::equal_to, ranges::iterator_t;
@@ -72,7 +70,6 @@ struct instantiator {
7270
assert(int_wrapper::constructions == 3);
7371
assert(int_wrapper::destructions == 0);
7472
assert(result == wrapped_input.end());
75-
assert(equal(wrapped_input, expected, equal_to{}, &int_wrapper::val));
7673
not_ranges_destroy(wrapped_input);
7774
assert(int_wrapper::constructions == 3);
7875
assert(int_wrapper::destructions == 3);
@@ -83,20 +80,20 @@ struct instantiator {
8380
struct throwing_test {
8481
template <ranges::forward_range Write>
8582
static void call() {
86-
holder<int_wrapper, 3> mem;
83+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
8784
Write wrapped_input{mem.as_span()};
8885

8986
int_wrapper::clear_counts();
9087
try {
91-
(void) ranges::uninitialized_default_construct_n(wrapped_input.begin(), 3);
88+
(void) ranges::uninitialized_default_construct_n(wrapped_input.begin(), int_wrapper::magic_throwing_val);
9289
assert(false);
9390
} catch (int i) {
9491
assert(i == int_wrapper::magic_throwing_val);
9592
} catch (...) {
9693
assert(false);
9794
}
98-
assert(int_wrapper::constructions == 2);
99-
assert(int_wrapper::destructions == 1);
95+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
96+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
10097
}
10198
};
10299

tests/std/tests/P0896R4_ranges_alg_uninitialized_fill/test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct int_wrapper {
2525
destructions = 0;
2626
}
2727

28-
static constexpr int magic_throwing_val = 2;
28+
static constexpr int magic_throwing_val = 4;
2929
int val;
3030

3131
int_wrapper() = default;
@@ -106,7 +106,7 @@ struct throwing_test {
106106
template <ranges::forward_range Write>
107107
static void call() {
108108
// Validate only range overload (one is plenty since they both use the same backend)
109-
holder<int_wrapper, 3> mem;
109+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
110110
Write wrapped_input{mem.as_span()};
111111

112112
int_wrapper::clear_counts();
@@ -118,8 +118,8 @@ struct throwing_test {
118118
} catch (...) {
119119
assert(false);
120120
}
121-
assert(int_wrapper::constructions == 2);
122-
assert(int_wrapper::destructions == 1);
121+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
122+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
123123
}
124124
};
125125

tests/std/tests/P0896R4_ranges_alg_uninitialized_fill_n/test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct int_wrapper {
2222
destructions = 0;
2323
}
2424

25-
static constexpr int magic_throwing_val = 2;
25+
static constexpr int magic_throwing_val = 4;
2626
int val;
2727

2828
int_wrapper() = default;
@@ -86,20 +86,20 @@ struct instantiator {
8686
struct throwing_test {
8787
template <ranges::forward_range Write>
8888
static void call() {
89-
holder<int_wrapper, 3> mem;
89+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
9090
Write wrapped_input{mem.as_span()};
9191

9292
int_wrapper::clear_counts();
9393
try {
94-
(void) ranges::uninitialized_fill_n(wrapped_input.begin(), 3, 42);
94+
(void) ranges::uninitialized_fill_n(wrapped_input.begin(), int_wrapper::magic_throwing_val, 42);
9595
assert(false);
9696
} catch (int i) {
9797
assert(i == int_wrapper::magic_throwing_val);
9898
} catch (...) {
9999
assert(false);
100100
}
101-
assert(int_wrapper::constructions == 2);
102-
assert(int_wrapper::destructions == 1);
101+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
102+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
103103
}
104104
};
105105

tests/std/tests/P0896R4_ranges_alg_uninitialized_value_construct/test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ struct int_wrapper {
2525
destructions = 0;
2626
}
2727

28-
static constexpr int magic_throwing_val = 2;
29-
int val;
28+
static constexpr int magic_throwing_val = 4;
29+
int val = 10;
3030

3131
int_wrapper() {
3232
if (++constructions == magic_throwing_val) {
@@ -60,7 +60,7 @@ void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy
6060
}
6161

6262
struct instantiator {
63-
static constexpr int expected[3] = {0, 0, 0};
63+
static constexpr int expected[3] = {10, 10, 10};
6464

6565
template <ranges::forward_range Write>
6666
static void call() {
@@ -103,7 +103,7 @@ struct throwing_test {
103103
template <ranges::forward_range Write>
104104
static void call() {
105105
// Validate only range overload (one is plenty since they both use the same backend)
106-
holder<int_wrapper, 3> mem;
106+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
107107
Write wrapped_input{mem.as_span()};
108108

109109
int_wrapper::clear_counts();
@@ -115,8 +115,8 @@ struct throwing_test {
115115
} catch (...) {
116116
assert(false);
117117
}
118-
assert(int_wrapper::constructions == 2);
119-
assert(int_wrapper::destructions == 1);
118+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
119+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
120120
}
121121
};
122122

tests/std/tests/P0896R4_ranges_alg_uninitialized_value_construct_n/test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ struct int_wrapper {
2222
destructions = 0;
2323
}
2424

25-
static constexpr int magic_throwing_val = 2;
26-
int val;
25+
static constexpr int magic_throwing_val = 4;
26+
int val = 10;
2727

2828
int_wrapper() {
2929
if (++constructions == magic_throwing_val) {
@@ -57,7 +57,7 @@ void not_ranges_destroy(R&& r) { // TRANSITION, ranges::destroy
5757
}
5858

5959
struct instantiator {
60-
static constexpr int expected[3] = {0, 0, 0};
60+
static constexpr int expected[3] = {10, 10, 10};
6161

6262
template <ranges::forward_range Write>
6363
static void call() {
@@ -83,20 +83,20 @@ struct instantiator {
8383
struct throwing_test {
8484
template <ranges::forward_range Write>
8585
static void call() {
86-
holder<int_wrapper, 3> mem;
86+
holder<int_wrapper, int_wrapper::magic_throwing_val> mem;
8787
Write wrapped_input{mem.as_span()};
8888

8989
int_wrapper::clear_counts();
9090
try {
91-
(void) ranges::uninitialized_value_construct_n(wrapped_input.begin(), 3);
91+
(void) ranges::uninitialized_value_construct_n(wrapped_input.begin(), int_wrapper::magic_throwing_val);
9292
assert(false);
9393
} catch (int i) {
9494
assert(i == int_wrapper::magic_throwing_val);
9595
} catch (...) {
9696
assert(false);
9797
}
98-
assert(int_wrapper::constructions == 2);
99-
assert(int_wrapper::destructions == 1);
98+
assert(int_wrapper::constructions == int_wrapper::magic_throwing_val);
99+
assert(int_wrapper::destructions == int_wrapper::magic_throwing_val - 1);
100100
}
101101
};
102102

0 commit comments

Comments
 (0)