zeromq / cppzmq

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

Seemingly unavoidable deprecation warning when using `send()` #330

Closed themightyoarfish closed 4 years ago

themightyoarfish commented 5 years ago

I have the following sample program

#include <zmq.hpp>

int main()
{
    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_REQ);
    zmq::message_t request(10);
    zmq::detail::send_result_t res = socket.send(request, zmq::send_flags::none);
}

which I compile like this:

clang zmq_test.cpp -lzmq -lstdc++ -std=gnu++14

This yields the warning

In file included from zmq_test.cpp:1:
/usr/local/include/zmq.hpp:1205:16: warning: 'send' is deprecated: from 4.3.1, use send taking message_t and send_flags [-Wdeprecated-declarations]
        return send(msg, flags_);
               ^
/usr/local/include/zmq.hpp:1189:5: note: 'send' has been explicitly marked deprecated here
    ZMQ_DEPRECATED("from 4.3.1, use send taking message_t and send_flags")
    ^
/usr/local/include/zmq.hpp:41:31: note: expanded from macro 'ZMQ_DEPRECATED'
#define ZMQ_DEPRECATED(msg) [[deprecated(msg)]]
                              ^
1 warning generated.

Which tells me I should use the overload of send() which takes message_t and send_flags as parameters. However, this appears to be exactly what I'm doing. The warning comes from

https://github.com/zeromq/cppzmq/blob/4e37816dfaf0240e6eb5635f176a8794d107e492/zmq.hpp#L1205

which tells me the intended overload at

https://github.com/zeromq/cppzmq/blob/4e37816dfaf0240e6eb5635f176a8794d107e492/zmq.hpp#L1235

is not called. (I guess because zmq::send_flags is an int subtype and zmq::detail::send_result_t can be assigned a bool value?)

I don't have a good understanding of C++ overload resolution, but it seems there is no way to call the version of send() that is recommended by the deprecation warning.

What is the recommended way to adapt the code to avoid this warning?

walchko commented 5 years ago

I get both send and recv warnings:

/Users/kevin/github/gecko/cppzmq/zmq.hpp:1205:16: warning: 'send' is deprecated:
      from 4.3.1, use send taking message_t and send_flags
      [-Wdeprecated-declarations]
        return send(msg, flags_);
               ^
/Users/kevin/github/gecko/cppzmq/zmq.hpp:1189:5: note: 'send' has been
      explicitly marked deprecated here
    ZMQ_DEPRECATED("from 4.3.1, use send taking message_t and send_flags")
    ^
/Users/kevin/github/gecko/cppzmq/zmq.hpp:41:31: note: expanded from macro
      'ZMQ_DEPRECATED'
#define ZMQ_DEPRECATED(msg) [[deprecated(msg)]]
                              ^
/Users/kevin/github/gecko/src/zmq_rep_req.cpp:20:10: warning: 'recv' is
      deprecated: from 4.3.1, use recv taking a reference to message_t and
      recv_flags [-Wdeprecated-declarations]
    sock.recv (&request, flags);
         ^
/Users/kevin/github/gecko/cppzmq/zmq.hpp:1265:5: note: 'recv' has been
      explicitly marked deprecated here
    ZMQ_DEPRECATED("from 4.3.1, use recv taking a reference to message_...
    ^
/Users/kevin/github/gecko/cppzmq/zmq.hpp:41:31: note: expanded from macro
      'ZMQ_DEPRECATED'
#define ZMQ_DEPRECATED(msg) [[deprecated(msg)]]

I am using macOS 10.14.5

kurdybacha commented 5 years ago

what version of clang do you use?

walchko commented 5 years ago

macOS:

(cv) kevin@Logan ~ $ /Library/Developer/CommandLineTools/usr/bin/c++ --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Also in my CMake file I turned on C++17:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Some output from the compile process:

 92%] Building CXX object gtests/CMakeFiles/ascii-gtest.dir/ascii-gtest.cpp.o
cd /Users/kevin/github/gecko/build/gtests && /Library/Developer/CommandLineTools/usr/bin/c++   -I/usr/local/include -I/Users/kevin/github/gecko/extlibs/nlohmann-json/include -I/usr/local/Cellar/zeromq/4.3.1_1/include -I/Users/kevin/github/gecko/extlibs/cppzmq -I/Users/kevin/github/gecko/src -I/Users/kevin/github/gecko/. -I/Users/kevin/github/gecko/extlibs/gecko-msgpack -isystem /Users/kevin/github/gecko/build/gtests/googletest-src/googletest/include -isystem /Users/kevin/github/gecko/build/gtests/googletest-src/googletest  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk   -std=c++1z -o CMakeFiles/ascii-gtest.dir/ascii-gtest.cpp.o -c /Users/kevin/github/gecko/gtests/ascii-gtest.cpp
[ 95%] Linking CXX executable ascii-gtest
cd /Users/kevin/github/gecko/build/gtests && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/ascii-gtest.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/ascii-gtest.dir/ascii-gtest.cpp.o  -o ascii-gtest  -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,-rpath,/Users/kevin/github/gecko/build ../lib/libgtest_main.a -lzmq -lzmq ../libgecko.dylib -lmsgpackc ../lib/libgtest.a -lzmq 
[ 95%] Built target ascii-gtest
/Library/Developer/CommandLineTools/usr/bin/make -f gtests/CMakeFiles/zmq-gtest.dir/build.make gtests/CMakeFiles/zmq-gtest.dir/depend
cd /Users/kevin/github/gecko/build && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_depends "Unix Makefiles" /Users/kevin/github/gecko /Users/kevin/github/gecko/gtests /Users/kevin/github/gecko/build /Users/kevin/github/gecko/build/gtests /Users/kevin/github/gecko/build/gtests/CMakeFiles/zmq-gtest.dir/DependInfo.cmake --color=
/Library/Developer/CommandLineTools/usr/bin/make -f gtests/CMakeFiles/zmq-gtest.dir/build.make gtests/CMakeFiles/zmq-gtest.dir/build
[ 97%] Building CXX object gtests/CMakeFiles/zmq-gtest.dir/zmq-gtest.cpp.o
cd /Users/kevin/github/gecko/build/gtests && /Library/Developer/CommandLineTools/usr/bin/c++   -I/usr/local/include -I/Users/kevin/github/gecko/extlibs/nlohmann-json/include -I/usr/local/Cellar/zeromq/4.3.1_1/include -I/Users/kevin/github/gecko/extlibs/cppzmq -I/Users/kevin/github/gecko/src -I/Users/kevin/github/gecko/. -I/Users/kevin/github/gecko/extlibs/gecko-msgpack -isystem /Users/kevin/github/gecko/build/gtests/googletest-src/googletest/include -isystem /Users/kevin/github/gecko/build/gtests/googletest-src/googletest  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk   -std=c++1z -o CMakeFiles/zmq-gtest.dir/zmq-gtest.cpp.o -c /Users/kevin/github/gecko/gtests/zmq-gtest.cpp
In file included from /Users/kevin/github/gecko/gtests/zmq-gtest.cpp:2:
In file included from /Users/kevin/github/gecko/src/gecko/gecko.hpp:9:
In file included from /Users/kevin/github/gecko/src/gecko/geckocpp.hpp:9:
In file included from /Users/kevin/github/gecko/src/gecko/transport.hpp:10:
/Users/kevin/github/gecko/extlibs/cppzmq/zmq.hpp:1205:16: warning: 'send' is
      deprecated: from 4.3.1, use send taking message_t and send_flags
      [-Wdeprecated-declarations]
        return send(msg, flags_);
               ^
/Users/kevin/github/gecko/extlibs/cppzmq/zmq.hpp:1189:5: note: 'send' has been
      explicitly marked deprecated here
    ZMQ_DEPRECATED("from 4.3.1, use send taking message_t and send_flags")
    ^
/Users/kevin/github/gecko/extlibs/cppzmq/zmq.hpp:41:31: note: expanded from
      macro 'ZMQ_DEPRECATED'
#define ZMQ_DEPRECATED(msg) [[deprecated(msg)]]
                              ^
1 warning generated.
[100%] Linking CXX executable zmq-gtest
cd /Users/kevin/github/gecko/build/gtests && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/zmq-gtest.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/zmq-gtest.dir/zmq-gtest.cpp.o  -o zmq-gtest  -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,-rpath,/Users/kevin/github/gecko/build ../lib/libgtest_main.a -lzmq -lzmq ../libgecko.dylib -lmsgpackc ../lib/libgtest.a -lzmq 
[100%] Built target zmq-gtest
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/kevin/github/gecko/build/CMakeFiles 0

linux:

I compile the same code on linux too and get the same errors

(.venv) kevin@dalek ~ $ g++ --version
g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
themightyoarfish commented 5 years ago

My clang version is

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
crashflow commented 5 years ago

same issue

Apple LLVM version 9.0.0 (clang-900.0.39.2) Target: x86_64-apple-darwin18.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

gummif commented 5 years ago

There is a PR #337 that hopefully solves this issue.

erblinium commented 5 years ago

Is this issue solved yet? I am still getting the same errors as @walchko: Severity Code Description Project File Line Suppression State Error C4996 'zmq::detail::socket_base::send': from 4.3.1, use send taking message_t and send_flags ZeroMQ_HeiVerden c:\users\ujkanie2\source\repos\zeromq_heiverden\zeromq_heiverden\main.cpp 43 Error C4996 'zmq::detail::socket_base::recv': from 4.3.1, use recv taking a reference to message_t and recv_flags ZeroMQ_HeiVerden c:\users\ujkanie2\source\repos\zeromq_heiverden\zeromq_heiverden\main.cpp 34 I am running with the latest zmqcpp (static) v4.3.3 on visual studio 15 2017 x64. (I installed it through vcpkg)

sigiesec commented 5 years ago

The version containing #337 has not been released yet. I am not sure what you refer to by zmqcpp 4.3.3. There is no cppzmq version 4.3.3. The most recent version is https://github.com/zeromq/cppzmq/releases/tag/v4.4.1

I can release a new version (4.5.0) if that suits your needs.

erblinium commented 5 years ago

I refer to the latest packages zeromq:x64-windows-static and cppzmq_x64-windows-static that I installed through vcpkg. I checked the version with the function zmq_version(&major, &minor, &patch);. I am testing now to see wether the 4.4.1 version works. Right now I am just trying to run some basic ZeroMQ programs with C++ on Visual Studio. But It would be nice to get the latest version as well.

blue7676 commented 5 years ago

Got lost in this

On Wed, Sep 11, 2019, 6:47 AM Erblinium notifications@github.com wrote:

I refer to the latest package zeromq:x64-windows-static that I installed through vcpkg. I am testing now to see wether the 4.4.1 version works. Right now I am just trying to run some basic ZeroMQ programs with C++ on Visual Studio. But It would be nice to get the latest version as well.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zeromq/cppzmq/issues/330?email_source=notifications&email_token=AM4EL5CVJW3RLNJIQCXFRALQJDLGJA5CNFSM4HVBRGLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6OGWDA#issuecomment-530344716, or mute the thread https://github.com/notifications/unsubscribe-auth/AM4EL5EAGVRZNAAAJ6FCENLQJDLGJANCNFSM4HVBRGLA .

sigiesec commented 5 years ago

I am not familiar with vcpkg, and the organization of its packages (ports?). I assume zeromq is libzmq? This has a distinct versioning (in the past, there was an attempt to use the same version numbers, but since both evolve independently, this has proven to be even more confusing). cppzmq uses libzmq, and that is probably also true for the vcpkg ports.

As said, 4.4.1 doesn't contain gummif's fix for the warning. There's nothing standing in the way of releasing a new version from my side. However, when it is released, probably the vcpkg port must be explicitly updated, too.

erblinium commented 5 years ago

Yes, zeromq is libzmq. I am just dropping vckpkg, I'll just build it from source with CMake from now on.

I see that the supported platforms of libzmq for Visual Studio are only x86, will there be support for x64 as well?

sigiesec commented 5 years ago

I see that the supported platforms of libzmq for Visual Studio are only x86, will there be support for x64 as well?

That's not true, x64 is supported as well. Where is this information from?

erblinium commented 5 years ago

In the README.md file under the source code of libzmq. I see only x86 architecture is supported here:

Supported platforms with primary CI

OS and version Architecture Compiler and version Build system Remarks
Android NDK 11c ARM gcc ? autotools
Ubuntu 14.04.5 LTS (trusty) amd64 clang 5.0.0 autotools STABLE, extras: GSSAPI, PGM, NORM, C++98 mode only
Ubuntu 14.04.5 LTS (trusty) amd64 gcc 4.8.4 autotools STABLE, DRAFT, extras: GSSAPI, PGM, NORM, TIPC, IPV6, also POLLER=poll, POLLER=select, also valgrind and address sanitizer executions
Ubuntu 14.04.5 LTS (trusty) amd64 gcc 4.8.4 CMake 3.12.2 STABLE
Windows Server 2012 R2 x86 Visual Studio 2008 CMake 3.12.2 DRAFT
Windows Server 2012 R2 x86 Visual Studio 2010 SP1 CMake 3.12.2 DRAFT
Windows Server 2012 R2 x86 Visual Studio 2012 Update 5 CMake 3.12.2 DRAFT
Windows Server 2012 R2 x86, amd64 Visual Studio 2013 Update 5 CMake 3.12.2 DRAFT, STABLE (x86 Release only), also POLLER=epoll
Windows Server 2012 R2 x86 Visual Studio 2015 Update 3 CMake 3.12.2 DRAFT
Windows Server 2016 x86 Visual Studio 2017 15.9.6 CMake 3.13.3 DRAFT
cygwin 3.0.0 on Windows Server 2012 R2 amd64 gcc 7.4.0 CMake 3.6.2 DRAFT
MSYS2 ? on Windows Server 2012 R2 amd64 gcc 6.4.0 CMake ? DRAFT
Mac OS X 10.13 amd64 Xcode 9.4.1, Apple LLVM 9.1.0 autotools STABLE, DRAFT
Mac OS X 10.13 amd64 Xcode 9.4.1, Apple LLVM 9.1.0 CMake 3.11.4 DRAFT
sigiesec commented 5 years ago

The list includes:

OS and version Architecture Compiler and version Build system Remarks
Windows Server 2012 R2 x86, amd64 Visual Studio 2013 Update 5 CMake 3.12.2 DRAFT, STABLE (x86 Release only), also POLLER=epoll

amd64 probably refers to what you want (see https://unix.stackexchange.com/questions/53415/why-are-64-bit-distros-often-called-amd64), this should probably be made clearer within the readme.

This is maybe not that visible in the list, given that all other Windows variants are only x86 (I am not sure why). However, note that this is not a complete list of supported platforms anyway, just those that CI jobs are run for every PR. However, the Windows support should be obviously be displayed clearer.

blue7676 commented 5 years ago

Thank you butt I think I did something different. And this is not what I want

On Sun, Sep 29, 2019, 4:35 PM Matt DeBoer notifications@github.com wrote:

Note: after compiling with current master (which contains merged #337 https://github.com/zeromq/cppzmq/pull/337), I still encounter the same compile warnings.

compiler: gcc/g++ 9.2.1 cmake: 3.13.4 arch: x86_64 os: ubuntu 19.04

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/zeromq/cppzmq/issues/330?email_source=notifications&email_token=AM4EL5F4SPB7CBLK4YQGOADQMENSVA5CNFSM4HVBRGLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD737HIA#issuecomment-536343456, or mute the thread https://github.com/notifications/unsubscribe-auth/AM4EL5BH6E4LBS7HSXQVHXLQMENSVANCNFSM4HVBRGLA .

abuzatu commented 5 years ago

@sigiesec, I also see these two warnings (interpreted as error by CMake for safety) on MacOS 10.14.6, with the latest versions of

brew install zmq
brew install cppzmq

You mentioned it is easy to create a new version of cppzqm that could be updated with brew? I would be happy to update to that, and not get the warnings interpreted as compilation errors. Would that be possible from your side?

Thank you, Adrian

gummif commented 5 years ago

There is still a warning in the tests (verifying old functionality). Do you get the warning when you install the package?

abuzatu commented 5 years ago

Hi gummif,

I get the warnings when I compile an executable using the package.

 warning: 'recv' is deprecated: from 4.3.1, use recv taking a
      reference to message_t and recv_flags [-Wdeprecated-declarations]
            if (subscriber.recv(&msg, ZMQ_DONTWAIT) == true)

and

 warning: 'send' is deprecated: from 4.3.1, use send taking
      message_t and send_flags [-Wdeprecated-declarations]
    bool rc = publisher.send(msg);

In addition but from another reason many of type

 warning: 'glBegin' is deprecated: first deprecated in macOS 10.14 - OpenGL API deprecated.
      (Define GL_SILENCE_DEPRECATION to silence these warnings) [-Wdeprecated-declarations]
  glBegin(GL_POINTS);

like glClear, glPushMatrix, glPointSize, glBegin, glVertex3f, glColor3ub, glEnd, glPopMatrix, glutSwapBuffers, etc.

daravi commented 4 years ago

I can confirm that using cppzmq 4.5.0 with libzmq 4.3.2 and llvm 9.0 this issue is resolved.

sigiesec commented 4 years ago

@daravi Thanks for the report! So we can close this issue now.