From 63250e15e8486dab1e5c9a33753e753aae8652b1 Mon Sep 17 00:00:00 2001 From: Girts Folkmanis Date: Tue, 28 May 2019 14:14:04 -0700 Subject: [PATCH] make poller_t work with ancient gcc 4.8.1 For some reason that I didn't get to the root cause, gcc 4.8.1 (that I'm stuck with) does not like the initializer for `unique_ptr` implemented as a lambda: ``` third_party/zmqcpp/repo/zmq.hpp: In constructor 'zmq::poller_t::poller_t() [with T = std::function]': third_party/zmqcpp/repo/zmq.hpp:1871:5: error: converting to 'std::unique_ptr >::destroy_poller_t>' from initializer list would use explicit constructor 'std::unique_ptr<_Ty, _Dx>::unique_ptr(std::unique_ptr<_Ty, _Dx>::pointer) [with _Ty = void; _Dx = zmq::poller_t >::destroy_poller_t; std::unique_ptr<_Ty, _Dx>::pointer = void*]' poller_t() = default; ^ In file included from networking/ipc/ipc.cc:6:0: third_party/zmqcpp/repo/zmq_addon.hpp: At global scope: third_party/zmqcpp/repo/zmq_addon.hpp:447:40: note: synthesized method 'zmq::poller_t::poller_t() [with T = std::function]' first required here poller_t base_poller{}; ^ In file included from ./networking/ipc/ipc.h:13:0, from networking/ipc/ipc.cc:1: third_party/zmqcpp/repo/zmq.hpp: In constructor 'zmq::poller_t::poller_t() [with T = zmq::socket_t]': third_party/zmqcpp/repo/zmq.hpp:1871:5: error: converting to 'std::unique_ptr::destroy_poller_t>' from initializer list would use explicit constructor 'std::unique_ptr<_Ty, _Dx>::unique_ptr(std::unique_ptr<_Ty, _Dx>::pointer) [with _Ty = void; _Dx = zmq::poller_t::destroy_poller_t; std::unique_ptr<_Ty, _Dx>::pointer = void*]' poller_t() = default; ^ networking/ipc/ipc.cc: In member function 'void networking::ipc::Ipc::ThreadMain()': networking/ipc/ipc.cc:313:36: note: synthesized method 'zmq::poller_t::poller_t() [with T = zmq::socket_t]' first required here ::zmq::poller_t<::zmq::socket_t> poller; ^ ``` This moves the initialization to constructor, and makes gcc happy. --- zmq.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/zmq.hpp b/zmq.hpp index 58c688f..b59d41b 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -1868,7 +1868,11 @@ template class poller_t public: using event_type = poller_event; - poller_t() = default; + poller_t() : poller_ptr(zmq_poller_new()) + { + if (!poller_ptr) + throw error_t(); + } template< typename Dummy = void, @@ -1931,13 +1935,7 @@ template class poller_t } }; - std::unique_ptr poller_ptr{ - []() { - auto poller_new = zmq_poller_new(); - if (poller_new) - return poller_new; - throw error_t(); - }()}; + std::unique_ptr poller_ptr; void add_impl(zmq::socket_ref socket, event_flags events, T *user_data) {