From 5ec44fe9e3fce9f8a0a9d6c25b63e3d2b4c9c122 Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Sun, 15 Oct 2017 22:56:38 -0700 Subject: [PATCH 1/5] Add /W4 for MSVS --- test/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4ccbaf06d..26b474c03 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -91,6 +91,16 @@ foreach(file ${files}) set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal") endif() + # https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake + if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() + endif() + add_test(NAME "${testcase}_default" COMMAND ${testcase} ${CATCH_TEST_FILTER} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} From 19f8f1c075e2d90d6a153b8876c58b645d51c67c Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Mon, 16 Oct 2017 00:21:38 -0700 Subject: [PATCH 2/5] Add missing "u8" This causes test-udt to crash due to bad iterator --- test/src/unit-udt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/unit-udt.cpp b/test/src/unit-udt.cpp index 6aa469fe4..409cac839 100644 --- a/test/src/unit-udt.cpp +++ b/test/src/unit-udt.cpp @@ -201,7 +201,7 @@ void from_json(const BasicJsonType& j, country& c) { {u8"中华人民共和国", country::china}, {"France", country::france}, - {"Российская Федерация", country::russia} + {u8"Российская Федерация", country::russia} }; const auto it = m.find(str); From 8a4af820c767bda5aae714c1ff1f86e55bff1a20 Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Mon, 16 Oct 2017 00:41:58 -0700 Subject: [PATCH 3/5] Fix warning C4706 --- src/json.hpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 3f0b6e3e9..d4dfd5382 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3034,12 +3034,20 @@ class parser { case token_type::begin_object: { - if (keep and (not callback or ((keep = callback(depth++, parse_event_t::object_start, result))))) - { - // explicitly set result to object to cope with {} - result.m_type = value_t::object; - result.m_value = value_t::object; - } + if (keep) + { + if (callback) + { + keep = callback(depth++, parse_event_t::object_start, result); + } + + if (not callback or keep) + { + // explicitly set result to object to cope with {} + result.m_type = value_t::object; + result.m_value = value_t::object; + } + } // read next token get_token(); @@ -3130,11 +3138,19 @@ class parser case token_type::begin_array: { - if (keep and (not callback or ((keep = callback(depth++, parse_event_t::array_start, result))))) + if (keep) { - // explicitly set result to object to cope with [] - result.m_type = value_t::array; - result.m_value = value_t::array; + if (callback) + { + keep = callback(depth++, parse_event_t::array_start, result); + } + + if (not callback or keep) + { + // explicitly set result to object to cope with [] + result.m_type = value_t::array; + result.m_value = value_t::array; + } } // read next token From 8ba7f69ab48eccb067a865612aee7a508009b39f Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Mon, 16 Oct 2017 00:49:59 -0700 Subject: [PATCH 4/5] Fix whitespace --- src/json.hpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index d4dfd5382..ef55e2ead 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3035,19 +3035,19 @@ class parser case token_type::begin_object: { if (keep) - { - if (callback) - { - keep = callback(depth++, parse_event_t::object_start, result); - } + { + if (callback) + { + keep = callback(depth++, parse_event_t::object_start, result); + } - if (not callback or keep) - { - // explicitly set result to object to cope with {} - result.m_type = value_t::object; - result.m_value = value_t::object; - } - } + if (not callback or keep) + { + // explicitly set result to object to cope with {} + result.m_type = value_t::object; + result.m_value = value_t::object; + } + } // read next token get_token(); @@ -3140,17 +3140,17 @@ class parser { if (keep) { - if (callback) - { - keep = callback(depth++, parse_event_t::array_start, result); - } + if (callback) + { + keep = callback(depth++, parse_event_t::array_start, result); + } - if (not callback or keep) - { - // explicitly set result to object to cope with [] - result.m_type = value_t::array; - result.m_value = value_t::array; - } + if (not callback or keep) + { + // explicitly set result to array to cope with [] + result.m_type = value_t::array; + result.m_value = value_t::array; + } } // read next token From af99090742fdb3e7de5572aa2006be228f2311cc Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Mon, 16 Oct 2017 01:02:48 -0700 Subject: [PATCH 5/5] Disable warning C4389: '==': signed/unsigned mismatch Lots of tests have this warning. Also moved out of for loop, doesn't need to be done every loop. --- test/CMakeLists.txt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 26b474c03..b51aff76d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -66,6 +66,19 @@ set_target_properties(catch_main PROPERTIES ) target_include_directories(catch_main PRIVATE "thirdparty/catch") +# https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake +if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() + + # Disable warning C4389: '==': signed/unsigned mismatch + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4389") +endif() + ############################################################################# # one executable for each unit test file ############################################################################# @@ -91,16 +104,6 @@ foreach(file ${files}) set_target_properties(${testcase} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal") endif() - # https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake - if(MSVC) - # Force to always compile with W4 - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() - endif() - add_test(NAME "${testcase}_default" COMMAND ${testcase} ${CATCH_TEST_FILTER} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}