From 7ed7af90b673a51559c7ca10f9a4b7600dc48585 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 3 Jan 2020 06:52:15 -0500 Subject: [PATCH 1/3] Fix timespec_object.*_32bit_sec tests on 32-bit platforms On 32-bit unix platforms, 0xffffffffUL is a 32-bit value so the compiler complains about converting it to a signed value. /home/runner/work/msgpack-c/msgpack-c/test/msgpack_cpp11.cpp:1085:20: error: constant expression evaluates to 4294967295 which cannot be narrowed to type '__time_t' (aka 'long') [-Wc++11-narrowing] timespec val1{ 0xffffffffUL, 0 }; ^~~~~~~~~~~~ /home/runner/work/msgpack-c/msgpack-c/test/msgpack_cpp11.cpp:1085:20: note: insert an explicit cast to silence this issue timespec val1{ 0xffffffffUL, 0 }; ^~~~~~~~~~~~ static_cast<__time_t>( ) /home/runner/work/msgpack-c/msgpack-c/test/msgpack_cpp11.cpp:1085:20: warning: implicit conversion changes signedness: 'unsigned long' to '__time_t' (aka 'long') [-Wsign-conversion] timespec val1{ 0xffffffffUL, 0 }; ~ ^~~~~~~~~~~~ Since we're trying to test how the maximum 32-bit value that fits in timespec.tv_sec is handled, directly use the maximum 32-bit value for the appropriate (un)signed type used for timespec.tv_sec. We don't just cast to the value, as the compiler suggests, because that would result in an extremely negative value. --- test/msgpack_cpp11.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/msgpack_cpp11.cpp b/test/msgpack_cpp11.cpp index d69af910..e266da04 100644 --- a/test/msgpack_cpp11.cpp +++ b/test/msgpack_cpp11.cpp @@ -1082,7 +1082,7 @@ TEST(MSGPACK_TIMESPEC, timespec_object_with_zone_zero) TEST(MSGPACK_TIMESPEC, timespec_pack_convert_32bit_sec) { std::stringstream ss; - timespec val1{ 0xffffffffUL, 0 }; + timespec val1{ std::numeric_limits().tv_sec)>::is_signed ? INT32_MAX : UINT32_MAX, 0 }; msgpack::pack(ss, val1); std::string const& str = ss.str(); @@ -1098,7 +1098,7 @@ TEST(MSGPACK_TIMESPEC, timespec_pack_convert_32bit_sec) TEST(MSGPACK_TIMESPEC, timespec_object_with_zone_32bit_sec) { msgpack::zone z; - timespec val1{ 0xffffffffUL, 0 }; + timespec val1{ std::numeric_limits().tv_sec)>::is_signed ? INT32_MAX : UINT32_MAX, 0 }; msgpack::object obj(val1, z); timespec val2 = obj.as(); EXPECT_EQ(val1.tv_sec, val2.tv_sec); From f8b0ad1766653cf72dc03411a473fe92374c0de5 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 3 Jan 2020 07:37:59 -0500 Subject: [PATCH 2/3] Skip timespec_pack_convert_64bit_sec_max_nano on systems where tv_sec <= 32-bit --- test/msgpack_cpp11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/msgpack_cpp11.cpp b/test/msgpack_cpp11.cpp index e266da04..bd367952 100644 --- a/test/msgpack_cpp11.cpp +++ b/test/msgpack_cpp11.cpp @@ -1188,6 +1188,7 @@ TEST(MSGPACK_TIMESPEC, timespec_object_with_zone_35bit_sec_max_nano) TEST(MSGPACK_TIMESPEC, timespec_pack_convert_64bit_sec_max_nano) { + if (sizeof(decltype(std::declval().tv_sec)) <= 4) return; std::stringstream ss; timespec val1{ std::numeric_limits().tv_sec)>::max(), 999999999 }; From 0d7caecdb5466e1a946e11eeb24f3c787aeaadfa Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Mon, 6 Jan 2020 13:04:14 +0900 Subject: [PATCH 3/3] Fixed cmake condition. If MSGPACK_CXX17 is ON then build MSGPACK_CXX11 target. --- example/cpp11/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/cpp11/CMakeLists.txt b/example/cpp11/CMakeLists.txt index c932a603..eb085ed1 100644 --- a/example/cpp11/CMakeLists.txt +++ b/example/cpp11/CMakeLists.txt @@ -1,4 +1,4 @@ -IF (MSGPACK_CXX11) +IF (MSGPACK_CXX11 OR MSGPACK_CXX17) INCLUDE_DIRECTORIES ( ../include ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 56c6b7aa..7924930c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -55,7 +55,7 @@ IF (MSGPACK_USE_X3_PARSE) ) ENDIF () -IF (MSGPACK_CXX11) +IF (MSGPACK_CXX11 OR MSGPACK_CXX17) LIST (APPEND check_PROGRAMS iterator_cpp11.cpp msgpack_cpp11.cpp