Skip to content

Commit 5f54df6

Browse files
committed
Address ldionne's comments
1 parent 8e45b59 commit 5f54df6

16 files changed

+101
-127
lines changed

libcxx/test/std/containers/sequences/vector.bool/append_range.pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vector>
1616

1717
#include "../insert_range_sequence_containers.h"
18+
#include "test_allocator.h"
1819
#include "test_macros.h"
1920

2021
// Tested cases:
@@ -56,6 +57,15 @@ constexpr bool test() {
5657
v.append_range(in);
5758
assert(std::ranges::equal(v, std::vector<bool>{0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1}));
5859
}
60+
61+
{ // Ensure that appending an empty range has no effect
62+
std::vector<bool, limited_allocator<bool, 10> > v;
63+
v.resize(v.max_size(), true);
64+
std::vector<bool> a;
65+
v.append_range(a);
66+
for (std::size_t i = 0; i < v.size(); ++i)
67+
assert(v[i] == true);
68+
}
5969
}
6070

6171
return true;

libcxx/test/std/containers/sequences/vector.bool/append_range_exceptions.pass.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
// constexpr void append_range(R&& rg); // C++23
1717

1818
#include <cassert>
19+
#include <stdexcept>
1920
#include <vector>
2021

2122
#include "../insert_range_sequence_containers.h"
2223
#include "test_allocator.h"
2324

24-
void test() {
25+
int main(int, char**) {
2526
// Note: `test_append_range_exception_safety_throwing_copy` doesn't apply because copying booleans cannot throw.
2627
test_append_range_exception_safety_throwing_allocator<std::vector, bool>();
2728

2829
{
29-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
30-
Vec v(Vec().max_size() - 2, true);
30+
std::vector<bool, limited_allocator<bool, 10> > v;
31+
v.resize(v.max_size() - 2, true);
3132
bool a[] = {false, true, false};
3233
try {
3334
v.append_range(a);
@@ -39,21 +40,17 @@ void test() {
3940
}
4041
}
4142
{
42-
std::vector<bool, limited_allocator<bool, 10> > v(10, true);
43-
bool a[10 * 65536] = {};
43+
std::vector<bool, limited_allocator<bool, 10> > v(5, true);
44+
bool a[v.max_size()] = {}; // A large enough array to trigger a length_error when appended
4445
try {
4546
v.append_range(a);
4647
assert(false);
47-
} catch (...) {
48-
assert(v.size() == 10);
48+
} catch (const std::length_error&) {
49+
assert(v.size() == 5);
4950
for (std::size_t i = 0; i != v.size(); ++i)
5051
assert(v[i] == true);
5152
}
5253
}
53-
}
54-
55-
int main(int, char**) {
56-
test();
5754

5855
return 0;
5956
}

libcxx/test/std/containers/sequences/vector.bool/emplace_back_exceptions.pass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
// reference emplace_back(Args&&... args); // reference in C++17
1717

1818
#include <cassert>
19+
#include <stdexcept>
1920
#include <vector>
2021

2122
#include "test_allocator.h"
2223

2324
int main(int, char**) {
24-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
25-
Vec v(Vec().max_size(), true);
25+
std::vector<bool, limited_allocator<bool, 10> > v;
26+
v.resize(v.max_size(), true);
2627
try {
2728
v.emplace_back(true);
2829
assert(false);
29-
} catch (...) {
30+
} catch (const std::length_error&) {
3031
assert(v.size() == v.max_size());
3132
for (std::size_t i = 0; i != v.size(); ++i)
3233
assert(v[i] == true);

libcxx/test/std/containers/sequences/vector.bool/emplace_exceptions.pass.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,48 @@
1515
// template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
1616

1717
#include <cassert>
18+
#include <stdexcept>
1819
#include <vector>
1920

2021
#include "test_allocator.h"
2122

22-
void test() {
23+
int main(int, char**) {
2324
{
24-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
25-
Vec v(Vec().max_size(), true);
25+
std::vector<bool, limited_allocator<bool, 10> > v;
26+
v.resize(v.max_size(), true);
2627
try {
2728
v.emplace(v.begin(), true);
2829
assert(false);
29-
} catch (...) {
30+
} catch (const std::length_error&) {
3031
assert(v.size() == v.max_size());
3132
for (std::size_t i = 0; i != v.size(); ++i)
3233
assert(v[i] == true);
3334
}
3435
}
3536
{
36-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
37-
Vec v(Vec().max_size(), true);
37+
std::vector<bool, limited_allocator<bool, 10> > v;
38+
v.resize(v.max_size(), true);
3839
try {
3940
v.emplace(v.end(), true);
4041
assert(false);
41-
} catch (...) {
42+
} catch (const std::length_error&) {
4243
assert(v.size() == v.max_size());
4344
for (std::size_t i = 0; i != v.size(); ++i)
4445
assert(v[i] == true);
4546
}
4647
}
4748
{
48-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
49-
Vec v(Vec().max_size(), true);
49+
std::vector<bool, limited_allocator<bool, 10> > v;
50+
v.resize(v.max_size(), true);
5051
try {
5152
v.emplace(v.begin() + v.size() / 2, true);
5253
assert(false);
53-
} catch (...) {
54+
} catch (const std::length_error&) {
5455
assert(v.size() == v.max_size());
5556
for (std::size_t i = 0; i != v.size(); ++i)
5657
assert(v[i] == true);
5758
}
5859
}
59-
}
60-
61-
int main(int, char**) {
62-
test();
6360

6461
return 0;
6562
}

libcxx/test/std/containers/sequences/vector.bool/insert_exceptions.pass.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,91 +18,88 @@
1818
// iterator insert(const_iterator position, Iter first, Iter last);
1919

2020
#include <cassert>
21+
#include <stdexcept>
2122
#include <vector>
2223

2324
#include "test_allocator.h"
2425
#include "test_macros.h"
2526

26-
void test() {
27+
int main(int, char**) {
2728
{
28-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
29-
Vec v(Vec().max_size(), true);
29+
std::vector<bool, limited_allocator<bool, 10> > v;
30+
v.resize(v.max_size(), true);
3031
try {
3132
v.insert(v.begin(), false);
3233
assert(false);
33-
} catch (...) {
34+
} catch (const std::length_error&) {
3435
assert(v.size() == v.max_size());
3536
for (std::size_t i = 0; i != v.size(); ++i)
3637
assert(v[i] == true);
3738
}
3839
}
3940
{
40-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
41-
Vec v(Vec().max_size(), false);
41+
std::vector<bool, limited_allocator<bool, 10> > v;
42+
v.resize(v.max_size(), false);
4243
try {
4344
v.insert(v.end(), 0);
4445
assert(false);
45-
} catch (...) {
46+
} catch (const std::length_error&) {
4647
assert(v.size() == v.max_size());
4748
for (std::size_t i = 0; i != v.size(); ++i)
4849
assert(v[i] == false);
4950
}
5051
}
5152
{
52-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
53-
Vec v(Vec().max_size(), true);
53+
std::vector<bool, limited_allocator<bool, 10> > v;
54+
v.resize(v.max_size(), true);
5455
try {
5556
v.insert(v.begin() + v.size() / 2, false);
5657
assert(false);
57-
} catch (...) {
58+
} catch (const std::length_error&) {
5859
assert(v.size() == v.max_size());
5960
for (std::size_t i = 0; i != v.size(); ++i)
6061
assert(v[i] == true);
6162
}
6263
}
6364
{
64-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
65-
Vec v(Vec().max_size(), true);
65+
std::vector<bool, limited_allocator<bool, 10> > v;
66+
v.resize(v.max_size(), true);
6667
try {
6768
v.insert(v.begin(), 1, false);
6869
assert(false);
69-
} catch (...) {
70+
} catch (const std::length_error&) {
7071
assert(v.size() == v.max_size());
7172
for (std::size_t i = 0; i != v.size(); ++i)
7273
assert(v[i] == true);
7374
}
7475
}
7576
{
76-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
77-
Vec v(Vec().max_size() - 2, true);
77+
std::vector<bool, limited_allocator<bool, 10> > v;
78+
v.resize(v.max_size() - 2, true);
7879
bool a[] = {true, false, true};
7980
try {
8081
v.insert(v.begin() + v.size() / 2, std::begin(a), std::end(a));
8182
assert(false);
82-
} catch (...) {
83+
} catch (const std::length_error&) {
8384
assert(v.size() == v.max_size() - 2);
8485
for (std::size_t i = 0; i != v.size(); ++i)
8586
assert(v[i] == true);
8687
}
8788
}
8889
#if TEST_STD_VER >= 11
8990
{
90-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
91-
Vec v(Vec().max_size() - 2, true);
91+
std::vector<bool, limited_allocator<bool, 10> > v;
92+
v.resize(v.max_size() - 2, true);
9293
try {
9394
v.insert(v.begin(), {true, false, true});
9495
assert(false);
95-
} catch (...) {
96+
} catch (const std::length_error&) {
9697
assert(v.size() == v.max_size() - 2);
9798
for (std::size_t i = 0; i != v.size(); ++i)
9899
assert(v[i] == true);
99100
}
100101
}
101102
#endif
102-
}
103-
104-
int main(int, char**) {
105-
test();
106103

107104
return 0;
108105
}

libcxx/test/std/containers/sequences/vector.bool/insert_range_exceptions.pass.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
// constexpr iterator insert_range(const_iterator position, R&& rg); // C++23
1717

1818
#include <cassert>
19+
#include <stdexcept>
1920
#include <vector>
2021

2122
#include "../insert_range_sequence_containers.h"
2223
#include "test_allocator.h"
2324

24-
void test() {
25+
int main(int, char**) {
2526
// Note: `test_insert_range_exception_safety_throwing_copy` doesn't apply because copying booleans cannot throw.
2627
test_insert_range_exception_safety_throwing_allocator<std::vector, bool>();
2728

2829
{
29-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
30-
Vec v(Vec().max_size() - 2, true);
30+
std::vector<bool, limited_allocator<bool, 10> > v;
31+
v.resize(v.max_size() - 2, true);
3132
bool a[] = {true, false, true};
3233
try {
3334
v.insert_range(v.end(), a);
@@ -39,8 +40,8 @@ void test() {
3940
}
4041
}
4142
{
42-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
43-
Vec v(Vec().max_size() - 2, false);
43+
std::vector<bool, limited_allocator<bool, 10> > v;
44+
v.resize(v.max_size() - 2, false);
4445
bool a[] = {true, false, true};
4546
try {
4647
v.insert_range(v.begin(), a);
@@ -52,21 +53,17 @@ void test() {
5253
}
5354
}
5455
{
55-
std::vector<bool, limited_allocator<bool, 10> > v(10, true);
56-
bool a[10 * 65536] = {};
56+
std::vector<bool, limited_allocator<bool, 10> > v(5, true);
57+
bool a[v.max_size()] = {};
5758
try {
5859
v.insert_range(v.begin() + v.size() / 2, a);
5960
assert(false);
60-
} catch (...) {
61-
assert(v.size() == 10);
61+
} catch (const std::length_error&) {
62+
assert(v.size() == 5);
6263
for (std::size_t i = 0; i != v.size(); ++i)
6364
assert(v[i] == true);
6465
}
6566
}
66-
}
67-
68-
int main(int, char**) {
69-
test();
7067

7168
return 0;
7269
}

libcxx/test/std/containers/sequences/vector.bool/push_back_exceptions.pass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
// void push_back(const value_type& x);
1515

1616
#include <cassert>
17+
#include <stdexcept>
1718
#include <vector>
1819

1920
#include "test_allocator.h"
2021

2122
int main(int, char**) {
22-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
23-
Vec v(Vec().max_size(), true);
23+
std::vector<bool, limited_allocator<bool, 10> > v;
24+
v.resize(v.max_size(), true);
2425
try {
2526
v.push_back(true);
2627
assert(false);
27-
} catch (...) {
28+
} catch (const std::length_error&) {
2829
assert(v.size() == v.max_size());
2930
for (std::size_t i = 0; i != v.size(); ++i)
3031
assert(v[i] == true);

libcxx/test/std/containers/sequences/vector.bool/reserve_exceptions.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "test_allocator.h"
2121

22-
void test() {
22+
int main(int, char**) {
2323
{
2424
std::vector<bool, limited_allocator<bool, 10> > v;
2525
v.reserve(5);
@@ -36,8 +36,8 @@ void test() {
3636
}
3737
}
3838
{
39-
using Vec = std::vector<bool, limited_allocator<bool, 10> >;
40-
Vec v(Vec().max_size(), true);
39+
std::vector<bool, limited_allocator<bool, 10> > v;
40+
v.resize(v.max_size(), true);
4141
try {
4242
v.reserve(v.max_size() + 1);
4343
assert(false);
@@ -60,9 +60,6 @@ void test() {
6060
assert(v[i] == a[i]);
6161
}
6262
}
63-
}
6463

65-
int main(int, char**) {
66-
test();
6764
return 0;
6865
}

0 commit comments

Comments
 (0)