Skip to content

Commit

Permalink
Removed warnings when compiling with C++11 enabled (zeromq#296)
Browse files Browse the repository at this point in the history
* Removed warnings when compiling with C++11 enabled

* ZMQ_NOTHROW now means throw() for pre-C++11
  • Loading branch information
ivan-cukic authored and sigiesec committed Mar 13, 2019
1 parent 0fd9bea commit 7d59f12
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
#define ZMQ_NOTHROW noexcept
#define ZMQ_EXPLICIT explicit
#define ZMQ_OVERRIDE override
#define ZMQ_NULLPTR nullptr
#else
#define ZMQ_CPP03
#define ZMQ_NOTHROW
#define ZMQ_NOTHROW throw()
#define ZMQ_EXPLICIT
#define ZMQ_OVERRIDE
#define ZMQ_NULLPTR 0
#endif

#include <zmq.h>
Expand All @@ -61,8 +63,8 @@

/* Version macros for compile-time API version detection */
#define CPPZMQ_VERSION_MAJOR 4
#define CPPZMQ_VERSION_MINOR 3
#define CPPZMQ_VERSION_PATCH 1
#define CPPZMQ_VERSION_MINOR 3
#define CPPZMQ_VERSION_PATCH 1

#define CPPZMQ_VERSION \
ZMQ_MAKE_VERSION(CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, \
Expand Down Expand Up @@ -138,11 +140,7 @@ class error_t : public std::exception
{
public:
error_t() : errnum(zmq_errno()) {}
#ifdef ZMQ_CPP11
virtual const char *what() const noexcept { return zmq_strerror(errnum); }
#else
virtual const char *what() const throw() { return zmq_strerror(errnum); }
#endif
virtual const char *what() const ZMQ_NOTHROW ZMQ_OVERRIDE { return zmq_strerror(errnum); }
int num() const { return errnum; }

private:
Expand Down Expand Up @@ -253,7 +251,7 @@ class message_t
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_);
if (rc != 0)
Expand Down Expand Up @@ -319,7 +317,7 @@ class message_t
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);
if (rc != 0)
Expand Down Expand Up @@ -399,7 +397,7 @@ class message_t
inline const char *gets(const char *property_)
{
const char *value = zmq_msg_gets(&msg, property_);
if (value == NULL)
if (value == ZMQ_NULLPTR)
throw error_t();
return value;
}
Expand Down Expand Up @@ -488,7 +486,7 @@ class context_t
inline context_t()
{
ptr = zmq_ctx_new();
if (ptr == NULL)
if (ptr == ZMQ_NULLPTR)
throw error_t();
}

Expand All @@ -497,7 +495,7 @@ class context_t
int max_sockets_ = ZMQ_MAX_SOCKETS_DFLT)
{
ptr = zmq_ctx_new();
if (ptr == NULL)
if (ptr == ZMQ_NULLPTR)
throw error_t();

int rc = zmq_ctx_set(ptr, ZMQ_IO_THREADS, io_threads_);
Expand All @@ -508,7 +506,7 @@ class context_t
}

#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
{
std::swap(ptr, rhs.ptr);
Expand All @@ -529,7 +527,7 @@ class context_t

inline void close() ZMQ_NOTHROW
{
if (ptr == NULL)
if (ptr == ZMQ_NULLPTR)
return;

int rc;
Expand All @@ -538,7 +536,7 @@ class context_t
} while (rc == -1 && errno == EINTR);

ZMQ_ASSERT(rc == 0);
ptr = NULL;
ptr = ZMQ_NULLPTR;
}

// Be careful with this, it's probably only useful for
Expand All @@ -548,7 +546,7 @@ class context_t

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:
void *ptr;
Expand Down Expand Up @@ -600,8 +598,8 @@ class socket_t
#ifdef ZMQ_HAS_RVALUE_REFS
inline socket_t(socket_t &&rhs) ZMQ_NOTHROW : ptr(rhs.ptr), ctxptr(rhs.ctxptr)
{
rhs.ptr = NULL;
rhs.ctxptr = NULL;
rhs.ptr = ZMQ_NULLPTR;
rhs.ctxptr = ZMQ_NULLPTR;
}
inline socket_t &operator=(socket_t &&rhs) ZMQ_NOTHROW
{
Expand All @@ -618,12 +616,12 @@ class socket_t

inline void close() ZMQ_NOTHROW
{
if (ptr == NULL)
if (ptr == ZMQ_NULLPTR)
// already closed
return;
int rc = zmq_close(ptr);
ZMQ_ASSERT(rc == 0);
ptr = 0;
ptr = ZMQ_NULLPTR;
}

template<typename T> void setsockopt(int option_, T const &optval)
Expand Down Expand Up @@ -689,7 +687,7 @@ class socket_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)
{
Expand Down Expand Up @@ -762,7 +760,7 @@ class socket_t
{
ctxptr = context_.ptr;
ptr = zmq_socket(context_.ptr, type_);
if (ptr == NULL)
if (ptr == ZMQ_NULLPTR)
throw error_t();
}

Expand All @@ -776,12 +774,12 @@ class socket_t
class monitor_t
{
public:
monitor_t() : socketPtr(NULL), monitor_socket(NULL) {}
monitor_t() : socketPtr(ZMQ_NULLPTR), monitor_socket(ZMQ_NULLPTR) {}

virtual ~monitor_t()
{
if (socketPtr)
zmq_socket_monitor(socketPtr, NULL, 0);
zmq_socket_monitor(socketPtr, ZMQ_NULLPTR, 0);

if (monitor_socket)
zmq_close(monitor_socket);
Expand All @@ -792,8 +790,8 @@ class monitor_t
monitor_t(monitor_t &&rhs) ZMQ_NOTHROW : socketPtr(rhs.socketPtr),
monitor_socket(rhs.monitor_socket)
{
rhs.socketPtr = NULL;
rhs.monitor_socket = NULL;
rhs.socketPtr = ZMQ_NULLPTR;
rhs.monitor_socket = ZMQ_NULLPTR;
}

socket_t &operator=(socket_t &&rhs) ZMQ_DELETED_FUNCTION;
Expand Down Expand Up @@ -963,9 +961,9 @@ class monitor_t
void abort()
{
if (socketPtr)
zmq_socket_monitor(socketPtr, NULL, 0);
zmq_socket_monitor(socketPtr, ZMQ_NULLPTR, 0);

socketPtr = NULL;
socketPtr = ZMQ_NULLPTR;
}
#endif
virtual void on_monitor_started() {}
Expand Down

0 comments on commit 7d59f12

Please sign in to comment.