From 6137b485a08661b8e9d785bb049fbc54d7f261ec Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Fri, 30 Aug 2019 20:46:32 +0000 Subject: [PATCH 1/5] Problem: C++11 partially supported on gcc 4.8 Solution: Use intrinsic instead of std::is_trivially_copyable for gcc versions older than 5. --- README.md | 2 +- zmq.hpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0489c65..3d0c04d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Supported platforms - Additional platforms that are known to work: - We have no current reports on additional platforms that are known to work yet. Please add your platform here. If CI can be provided for them with a cloud-based CI service working with GitHub, you are invited to add CI, and make it possible to be included in the list above. - Additional platforms that probably work: - - Any platform supported by libzmq that provides a sufficiently recent gcc (4.8.1 or newer) or clang (3.3 or newer) + - Any platform supported by libzmq that provides a sufficiently recent gcc (4.8.1 or newer) or clang (3.4.1 or newer) - Visual Studio 2012+ x86/x64 Examples diff --git a/zmq.hpp b/zmq.hpp index 6791682..3b76a78 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -122,6 +122,14 @@ #define ZMQ_DELETED_FUNCTION #endif +#ifdef ZMQ_CPP11 +#if defined(__GNUC__) && __GNUC__ < 5 +#define ZMQ_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T) +#else +#define ZMQ_IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value +#endif +#endif + #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3, 3, 0) #define ZMQ_NEW_MONITOR_EVENT_LAYOUT #endif @@ -331,7 +339,7 @@ class message_t template::value - && std::is_trivially_copyable>::value + && ZMQ_IS_TRIVIALLY_COPYABLE(detail::range_value_t) && !std::is_same::value>::type> explicit message_t(const Range &rng) : message_t(detail::ranges::begin(rng), detail::ranges::end(rng)) @@ -948,7 +956,7 @@ template struct is_pod_like // trivially copyable OR standard layout. // Here we decide to be conservative and require both. static constexpr bool value = - std::is_trivially_copyable::value && std::is_standard_layout::value; + ZMQ_IS_TRIVIALLY_COPYABLE(T) && std::is_standard_layout::value; }; template constexpr auto seq_size(const C &c) noexcept -> decltype(c.size()) From b6765e56923f6a4fef8fd58c771ce76f4147d3a4 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Fri, 30 Aug 2019 21:31:31 +0000 Subject: [PATCH 2/5] Add GCC 4.9 to travis tests --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 90557f4..b1ee2d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,6 +60,17 @@ matrix: env: - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6" + # GCC 4.9, draft disabled (default), latest libzmq (default) + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.9 + env: + - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9" + # GCC 7, draft enabled, latest libzmq (default) - os: linux addons: From 9b20c461a0be64dec1a6e60715efad19e86d26f1 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Fri, 30 Aug 2019 22:23:52 +0000 Subject: [PATCH 3/5] Use C++11 when testing with GCC 4.9 --- .travis.yml | 2 +- ci_build.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b1ee2d8..9b34cd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ matrix: packages: - g++-4.9 env: - - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9" + - MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9" CMAKE_CPP_STD=-DCMAKE_CXX_STANDARD=11 # GCC 7, draft enabled, latest libzmq (default) - os: linux diff --git a/ci_build.sh b/ci_build.sh index e2beb49..cb182c4 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -39,7 +39,8 @@ cppzmq_build() { pushd . CMAKE_PREFIX_PATH=${LIBZMQ} \ cmake -H. -B${CPPZMQ} -DENABLE_DRAFTS=${ENABLE_DRAFTS} \ - -DCOVERAGE=${COVERAGE} + -DCOVERAGE=${COVERAGE} \ + ${CMAKE_CPP_STD:-} cmake --build ${CPPZMQ} -- -j${JOBS} popd } From 9e0b9b4a386108fd272544beedc050b820d96248 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Fri, 30 Aug 2019 22:33:49 +0000 Subject: [PATCH 4/5] Fix tests --- tests/socket_ref.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/socket_ref.cpp b/tests/socket_ref.cpp index 8a10344..dc2461a 100644 --- a/tests/socket_ref.cpp +++ b/tests/socket_ref.cpp @@ -7,7 +7,7 @@ static_assert(std::is_nothrow_swappable_v); #endif static_assert(sizeof(zmq::socket_ref) == sizeof(void *), "size mismatch"); static_assert(alignof(zmq::socket_ref) == alignof(void *), "alignment mismatch"); -static_assert(std::is_trivially_copyable::value, +static_assert(ZMQ_IS_TRIVIALLY_COPYABLE(zmq::socket_ref), "needs to be trivially copyable"); TEST_CASE("socket_ref default init", "[socket_ref]") From 4f1ff4952df682c6dfe243fd4e879c9aaec06af2 Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Fri, 30 Aug 2019 23:14:16 +0000 Subject: [PATCH 5/5] Fix for lacking SFINAE support on older GCC --- tests/utilities.cpp | 18 +++++++++--------- zmq.hpp | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/utilities.cpp b/tests/utilities.cpp index c7b8c99..9f1e2f2 100644 --- a/tests/utilities.cpp +++ b/tests/utilities.cpp @@ -1,7 +1,7 @@ #include #include -#ifdef ZMQ_CPP11 +#if defined(ZMQ_CPP11) && !defined(ZMQ_CPP11_PARTIAL) namespace test_ns { @@ -16,11 +16,11 @@ struct T_mr struct T_fr { }; -void *begin(const T_fr &) noexcept +inline void *begin(const T_fr &) noexcept { return nullptr; } -void *end(const T_fr &) noexcept +inline void *end(const T_fr &) noexcept { return nullptr; } @@ -29,11 +29,11 @@ struct T_mfr void *begin() const noexcept { return nullptr; } void *end() const noexcept { return nullptr; } }; -void *begin(const T_mfr &) noexcept +inline void *begin(const T_mfr &) noexcept { return nullptr; } -void *end(const T_mfr &) noexcept +inline void *end(const T_mfr &) noexcept { return nullptr; } @@ -50,11 +50,11 @@ struct T_assoc_ns_mr : std::exception struct T_assoc_ns_fr : std::exception { }; -void *begin(const T_assoc_ns_fr &) noexcept +inline void *begin(const T_assoc_ns_fr &) noexcept { return nullptr; } -void *end(const T_assoc_ns_fr &) noexcept +inline void *end(const T_assoc_ns_fr &) noexcept { return nullptr; } @@ -63,11 +63,11 @@ struct T_assoc_ns_mfr : std::exception void *begin() const noexcept { return nullptr; } void *end() const noexcept { return nullptr; } }; -void *begin(const T_assoc_ns_mfr &) noexcept +inline void *begin(const T_assoc_ns_mfr &) noexcept { return nullptr; } -void *end(const T_assoc_ns_mfr &) noexcept +inline void *end(const T_assoc_ns_mfr &) noexcept { return nullptr; } diff --git a/zmq.hpp b/zmq.hpp index 3b76a78..c86be81 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -122,8 +122,12 @@ #define ZMQ_DELETED_FUNCTION #endif +#if defined(ZMQ_CPP11) && defined(__GNUC__) && __GNUC__ < 5 +#define ZMQ_CPP11_PARTIAL +#endif + #ifdef ZMQ_CPP11 -#if defined(__GNUC__) && __GNUC__ < 5 +#ifdef ZMQ_CPP11_PARTIAL #define ZMQ_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T) #else #define ZMQ_IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value @@ -335,7 +339,7 @@ class message_t throw error_t(); } -#ifdef ZMQ_CPP11 +#if defined(ZMQ_CPP11) && !defined(ZMQ_CPP11_PARTIAL) template::value