From 73fb3f0bfa8a71805d9cff188576e9d5140898bd Mon Sep 17 00:00:00 2001 From: Joe Loser Date: Wed, 20 Jun 2018 22:03:08 -0400 Subject: [PATCH] Mark some move and move-assignment ctors noexcept --- CMakeLists.txt | 4 +- src/ripple/basics/Buffer.h | 4 +- src/ripple/basics/CountedObject.h | 23 ++++---- src/ripple/basics/impl/CountedObject.cpp | 9 ++-- src/ripple/basics/qalloc.h | 4 +- src/ripple/consensus/Consensus.h | 2 +- src/ripple/core/ClosureCounter.h | 3 +- src/ripple/crypto/impl/openssl.h | 6 +-- src/ripple/ledger/CashDiff.h | 2 +- src/ripple/ledger/detail/ReadViewFwdRange.h | 12 ++++- src/ripple/ledger/detail/ReadViewFwdRange.ipp | 4 +- src/ripple/ledger/impl/CashDiff.cpp | 2 +- src/test/basics/Buffer_test.cpp | 4 ++ src/test/basics/qalloc_test.cpp | 47 ++++++++++++++++ src/test/core/ClosureCounter_test.cpp | 2 +- src/test/crypto/Openssl_test.cpp | 54 +++++++++++++++++++ src/test/ledger/CashDiff_test.cpp | 8 ++- src/test/unity/basics_test_unity.cpp | 1 + src/test/unity/crypto_test_unity.cpp | 21 ++++++++ 19 files changed, 179 insertions(+), 33 deletions(-) create mode 100644 src/test/basics/qalloc_test.cpp create mode 100644 src/test/crypto/Openssl_test.cpp create mode 100644 src/test/unity/crypto_test_unity.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 44cd22d0f..b6c4e2c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,7 @@ beast_test_unity2.cpp conditions_test_unity.cpp consensus_test_unity.cpp core_test_unity.cpp +crypto_test_unity.cpp json_test_unity.cpp ledger_test_unity.cpp overlay_test_unity.cpp @@ -273,8 +274,8 @@ foreach(curdir app basics conditions - crypto consensus + crypto json ledger legacy @@ -310,6 +311,7 @@ foreach(curdir conditions consensus core + crypto csf json jtx diff --git a/src/ripple/basics/Buffer.h b/src/ripple/basics/Buffer.h index 3e9bf3703..bfb119d6c 100644 --- a/src/ripple/basics/Buffer.h +++ b/src/ripple/basics/Buffer.h @@ -82,7 +82,7 @@ public: /** Move-construct. The other buffer is reset. */ - Buffer (Buffer&& other) + Buffer (Buffer&& other) noexcept : p_ (std::move(other.p_)) , size_ (other.size_) { @@ -92,7 +92,7 @@ public: /** Move-assign. The other buffer is reset. */ - Buffer& operator= (Buffer&& other) + Buffer& operator= (Buffer&& other) noexcept { if (this != &other) { diff --git a/src/ripple/basics/CountedObject.h b/src/ripple/basics/CountedObject.h index 8b52eeb7d..01bc05353 100644 --- a/src/ripple/basics/CountedObject.h +++ b/src/ripple/basics/CountedObject.h @@ -31,7 +31,7 @@ namespace ripple { class CountedObjects { public: - static CountedObjects& getInstance (); + static CountedObjects& getInstance () noexcept; using Entry = std::pair ; using List = std::vector ; @@ -46,9 +46,9 @@ public: class CounterBase { public: - CounterBase (); + CounterBase () noexcept; - virtual ~CounterBase (); + virtual ~CounterBase () noexcept; int increment () noexcept { @@ -81,8 +81,8 @@ public: }; private: - CountedObjects (); - ~CountedObjects () = default; + CountedObjects () noexcept; + ~CountedObjects () noexcept = default; private: std::atomic m_count; @@ -102,19 +102,19 @@ template class CountedObject { public: - CountedObject () + CountedObject () noexcept { getCounter ().increment (); } - CountedObject (CountedObject const&) + CountedObject (CountedObject const&) noexcept { getCounter ().increment (); } - CountedObject& operator=(CountedObject const&) = default; + CountedObject& operator=(CountedObject const&) noexcept = default; - ~CountedObject () + ~CountedObject () noexcept { getCounter ().decrement (); } @@ -123,7 +123,7 @@ private: class Counter : public CountedObjects::CounterBase { public: - Counter () { } + Counter () noexcept { } char const* getName () const override { @@ -134,8 +134,9 @@ private: }; private: - static Counter& getCounter() + static Counter& getCounter() noexcept { + static_assert(std::is_nothrow_constructible{}, ""); static Counter c; return c; } diff --git a/src/ripple/basics/impl/CountedObject.cpp b/src/ripple/basics/impl/CountedObject.cpp index 752ccaf42..14d08d802 100644 --- a/src/ripple/basics/impl/CountedObject.cpp +++ b/src/ripple/basics/impl/CountedObject.cpp @@ -18,17 +18,18 @@ //============================================================================== #include +#include namespace ripple { -CountedObjects& CountedObjects::getInstance () +CountedObjects& CountedObjects::getInstance () noexcept { static CountedObjects instance; return instance; } -CountedObjects::CountedObjects () +CountedObjects::CountedObjects () noexcept : m_count (0) , m_head (nullptr) { @@ -66,7 +67,7 @@ CountedObjects::List CountedObjects::getCounts (int minimumThreshold) const //------------------------------------------------------------------------------ -CountedObjects::CounterBase::CounterBase () +CountedObjects::CounterBase::CounterBase () noexcept : m_count (0) { // Insert ourselves at the front of the lock-free linked list @@ -84,7 +85,7 @@ CountedObjects::CounterBase::CounterBase () ++instance.m_count; } -CountedObjects::CounterBase::~CounterBase () +CountedObjects::CounterBase::~CounterBase () noexcept { // VFALCO NOTE If the counters are destroyed before the singleton, // undefined behavior will result if the singleton's member diff --git a/src/ripple/basics/qalloc.h b/src/ripple/basics/qalloc.h index 7f103a0d8..4d8a0f1c1 100644 --- a/src/ripple/basics/qalloc.h +++ b/src/ripple/basics/qalloc.h @@ -117,9 +117,9 @@ public: }; qalloc_type (qalloc_type const&) = default; - qalloc_type (qalloc_type&& other) = default; + qalloc_type (qalloc_type&& other) noexcept = default; qalloc_type& operator= (qalloc_type const&) = default; - qalloc_type& operator= (qalloc_type&&) = default; + qalloc_type& operator= (qalloc_type&&) noexcept = default; qalloc_type(); diff --git a/src/ripple/consensus/Consensus.h b/src/ripple/consensus/Consensus.h index 621e02650..9225a4048 100644 --- a/src/ripple/consensus/Consensus.h +++ b/src/ripple/consensus/Consensus.h @@ -320,7 +320,7 @@ public: //! Clock type for measuring time within the consensus code using clock_type = beast::abstract_clock; - Consensus(Consensus&&) = default; + Consensus(Consensus&&) noexcept = default; /** Constructor. diff --git a/src/ripple/core/ClosureCounter.h b/src/ripple/core/ClosureCounter.h index 609ffd2f9..e14364e79 100644 --- a/src/ripple/core/ClosureCounter.h +++ b/src/ripple/core/ClosureCounter.h @@ -93,7 +93,8 @@ private: ++counter_; } - Wrapper (Wrapper&& rhs) + Wrapper (Wrapper&& rhs) noexcept( + std::is_nothrow_move_constructible::value) : counter_ (rhs.counter_) , closure_ (std::move (rhs.closure_)) { diff --git a/src/ripple/crypto/impl/openssl.h b/src/ripple/crypto/impl/openssl.h index dae858f95..68cffed42 100644 --- a/src/ripple/crypto/impl/openssl.h +++ b/src/ripple/crypto/impl/openssl.h @@ -61,12 +61,12 @@ public: assign_new (thing.data(), thing.size()); } - bignum(bignum&& that) : ptr( that.ptr ) + bignum(bignum&& that) noexcept : ptr( that.ptr ) { that.ptr = nullptr; } - bignum& operator= (bignum&& that) + bignum& operator= (bignum&& that) noexcept { using std::swap; @@ -163,7 +163,7 @@ public: ec_point (ec_point const&) = delete; ec_point& operator=(ec_point const&) = delete; - ec_point(ec_point&& that) + ec_point(ec_point&& that) noexcept { ptr = that.ptr; that.ptr = nullptr; diff --git a/src/ripple/ledger/CashDiff.h b/src/ripple/ledger/CashDiff.h index 0b5b9e33b..53d130a43 100644 --- a/src/ripple/ledger/CashDiff.h +++ b/src/ripple/ledger/CashDiff.h @@ -62,7 +62,7 @@ class CashDiff public: CashDiff() = delete; CashDiff (CashDiff const&) = delete; - CashDiff (CashDiff&& other); + CashDiff (CashDiff&& other) noexcept; CashDiff& operator= (CashDiff const&) = delete; ~CashDiff(); diff --git a/src/ripple/ledger/detail/ReadViewFwdRange.h b/src/ripple/ledger/detail/ReadViewFwdRange.h index 10ca16275..debf112d7 100644 --- a/src/ripple/ledger/detail/ReadViewFwdRange.h +++ b/src/ripple/ledger/detail/ReadViewFwdRange.h @@ -74,6 +74,11 @@ public: using iter_base = ReadViewFwdIter; + static_assert( + std::is_nothrow_move_constructible{}, + "ReadViewFwdRange move and move assign constructors should be " + "noexcept"); + class iterator { public: @@ -92,7 +97,7 @@ public: iterator() = default; iterator (iterator const& other); - iterator (iterator&& other); + iterator (iterator&& other) noexcept; // Used by the implementation explicit @@ -103,7 +108,7 @@ public: operator= (iterator const& other); iterator& - operator= (iterator&& other); + operator= (iterator&& other) noexcept; bool operator== (iterator const& other) const; @@ -131,6 +136,9 @@ public: boost::optional mutable cache_; }; + static_assert(std::is_nothrow_move_constructible{}, ""); + static_assert(std::is_nothrow_move_assignable{}, ""); + using const_iterator = iterator; using value_type = ValueType; diff --git a/src/ripple/ledger/detail/ReadViewFwdRange.ipp b/src/ripple/ledger/detail/ReadViewFwdRange.ipp index 0062fb2c6..7e39d87ac 100644 --- a/src/ripple/ledger/detail/ReadViewFwdRange.ipp +++ b/src/ripple/ledger/detail/ReadViewFwdRange.ipp @@ -35,7 +35,7 @@ ReadViewFwdRange::iterator::iterator( template ReadViewFwdRange::iterator::iterator( - iterator&& other) + iterator&& other) noexcept : view_ (other.view_) , impl_ (std::move(other.impl_)) , cache_ (std::move(other.cache_)) @@ -69,7 +69,7 @@ ReadViewFwdRange::iterator::operator=( template auto ReadViewFwdRange::iterator::operator=( - iterator&& other) -> + iterator&& other) noexcept -> iterator& { view_ = other.view_; diff --git a/src/ripple/ledger/impl/CashDiff.cpp b/src/ripple/ledger/impl/CashDiff.cpp index 873de8675..e222663a3 100644 --- a/src/ripple/ledger/impl/CashDiff.cpp +++ b/src/ripple/ledger/impl/CashDiff.cpp @@ -633,7 +633,7 @@ void CashDiff::Impl::findDiffs ( //------------------------------------------------------------------------------ // Locates differences between two ApplyStateTables. -CashDiff::CashDiff (CashDiff&& other) +CashDiff::CashDiff (CashDiff&& other) noexcept : impl_ (std::move (other.impl_)) { } diff --git a/src/test/basics/Buffer_test.cpp b/src/test/basics/Buffer_test.cpp index bffea7fd7..115ba9336 100644 --- a/src/test/basics/Buffer_test.cpp +++ b/src/test/basics/Buffer_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -108,6 +109,9 @@ struct Buffer_test : beast::unit_test::suite // Check move constructor & move assignments: { testcase ("Move Construction / Assignment"); + + static_assert(std::is_nothrow_move_constructible::value, ""); + static_assert(std::is_nothrow_move_assignable::value, ""); { // Move-construct from empty buf Buffer x; diff --git a/src/test/basics/qalloc_test.cpp b/src/test/basics/qalloc_test.cpp new file mode 100644 index 000000000..4ed2010df --- /dev/null +++ b/src/test/basics/qalloc_test.cpp @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2018 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include + +namespace ripple { + +struct qalloc_test : beast::unit_test::suite +{ + void + testBasicProperties() + { + BEAST_EXPECT(std::is_default_constructible{}); + BEAST_EXPECT(std::is_copy_constructible{}); + BEAST_EXPECT(std::is_copy_assignable{}); + BEAST_EXPECT(std::is_nothrow_move_constructible{}); + BEAST_EXPECT(std::is_nothrow_move_assignable{}); + } + + void + run() override + { + testBasicProperties(); + } +}; + +BEAST_DEFINE_TESTSUITE(qalloc, ripple_basics, ripple); + +} // namespace ripple diff --git a/src/test/core/ClosureCounter_test.cpp b/src/test/core/ClosureCounter_test.cpp index cb4e6596f..bac109ab1 100644 --- a/src/test/core/ClosureCounter_test.cpp +++ b/src/test/core/ClosureCounter_test.cpp @@ -126,7 +126,7 @@ class ClosureCounter_test : public beast::unit_test::suite , str (rhs.str) {} // Move constructor - TrackedString (TrackedString&& rhs) + TrackedString (TrackedString&& rhs) noexcept : copies (rhs.copies) , moves (rhs.moves + 1) , str (std::move(rhs.str)) {} diff --git a/src/test/crypto/Openssl_test.cpp b/src/test/crypto/Openssl_test.cpp new file mode 100644 index 000000000..6bc91feab --- /dev/null +++ b/src/test/crypto/Openssl_test.cpp @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2018 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include + +namespace ripple { +struct Openssl_test : public beast::unit_test::suite +{ + void + testBasicProperties() + { + using namespace openssl; + + BEAST_EXPECT(std::is_default_constructible{}); + BEAST_EXPECT(!std::is_copy_constructible{}); + BEAST_EXPECT(!std::is_copy_assignable{}); + BEAST_EXPECT(std::is_nothrow_move_constructible{}); + BEAST_EXPECT(std::is_nothrow_move_assignable{}); + + BEAST_EXPECT(!std::is_default_constructible{}); + BEAST_EXPECT(!std::is_copy_constructible{}); + BEAST_EXPECT(!std::is_copy_assignable{}); + BEAST_EXPECT(std::is_nothrow_move_constructible{}); + BEAST_EXPECT(!std::is_nothrow_move_assignable{}); + } + + void + run() override + { + testBasicProperties(); + }; +}; + +BEAST_DEFINE_TESTSUITE(Openssl, crypto, ripple); + +} // namespace ripple diff --git a/src/test/ledger/CashDiff_test.cpp b/src/test/ledger/CashDiff_test.cpp index c9208ee0d..22ed1a391 100644 --- a/src/test/ledger/CashDiff_test.cpp +++ b/src/test/ledger/CashDiff_test.cpp @@ -20,14 +20,20 @@ #include #include #include +#include namespace ripple { namespace test { class CashDiff_test : public beast::unit_test::suite { + static_assert(!std::is_default_constructible{}, ""); + static_assert(!std::is_copy_constructible{}, ""); + static_assert(!std::is_copy_assignable{}, ""); + static_assert(std::is_nothrow_move_constructible{}, ""); + static_assert(!std::is_move_assignable{}, ""); - // Exercise diffIsDust (STAmount, STAmount) + // Exercise diffIsDust (STAmount, STAmount) void testDust () { diff --git a/src/test/unity/basics_test_unity.cpp b/src/test/unity/basics_test_unity.cpp index da3ab9189..a711181dd 100644 --- a/src/test/unity/basics_test_unity.cpp +++ b/src/test/unity/basics_test_unity.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/unity/crypto_test_unity.cpp b/src/test/unity/crypto_test_unity.cpp new file mode 100644 index 000000000..925b7e632 --- /dev/null +++ b/src/test/unity/crypto_test_unity.cpp @@ -0,0 +1,21 @@ + +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2018 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include