From a91c7e718cf9de649768ee13dbb7d79747046497 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 30 May 2018 22:04:17 +0200 Subject: [PATCH] Problem: warnings on violations of CERT ERR-58 Solution: declare functions noexcept --- src/atomic_counter.hpp | 23 ++++++++++++++++------- src/atomic_ptr.hpp | 34 +++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/atomic_counter.hpp b/src/atomic_counter.hpp index 1b0cc58f..a1d3655f 100644 --- a/src/atomic_counter.hpp +++ b/src/atomic_counter.hpp @@ -66,6 +66,14 @@ #include #endif +#if !defined ZMQ_NOEXCEPT +#if defined ZMQ_HAVE_NOEXCEPT +#define ZMQ_NOEXCEPT noexcept +#else +#define ZMQ_NOEXCEPT +#endif +#endif + namespace zmq { // This class represents an integer that can be incremented/decremented @@ -90,15 +98,16 @@ class atomic_counter_t public: typedef uint32_t integer_t; - inline atomic_counter_t (integer_t value_ = 0) : _value (value_) {} - - inline ~atomic_counter_t () {} + inline atomic_counter_t (integer_t value_ = 0) ZMQ_NOEXCEPT + : _value (value_) + { + } // Set counter _value (not thread-safe). - inline void set (integer_t value_) { _value = value_; } + inline void set (integer_t value_) ZMQ_NOEXCEPT { _value = value_; } // Atomic addition. Returns the old _value. - inline integer_t add (integer_t increment_) + inline integer_t add (integer_t increment_) ZMQ_NOEXCEPT { integer_t old_value; @@ -143,7 +152,7 @@ class atomic_counter_t } // Atomic subtraction. Returns false if the counter drops to zero. - inline bool sub (integer_t decrement_) + inline bool sub (integer_t decrement_) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_COUNTER_WINDOWS LONG delta = -((LONG) decrement_); @@ -198,7 +207,7 @@ class atomic_counter_t #endif } - inline integer_t get () const { return _value; } + inline integer_t get () const ZMQ_NOEXCEPT { return _value; } private: #if defined ZMQ_ATOMIC_COUNTER_CXX11 diff --git a/src/atomic_ptr.hpp b/src/atomic_ptr.hpp index 5b85073c..9940dae1 100644 --- a/src/atomic_ptr.hpp +++ b/src/atomic_ptr.hpp @@ -64,6 +64,14 @@ #include #endif +#if !defined ZMQ_NOEXCEPT +#if defined ZMQ_HAVE_NOEXCEPT +#define ZMQ_NOEXCEPT noexcept +#else +#define ZMQ_NOEXCEPT +#endif +#endif + namespace zmq { #if !defined ZMQ_ATOMIC_PTR_CXX11 @@ -73,7 +81,7 @@ inline void *atomic_xchg_ptr (void **ptr_, , mutex_t &_sync #endif -) + ) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_WINDOWS return InterlockedExchangePointer ((PVOID *) ptr_, val_); @@ -120,7 +128,7 @@ inline void *atomic_cas (void *volatile *ptr_, , mutex_t &_sync #endif -) + ) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_WINDOWS return InterlockedCompareExchangePointer ((volatile PVOID *) ptr_, val_, @@ -176,19 +184,16 @@ template class atomic_ptr_t { public: // Initialise atomic pointer - inline atomic_ptr_t () { _ptr = NULL; } - - // Destroy atomic pointer - inline ~atomic_ptr_t () {} + inline atomic_ptr_t () ZMQ_NOEXCEPT { _ptr = NULL; } // Set value of atomic pointer in a non-threadsafe way // Use this function only when you are sure that at most one // thread is accessing the pointer at the moment. - inline void set (T *ptr_) { _ptr = ptr_; } + inline void set (T *ptr_) ZMQ_NOEXCEPT { _ptr = ptr_; } // Perform atomic 'exchange pointers' operation. Pointer is set // to the 'val_' value. Old value is returned. - inline T *xchg (T *val_) + inline T *xchg (T *val_) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_CXX11 return _ptr.exchange (val_, std::memory_order_acq_rel); @@ -206,7 +211,7 @@ template class atomic_ptr_t // The pointer is compared to 'cmp' argument and if they are // equal, its value is set to 'val_'. Old value of the pointer // is returned. - inline T *cas (T *cmp_, T *val_) + inline T *cas (T *cmp_, T *val_) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_CXX11 _ptr.compare_exchange_strong (cmp_, val_, std::memory_order_acq_rel); @@ -240,11 +245,14 @@ template class atomic_ptr_t struct atomic_value_t { - atomic_value_t (const int value_) : _value (value_) {} + atomic_value_t (const int value_) ZMQ_NOEXCEPT : _value (value_) {} - atomic_value_t (const atomic_value_t &src_) : _value (src_.load ()) {} + atomic_value_t (const atomic_value_t &src_) ZMQ_NOEXCEPT + : _value (src_.load ()) + { + } - void store (const int value_) + void store (const int value_) ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_CXX11 _value.store (value_, std::memory_order_release); @@ -258,7 +266,7 @@ struct atomic_value_t #endif } - int load () const + int load () const ZMQ_NOEXCEPT { #if defined ZMQ_ATOMIC_PTR_CXX11 return _value.load (std::memory_order_acquire);