zeromq / cppzmq

Header-only C++ binding for libzmq
http://www.zeromq.org
MIT License
1.93k stars 757 forks source link

'recv' is deprecated: from 4.3.1, use recv taking a reference to message_t and recv_flags clang #556

Closed embeddedpenguin closed 2 years ago

embeddedpenguin commented 2 years ago

Warning:

'recv' is deprecated: from 4.3.1, use recv taking a reference to message_t and recv_flags clang (-Wdeprecated-declarations) [36, 11]

Snippet:

if (sub.recv(&msg, 0))
{...}

Can't really get around this warning, despite using the function with a flags argument like the warning wants.

gin-ahirsch commented 2 years ago

"taking a reference" refers to a C++ reference type, as can be seen in the type signature. Thus sub.recv(msg) (removing the & operator) should work to get rid of the warning.

embeddedpenguin commented 2 years ago

"taking a reference" refers to a C++ reference type, as can be seen in the type signature. Thus sub.recv(msg) (removing the & operator) should work to get rid of the warning.

Making this change causes a compilation error:

src/main.cpp:42:37: error: no matching function for call to ‘zmq::socket_t::recv(zmq::message_t&, int)’
   42 |                         if (sub.recv(msg_recv, 0))
      |                             ~~~~~~~~^~~~~~~~~~~~~
embeddedpenguin commented 2 years ago

Also, my signature is different than the one you've referenced.

#ifdef ZMQ_CPP11
    ZMQ_DEPRECATED("from 4.3.1, use recv taking a reference to message_t and recv_flags")
#endif
    bool recv(message_t *msg_, int flags_ = 0)
    {
        int nbytes = zmq_msg_recv(msg_->handle(), _handle, flags_);
        if (nbytes >= 0)
            return true;
        if (zmq_errno() == EAGAIN)
            return false;
        throw error_t();
    }

I'm compiling with -std=gnu++11. My zmq version is 4.6.0. Even when compiling with -std=gnu++17, the result is the same.

embeddedpenguin commented 2 years ago

Ok I see what's happening. Fixed by adding this:

if (sub.recv(msg_recv, zmq::recv_flags(0)))
{}