diff options
author | MacroFake <falke.marco@gmail.com> | 2022-05-02 14:14:51 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-05-02 14:14:58 +0200 |
commit | 5c93fc188d61cb64db91e6a0b9a98579974fa31d (patch) | |
tree | 7f7e9471323f96170205c4432f42aee6e6bfcc44 /src | |
parent | e389c4d30881db4d115aeb700d0a22c2859ba9fe (diff) | |
parent | e5485e8e4be7f2ee0671f58c3dcce35c68ba0ee0 (diff) |
Merge bitcoin/bitcoin#25017: validation: make CScriptCheck and prevector swap members noexcept
e5485e8e4be7f2ee0671f58c3dcce35c68ba0ee0 test, bench: make prevector and checkqueue swap member functions noexcept (Jon Atack)
abc1ee509025d92db5311c3f5df3b61c09cad24f validation: make CScriptCheck and prevector swap member functions noexcept (Jon Atack)
Pull request description:
along with those seen elsewhere in the codebase (prevector and checkqueue units/fuzz/bench).
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
ACKs for top commit:
pk-b2:
ACK https://github.com/bitcoin/bitcoin/pull/25017/commits/e5485e8e4be7f2ee0671f58c3dcce35c68ba0ee0
w0xlt:
ACK https://github.com/bitcoin/bitcoin/pull/25017/commits/e5485e8e4be7f2ee0671f58c3dcce35c68ba0ee0
Tree-SHA512: c82359d5e13f9262ce45efdae9baf71e41ed26568e0aff620e2bfb0ab37a62b6d56ae9340a28a0332c902cc1fa87da3fb72d6f6d6f53a8b7e695a5011f71f7f1
Diffstat (limited to 'src')
-rw-r--r-- | src/bench/checkqueue.cpp | 5 | ||||
-rw-r--r-- | src/prevector.h | 3 | ||||
-rw-r--r-- | src/test/checkqueue_tests.cpp | 21 | ||||
-rw-r--r-- | src/test/fuzz/checkqueue.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/prevector.cpp | 2 | ||||
-rw-r--r-- | src/test/prevector_tests.cpp | 3 | ||||
-rw-r--r-- | src/validation.h | 3 |
7 files changed, 27 insertions, 12 deletions
diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index d7b8c1badc..53591f8905 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -39,7 +39,10 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench) { 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}; // The main thread should be counted to prevent thread oversubscription, and diff --git a/src/prevector.h b/src/prevector.h index aa20efaaa7..830b31e315 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -458,7 +458,8 @@ public: return *item_ptr(size() - 1); } - void swap(prevector<N, T, Size, Diff>& other) { + void swap(prevector<N, T, Size, Diff>& other) noexcept + { std::swap(_union, other._union); std::swap(_size, other._size); } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 0d95bd7670..79d6b94dff 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -42,7 +42,7 @@ struct FakeCheck { { return true; } - void swap(FakeCheck& x){}; + void swap(FakeCheck& x) noexcept {}; }; struct FakeCheckCheckCompletion { @@ -52,7 +52,7 @@ struct FakeCheckCheckCompletion { n_calls.fetch_add(1, std::memory_order_relaxed); return true; } - void swap(FakeCheckCheckCompletion& x){}; + void swap(FakeCheckCheckCompletion& x) noexcept {}; }; struct FailingCheck { @@ -63,7 +63,7 @@ struct FailingCheck { { return !fails; } - void swap(FailingCheck& x) + void swap(FailingCheck& x) noexcept { std::swap(fails, x.fails); }; @@ -81,7 +81,10 @@ struct UniqueCheck { results.insert(check_id); 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); }; - void swap(MemoryCheck& x) { std::swap(b, x.b); }; + void swap(MemoryCheck& x) noexcept + { + std::swap(b, x.b); + }; }; struct FrozenCleanupCheck { @@ -133,7 +139,10 @@ struct FrozenCleanupCheck { 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 diff --git a/src/test/fuzz/checkqueue.cpp b/src/test/fuzz/checkqueue.cpp index 0b16f0f0d5..7d107995aa 100644 --- a/src/test/fuzz/checkqueue.cpp +++ b/src/test/fuzz/checkqueue.cpp @@ -26,7 +26,7 @@ struct DumbCheck { return result; } - void swap(DumbCheck& x) + void swap(DumbCheck& x) noexcept { } }; diff --git a/src/test/fuzz/prevector.cpp b/src/test/fuzz/prevector.cpp index a48bab1ee2..e2d65a4796 100644 --- a/src/test/fuzz/prevector.cpp +++ b/src/test/fuzz/prevector.cpp @@ -161,7 +161,7 @@ public: pre_vector.shrink_to_fit(); } - void swap() + void swap() noexcept { real_vector.swap(real_vector_alt); pre_vector.swap(pre_vector_alt); diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index 89814748fe..3977a3d548 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -165,7 +165,8 @@ public: test(); } - void swap() { + void swap() noexcept + { real_vector.swap(real_vector_alt); pre_vector.swap(pre_vector_alt); test(); diff --git a/src/validation.h b/src/validation.h index e3ea8617e7..afc53bb445 100644 --- a/src/validation.h +++ b/src/validation.h @@ -328,7 +328,8 @@ public: bool operator()(); - void swap(CScriptCheck &check) { + void swap(CScriptCheck& check) noexcept + { std::swap(ptxTo, check.ptxTo); std::swap(m_tx_out, check.m_tx_out); std::swap(nIn, check.nIn); |