Removed warnings when compiling with C++11 enabled (#296)

* Removed warnings when compiling with C++11 enabled

* ZMQ_NOTHROW now means throw() for pre-C++11
This commit is contained in:
Ivan Čukić 2019-03-13 19:18:27 +01:00 committed by Simon Giesecke
parent 0fd9bea760
commit 7d59f129c8

56
zmq.hpp
View File

@ -39,11 +39,13 @@
#define ZMQ_NOTHROW noexcept #define ZMQ_NOTHROW noexcept
#define ZMQ_EXPLICIT explicit #define ZMQ_EXPLICIT explicit
#define ZMQ_OVERRIDE override #define ZMQ_OVERRIDE override
#define ZMQ_NULLPTR nullptr
#else #else
#define ZMQ_CPP03 #define ZMQ_CPP03
#define ZMQ_NOTHROW #define ZMQ_NOTHROW throw()
#define ZMQ_EXPLICIT #define ZMQ_EXPLICIT
#define ZMQ_OVERRIDE #define ZMQ_OVERRIDE
#define ZMQ_NULLPTR 0
#endif #endif
#include <zmq.h> #include <zmq.h>
@ -61,8 +63,8 @@
/* Version macros for compile-time API version detection */ /* Version macros for compile-time API version detection */
#define CPPZMQ_VERSION_MAJOR 4 #define CPPZMQ_VERSION_MAJOR 4
#define CPPZMQ_VERSION_MINOR 3 #define CPPZMQ_VERSION_MINOR 3
#define CPPZMQ_VERSION_PATCH 1 #define CPPZMQ_VERSION_PATCH 1
#define CPPZMQ_VERSION \ #define CPPZMQ_VERSION \
ZMQ_MAKE_VERSION(CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, \ ZMQ_MAKE_VERSION(CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, \
@ -138,11 +140,7 @@ class error_t : public std::exception
{ {
public: public:
error_t() : errnum(zmq_errno()) {} error_t() : errnum(zmq_errno()) {}
#ifdef ZMQ_CPP11 virtual const char *what() const ZMQ_NOTHROW ZMQ_OVERRIDE { return zmq_strerror(errnum); }
virtual const char *what() const noexcept { return zmq_strerror(errnum); }
#else
virtual const char *what() const throw() { return zmq_strerror(errnum); }
#endif
int num() const { return errnum; } int num() const { return errnum; }
private: private:
@ -253,7 +251,7 @@ class message_t
memcpy(data(), data_, size_); memcpy(data(), data_, size_);
} }
inline message_t(void *data_, size_t size_, free_fn *ffn_, void *hint_ = NULL) inline message_t(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)
{ {
int rc = zmq_msg_init_data(&msg, data_, size_, ffn_, hint_); int rc = zmq_msg_init_data(&msg, data_, size_, ffn_, hint_);
if (rc != 0) if (rc != 0)
@ -319,7 +317,7 @@ class message_t
memcpy(data(), data_, size_); memcpy(data(), data_, size_);
} }
inline void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_ = NULL) inline void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_ = ZMQ_NULLPTR)
{ {
int rc = zmq_msg_close(&msg); int rc = zmq_msg_close(&msg);
if (rc != 0) if (rc != 0)
@ -399,7 +397,7 @@ class message_t
inline const char *gets(const char *property_) inline const char *gets(const char *property_)
{ {
const char *value = zmq_msg_gets(&msg, property_); const char *value = zmq_msg_gets(&msg, property_);
if (value == NULL) if (value == ZMQ_NULLPTR)
throw error_t(); throw error_t();
return value; return value;
} }
@ -488,7 +486,7 @@ class context_t
inline context_t() inline context_t()
{ {
ptr = zmq_ctx_new(); ptr = zmq_ctx_new();
if (ptr == NULL) if (ptr == ZMQ_NULLPTR)
throw error_t(); throw error_t();
} }
@ -497,7 +495,7 @@ class context_t
int max_sockets_ = ZMQ_MAX_SOCKETS_DFLT) int max_sockets_ = ZMQ_MAX_SOCKETS_DFLT)
{ {
ptr = zmq_ctx_new(); ptr = zmq_ctx_new();
if (ptr == NULL) if (ptr == ZMQ_NULLPTR)
throw error_t(); throw error_t();
int rc = zmq_ctx_set(ptr, ZMQ_IO_THREADS, io_threads_); int rc = zmq_ctx_set(ptr, ZMQ_IO_THREADS, io_threads_);
@ -508,7 +506,7 @@ class context_t
} }
#ifdef ZMQ_HAS_RVALUE_REFS #ifdef ZMQ_HAS_RVALUE_REFS
inline context_t(context_t &&rhs) ZMQ_NOTHROW : ptr(rhs.ptr) { rhs.ptr = NULL; } inline context_t(context_t &&rhs) ZMQ_NOTHROW : ptr(rhs.ptr) { rhs.ptr = ZMQ_NULLPTR; }
inline context_t &operator=(context_t &&rhs) ZMQ_NOTHROW inline context_t &operator=(context_t &&rhs) ZMQ_NOTHROW
{ {
std::swap(ptr, rhs.ptr); std::swap(ptr, rhs.ptr);
@ -529,7 +527,7 @@ class context_t
inline void close() ZMQ_NOTHROW inline void close() ZMQ_NOTHROW
{ {
if (ptr == NULL) if (ptr == ZMQ_NULLPTR)
return; return;
int rc; int rc;
@ -538,7 +536,7 @@ class context_t
} while (rc == -1 && errno == EINTR); } while (rc == -1 && errno == EINTR);
ZMQ_ASSERT(rc == 0); ZMQ_ASSERT(rc == 0);
ptr = NULL; ptr = ZMQ_NULLPTR;
} }
// Be careful with this, it's probably only useful for // Be careful with this, it's probably only useful for
@ -548,7 +546,7 @@ class context_t
inline ZMQ_EXPLICIT operator void const *() const ZMQ_NOTHROW { return ptr; } inline ZMQ_EXPLICIT operator void const *() const ZMQ_NOTHROW { return ptr; }
inline operator bool() const ZMQ_NOTHROW { return ptr != NULL; } inline operator bool() const ZMQ_NOTHROW { return ptr != ZMQ_NULLPTR; }
private: private:
void *ptr; void *ptr;
@ -600,8 +598,8 @@ class socket_t
#ifdef ZMQ_HAS_RVALUE_REFS #ifdef ZMQ_HAS_RVALUE_REFS
inline socket_t(socket_t &&rhs) ZMQ_NOTHROW : ptr(rhs.ptr), ctxptr(rhs.ctxptr) inline socket_t(socket_t &&rhs) ZMQ_NOTHROW : ptr(rhs.ptr), ctxptr(rhs.ctxptr)
{ {
rhs.ptr = NULL; rhs.ptr = ZMQ_NULLPTR;
rhs.ctxptr = NULL; rhs.ctxptr = ZMQ_NULLPTR;
} }
inline socket_t &operator=(socket_t &&rhs) ZMQ_NOTHROW inline socket_t &operator=(socket_t &&rhs) ZMQ_NOTHROW
{ {
@ -618,12 +616,12 @@ class socket_t
inline void close() ZMQ_NOTHROW inline void close() ZMQ_NOTHROW
{ {
if (ptr == NULL) if (ptr == ZMQ_NULLPTR)
// already closed // already closed
return; return;
int rc = zmq_close(ptr); int rc = zmq_close(ptr);
ZMQ_ASSERT(rc == 0); ZMQ_ASSERT(rc == 0);
ptr = 0; ptr = ZMQ_NULLPTR;
} }
template<typename T> void setsockopt(int option_, T const &optval) template<typename T> void setsockopt(int option_, T const &optval)
@ -689,7 +687,7 @@ class socket_t
throw error_t(); throw error_t();
} }
inline bool connected() const ZMQ_NOTHROW { return (ptr != NULL); } inline bool connected() const ZMQ_NOTHROW { return (ptr != ZMQ_NULLPTR); }
inline size_t send(const void *buf_, size_t len_, int flags_ = 0) inline size_t send(const void *buf_, size_t len_, int flags_ = 0)
{ {
@ -762,7 +760,7 @@ class socket_t
{ {
ctxptr = context_.ptr; ctxptr = context_.ptr;
ptr = zmq_socket(context_.ptr, type_); ptr = zmq_socket(context_.ptr, type_);
if (ptr == NULL) if (ptr == ZMQ_NULLPTR)
throw error_t(); throw error_t();
} }
@ -776,12 +774,12 @@ class socket_t
class monitor_t class monitor_t
{ {
public: public:
monitor_t() : socketPtr(NULL), monitor_socket(NULL) {} monitor_t() : socketPtr(ZMQ_NULLPTR), monitor_socket(ZMQ_NULLPTR) {}
virtual ~monitor_t() virtual ~monitor_t()
{ {
if (socketPtr) if (socketPtr)
zmq_socket_monitor(socketPtr, NULL, 0); zmq_socket_monitor(socketPtr, ZMQ_NULLPTR, 0);
if (monitor_socket) if (monitor_socket)
zmq_close(monitor_socket); zmq_close(monitor_socket);
@ -792,8 +790,8 @@ class monitor_t
monitor_t(monitor_t &&rhs) ZMQ_NOTHROW : socketPtr(rhs.socketPtr), monitor_t(monitor_t &&rhs) ZMQ_NOTHROW : socketPtr(rhs.socketPtr),
monitor_socket(rhs.monitor_socket) monitor_socket(rhs.monitor_socket)
{ {
rhs.socketPtr = NULL; rhs.socketPtr = ZMQ_NULLPTR;
rhs.monitor_socket = NULL; rhs.monitor_socket = ZMQ_NULLPTR;
} }
socket_t &operator=(socket_t &&rhs) ZMQ_DELETED_FUNCTION; socket_t &operator=(socket_t &&rhs) ZMQ_DELETED_FUNCTION;
@ -963,9 +961,9 @@ class monitor_t
void abort() void abort()
{ {
if (socketPtr) if (socketPtr)
zmq_socket_monitor(socketPtr, NULL, 0); zmq_socket_monitor(socketPtr, ZMQ_NULLPTR, 0);
socketPtr = NULL; socketPtr = ZMQ_NULLPTR;
} }
#endif #endif
virtual void on_monitor_started() {} virtual void on_monitor_started() {}