Skip to content

Commit e5485e8

Browse files
committed
test, bench: make prevector and checkqueue swap member functions noexcept
Reason: A swap must not fail; when a class has a swap member function, it should be declared noexcept. https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c84-a-swap-function-must-not-fail
1 parent abc1ee5 commit e5485e8

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

Diff for: src/bench/checkqueue.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
3939
{
4040
return true;
4141
}
42-
void swap(PrevectorJob& x){p.swap(x.p);};
42+
void swap(PrevectorJob& x) noexcept
43+
{
44+
p.swap(x.p);
45+
};
4346
};
4447
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
4548
// The main thread should be counted to prevent thread oversubscription, and

Diff for: src/test/checkqueue_tests.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct FakeCheck {
4242
{
4343
return true;
4444
}
45-
void swap(FakeCheck& x){};
45+
void swap(FakeCheck& x) noexcept {};
4646
};
4747

4848
struct FakeCheckCheckCompletion {
@@ -52,7 +52,7 @@ struct FakeCheckCheckCompletion {
5252
n_calls.fetch_add(1, std::memory_order_relaxed);
5353
return true;
5454
}
55-
void swap(FakeCheckCheckCompletion& x){};
55+
void swap(FakeCheckCheckCompletion& x) noexcept {};
5656
};
5757

5858
struct FailingCheck {
@@ -63,7 +63,7 @@ struct FailingCheck {
6363
{
6464
return !fails;
6565
}
66-
void swap(FailingCheck& x)
66+
void swap(FailingCheck& x) noexcept
6767
{
6868
std::swap(fails, x.fails);
6969
};
@@ -81,7 +81,10 @@ struct UniqueCheck {
8181
results.insert(check_id);
8282
return true;
8383
}
84-
void swap(UniqueCheck& x) { std::swap(x.check_id, check_id); };
84+
void swap(UniqueCheck& x) noexcept
85+
{
86+
std::swap(x.check_id, check_id);
87+
};
8588
};
8689

8790

@@ -109,7 +112,10 @@ struct MemoryCheck {
109112
{
110113
fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed);
111114
};
112-
void swap(MemoryCheck& x) { std::swap(b, x.b); };
115+
void swap(MemoryCheck& x) noexcept
116+
{
117+
std::swap(b, x.b);
118+
};
113119
};
114120

115121
struct FrozenCleanupCheck {
@@ -133,7 +139,10 @@ struct FrozenCleanupCheck {
133139
cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
134140
}
135141
}
136-
void swap(FrozenCleanupCheck& x){std::swap(should_freeze, x.should_freeze);};
142+
void swap(FrozenCleanupCheck& x) noexcept
143+
{
144+
std::swap(should_freeze, x.should_freeze);
145+
};
137146
};
138147

139148
// Static Allocations

Diff for: src/test/fuzz/checkqueue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct DumbCheck {
2626
return result;
2727
}
2828

29-
void swap(DumbCheck& x)
29+
void swap(DumbCheck& x) noexcept
3030
{
3131
}
3232
};

Diff for: src/test/fuzz/prevector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class prevector_tester
161161
pre_vector.shrink_to_fit();
162162
}
163163

164-
void swap()
164+
void swap() noexcept
165165
{
166166
real_vector.swap(real_vector_alt);
167167
pre_vector.swap(pre_vector_alt);

Diff for: src/test/prevector_tests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ class prevector_tester {
165165
test();
166166
}
167167

168-
void swap() {
168+
void swap() noexcept
169+
{
169170
real_vector.swap(real_vector_alt);
170171
pre_vector.swap(pre_vector_alt);
171172
test();

0 commit comments

Comments
 (0)