From 5fef9aadd206dce1d0faa984e66a0c3eb12154dd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 14 Dec 2022 19:36:20 +0300 Subject: Add noexcept to move constructors and move assignment operators --- odb/database.hxx | 2 ++ odb/details/transfer-ptr.hxx | 2 +- odb/details/unique-ptr.hxx | 4 ++-- odb/lazy-ptr-impl.hxx | 8 ++++---- odb/lazy-ptr-impl.ixx | 8 ++++---- odb/lazy-ptr.hxx | 8 ++++---- odb/lazy-ptr.ixx | 8 ++++---- odb/vector-impl.hxx | 4 ++-- odb/vector-impl.ixx | 11 +++++++++-- odb/vector.hxx | 8 +++++++- 10 files changed, 39 insertions(+), 24 deletions(-) diff --git a/odb/database.hxx b/odb/database.hxx index 485cf52..e18e8ee 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -48,6 +48,8 @@ namespace odb #ifdef ODB_CXX11 //database (database&&) = default; // VC 2013 + // Note: noexcept is not specified since *_map_ (std::map) can throw. + // database (database&& d) : id_ (d.id_), tracer_ (d.tracer_), diff --git a/odb/details/transfer-ptr.hxx b/odb/details/transfer-ptr.hxx index 2ee0752..4b63df6 100644 --- a/odb/details/transfer-ptr.hxx +++ b/odb/details/transfer-ptr.hxx @@ -49,7 +49,7 @@ namespace odb transfer_ptr& operator= (const transfer_ptr&); public: - transfer_ptr (transfer_ptr&& p): p_ (p.transfer ()) {} + transfer_ptr (transfer_ptr&& p) noexcept: p_ (p.transfer ()) {} #endif ~transfer_ptr () {delete p_;} diff --git a/odb/details/unique-ptr.hxx b/odb/details/unique-ptr.hxx index 6663c30..06b2c76 100644 --- a/odb/details/unique-ptr.hxx +++ b/odb/details/unique-ptr.hxx @@ -22,8 +22,8 @@ namespace odb ~unique_ptr () {delete p_;} #ifdef ODB_CXX11 - unique_ptr (unique_ptr&& p): p_ (p.p_) {p.p_ = 0;} - unique_ptr& operator= (unique_ptr&& p) + unique_ptr (unique_ptr&& p) noexcept: p_ (p.p_) {p.p_ = 0;} + unique_ptr& operator= (unique_ptr&& p) noexcept { if (this != &p) { diff --git a/odb/lazy-ptr-impl.hxx b/odb/lazy-ptr-impl.hxx index 83d6011..89fe798 100644 --- a/odb/lazy-ptr-impl.hxx +++ b/odb/lazy-ptr-impl.hxx @@ -44,10 +44,10 @@ namespace odb // public: #ifdef ODB_CXX11 - lazy_ptr_base (lazy_ptr_base&&); + lazy_ptr_base (lazy_ptr_base&&) noexcept; lazy_ptr_base& - operator= (lazy_ptr_base&&); + operator= (lazy_ptr_base&&) noexcept; #endif public: @@ -139,13 +139,13 @@ namespace odb // public: #ifdef ODB_CXX11 - lazy_ptr_impl (lazy_ptr_impl&&); + lazy_ptr_impl (lazy_ptr_impl&&) noexcept; template lazy_ptr_impl (lazy_ptr_impl&&); lazy_ptr_impl& - operator= (lazy_ptr_impl&&); + operator= (lazy_ptr_impl&&) noexcept; template lazy_ptr_impl& diff --git a/odb/lazy-ptr-impl.ixx b/odb/lazy-ptr-impl.ixx index 7843dc9..9ab0471 100644 --- a/odb/lazy-ptr-impl.ixx +++ b/odb/lazy-ptr-impl.ixx @@ -31,7 +31,7 @@ namespace odb #ifdef ODB_CXX11 inline lazy_ptr_base:: - lazy_ptr_base (lazy_ptr_base&& r) + lazy_ptr_base (lazy_ptr_base&& r) noexcept : id_ (r.id_), db_ (r.db_), loader_ (r.loader_), free_ (r.free_), copy_ (r.copy_) { @@ -78,7 +78,7 @@ namespace odb #ifdef ODB_CXX11 inline lazy_ptr_base& lazy_ptr_base:: - operator= (lazy_ptr_base&& r) + operator= (lazy_ptr_base&& r) noexcept { if (id_ != r.id_) { @@ -272,7 +272,7 @@ namespace odb #ifdef ODB_CXX11 template inline lazy_ptr_impl:: - lazy_ptr_impl (lazy_ptr_impl&& r) + lazy_ptr_impl (lazy_ptr_impl&& r) noexcept : lazy_ptr_base (std::move (r)) { } @@ -287,7 +287,7 @@ namespace odb template inline lazy_ptr_impl& lazy_ptr_impl:: - operator= (lazy_ptr_impl&& r) + operator= (lazy_ptr_impl&& r) noexcept { lazy_ptr_base& b (*this); b = std::move (r); diff --git a/odb/lazy-ptr.hxx b/odb/lazy-ptr.hxx index ae2b43c..ab31dfc 100644 --- a/odb/lazy-ptr.hxx +++ b/odb/lazy-ptr.hxx @@ -246,14 +246,14 @@ namespace odb lazy_unique_ptr (pointer, const deleter_type&) /*noexcept*/; lazy_unique_ptr (pointer, deleter_type&&) /*noexcept*/; - lazy_unique_ptr (lazy_unique_ptr&&) /*noexcept*/; + lazy_unique_ptr (lazy_unique_ptr&&) noexcept; template lazy_unique_ptr (lazy_unique_ptr&&) /*noexcept*/; //template lazy_unique_ptr (std::auto_ptr&&) /*noexcept*/; #ifdef ODB_CXX11_NULLPTR lazy_unique_ptr& operator= (std::nullptr_t) /*noexcept*/; #endif - lazy_unique_ptr& operator= (lazy_unique_ptr&&) /*noexcept*/; + lazy_unique_ptr& operator= (lazy_unique_ptr&&) noexcept; template lazy_unique_ptr& operator= (lazy_unique_ptr&&) /*noexcept*/; T& operator* () const; @@ -407,7 +407,7 @@ namespace odb lazy_shared_ptr (const lazy_shared_ptr&) /*noexcept*/; template lazy_shared_ptr (const lazy_shared_ptr&) /*noexcept*/; - lazy_shared_ptr (lazy_shared_ptr&&) /*noexcept*/; + lazy_shared_ptr (lazy_shared_ptr&&) noexcept; template lazy_shared_ptr (lazy_shared_ptr&&) /*noexcept*/; template explicit lazy_shared_ptr (const lazy_weak_ptr&); //template explicit lazy_shared_ptr (std::auto_ptr&&); @@ -417,7 +417,7 @@ namespace odb lazy_shared_ptr& operator= (const lazy_shared_ptr&) /*noexcept*/; template lazy_shared_ptr& operator= (const lazy_shared_ptr&) /*noexcept*/; - lazy_shared_ptr& operator= (lazy_shared_ptr&&) /*noexcept*/; + lazy_shared_ptr& operator= (lazy_shared_ptr&&) noexcept; template lazy_shared_ptr& operator= (lazy_shared_ptr&&) /*noexcept*/; //template lazy_shared_ptr& operator= (std::auto_ptr&&); template lazy_shared_ptr& operator= (std::unique_ptr&&); diff --git a/odb/lazy-ptr.ixx b/odb/lazy-ptr.ixx index 647db83..a2d72f5 100644 --- a/odb/lazy-ptr.ixx +++ b/odb/lazy-ptr.ixx @@ -519,7 +519,7 @@ namespace odb template lazy_unique_ptr:: - lazy_unique_ptr (lazy_unique_ptr&& r) + lazy_unique_ptr (lazy_unique_ptr&& r) noexcept : p_ (std::move (r.p_)), i_ (std::move (r.i_)) {} template @@ -545,7 +545,7 @@ namespace odb template lazy_unique_ptr& lazy_unique_ptr:: - operator= (lazy_unique_ptr&& r) + operator= (lazy_unique_ptr&& r) noexcept { p_ = std::move (r.p_); i_ = std::move (r.i_); @@ -922,7 +922,7 @@ namespace odb template inline lazy_shared_ptr:: - lazy_shared_ptr (lazy_shared_ptr&& r) + lazy_shared_ptr (lazy_shared_ptr&& r) noexcept : p_ (std::move (r.p_)), i_ (std::move (r.i_)) {} template @@ -979,7 +979,7 @@ namespace odb template inline lazy_shared_ptr& lazy_shared_ptr:: - operator= (lazy_shared_ptr&& r) + operator= (lazy_shared_ptr&& r) noexcept { p_ = std::move (r.p_); i_ = std::move (r.i_); diff --git a/odb/vector-impl.hxx b/odb/vector-impl.hxx index 5189395..9f2ea7c 100644 --- a/odb/vector-impl.hxx +++ b/odb/vector-impl.hxx @@ -45,7 +45,7 @@ namespace odb vector_impl (const vector_impl&); #ifdef ODB_CXX11 - vector_impl (vector_impl&&); + vector_impl (vector_impl&&) noexcept; #endif void @@ -195,7 +195,7 @@ namespace odb vector_base (const vector_base&); #ifdef ODB_CXX11 - vector_base (vector_base&&); + vector_base (vector_base&&) noexcept; #endif void diff --git a/odb/vector-impl.ixx b/odb/vector-impl.ixx index 3377cb8..1c0ee90 100644 --- a/odb/vector-impl.ixx +++ b/odb/vector-impl.ixx @@ -20,7 +20,7 @@ namespace odb #ifdef ODB_CXX11 inline vector_impl:: - vector_impl (vector_impl&& x) + vector_impl (vector_impl&& x) noexcept : state_ (state_not_tracking), size_ (0), tail_ (0), capacity_ (0), data_ (0) { @@ -167,12 +167,19 @@ namespace odb #ifdef ODB_CXX11 inline vector_base:: - vector_base (vector_base&& x) + vector_base (vector_base&& x) noexcept : impl_ (std::move (x.impl_)), tran_ (0) { if (x.tran_ != 0) { x.tran_->callback_unregister (&x); + + // Note that _arm() can potentially throw bad_alloc while adding a new + // callback to the callbacks list of the transaction object. However, we + // assume that this will not happen since the new callback should be + // saved into an existing slot, freed by the above callback_unregister() + // call. + // _arm (*x.tran_); } } diff --git a/odb/vector.hxx b/odb/vector.hxx index ac75ef1..3fe7d8a 100644 --- a/odb/vector.hxx +++ b/odb/vector.hxx @@ -91,10 +91,16 @@ namespace odb {return v_.get_allocator ();} #ifdef ODB_CXX11 - vector(vector&& x): vector_base (std::move (x)), v_ (std::move (x.v_)) {} + vector(vector&& x) noexcept + : vector_base (std::move (x)), v_ (std::move (x.v_)) {} + vector(const vector& x, const A& a): vector_base (x), v_ (x.v_, a) {} vector(vector&& x, const A& a) : vector_base (std::move (x)), v_ (std::move (x.v_), a) {} + + // Note: noexcept is not specified since it can throw while reallocating + // impl_. + // vector& operator=(vector&&); #ifdef ODB_CXX11_INITIALIZER_LIST vector(std::initializer_list il, const A& a = A()): v_ (il, a) {} -- cgit v1.1