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
This commit is contained in:
Jon Atack 2022-04-28 13:33:57 +02:00
parent abc1ee5090
commit e5485e8e4b
5 changed files with 23 additions and 10 deletions

View File

@ -39,7 +39,10 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
{ {
return true; return true;
} }
void swap(PrevectorJob& x){p.swap(x.p);}; void swap(PrevectorJob& x) noexcept
{
p.swap(x.p);
};
}; };
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE}; CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
// The main thread should be counted to prevent thread oversubscription, and // The main thread should be counted to prevent thread oversubscription, and

View File

@ -42,7 +42,7 @@ struct FakeCheck {
{ {
return true; return true;
} }
void swap(FakeCheck& x){}; void swap(FakeCheck& x) noexcept {};
}; };
struct FakeCheckCheckCompletion { struct FakeCheckCheckCompletion {
@ -52,7 +52,7 @@ struct FakeCheckCheckCompletion {
n_calls.fetch_add(1, std::memory_order_relaxed); n_calls.fetch_add(1, std::memory_order_relaxed);
return true; return true;
} }
void swap(FakeCheckCheckCompletion& x){}; void swap(FakeCheckCheckCompletion& x) noexcept {};
}; };
struct FailingCheck { struct FailingCheck {
@ -63,7 +63,7 @@ struct FailingCheck {
{ {
return !fails; return !fails;
} }
void swap(FailingCheck& x) void swap(FailingCheck& x) noexcept
{ {
std::swap(fails, x.fails); std::swap(fails, x.fails);
}; };
@ -81,7 +81,10 @@ struct UniqueCheck {
results.insert(check_id); results.insert(check_id);
return true; return true;
} }
void swap(UniqueCheck& x) { std::swap(x.check_id, check_id); }; void swap(UniqueCheck& x) noexcept
{
std::swap(x.check_id, check_id);
};
}; };
@ -109,7 +112,10 @@ struct MemoryCheck {
{ {
fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed); fake_allocated_memory.fetch_sub(b, std::memory_order_relaxed);
}; };
void swap(MemoryCheck& x) { std::swap(b, x.b); }; void swap(MemoryCheck& x) noexcept
{
std::swap(b, x.b);
};
}; };
struct FrozenCleanupCheck { struct FrozenCleanupCheck {
@ -133,7 +139,10 @@ struct FrozenCleanupCheck {
cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;}); cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
} }
} }
void swap(FrozenCleanupCheck& x){std::swap(should_freeze, x.should_freeze);}; void swap(FrozenCleanupCheck& x) noexcept
{
std::swap(should_freeze, x.should_freeze);
};
}; };
// Static Allocations // Static Allocations

View File

@ -26,7 +26,7 @@ struct DumbCheck {
return result; return result;
} }
void swap(DumbCheck& x) void swap(DumbCheck& x) noexcept
{ {
} }
}; };

View File

@ -161,7 +161,7 @@ public:
pre_vector.shrink_to_fit(); pre_vector.shrink_to_fit();
} }
void swap() void swap() noexcept
{ {
real_vector.swap(real_vector_alt); real_vector.swap(real_vector_alt);
pre_vector.swap(pre_vector_alt); pre_vector.swap(pre_vector_alt);

View File

@ -165,7 +165,8 @@ public:
test(); test();
} }
void swap() { void swap() noexcept
{
real_vector.swap(real_vector_alt); real_vector.swap(real_vector_alt);
pre_vector.swap(pre_vector_alt); pre_vector.swap(pre_vector_alt);
test(); test();