From 917d9d8bc361e9c8015a5b532ff6c453e4991c1a Mon Sep 17 00:00:00 2001 From: Jamie Seward Date: Mon, 16 Oct 2017 23:23:55 -0700 Subject: [PATCH] Fix Visual Studio 2017 warnings --- src/json.hpp | 2 +- test/CMakeLists.txt | 7 +++++-- test/src/unit-constructor1.cpp | 2 +- test/src/unit-readme.cpp | 9 +++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index ef55e2ea..ade73662 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -5292,7 +5292,7 @@ class binary_reader { get(); check_eof(); - return current; + return static_cast(current); }); return result; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b51aff76..0a4680ea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -75,8 +75,11 @@ if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() - # Disable warning C4389: '==': signed/unsigned mismatch - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4389") + # warning C4389: '==': signed/unsigned mismatch + # warning C4309: 'static_cast': truncation of constant value + # warning C4566: character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252) + # warning C4996: 'nlohmann::basic_json::operator <<': was declared deprecated + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4389 /wd4309 /wd4566 /wd4996") endif() ############################################################################# diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index ec096dcd..ed2c8007 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -242,7 +242,7 @@ TEST_CASE("constructors") SECTION("std::pair") { - std::pair p{1.0, "string"}; + std::pair p{1.0f, "string"}; json j(p); CHECK(j.type() == json::value_t::array); diff --git a/test/src/unit-readme.cpp b/test/src/unit-readme.cpp index e921c4b6..576f5834 100644 --- a/test/src/unit-readme.cpp +++ b/test/src/unit-readme.cpp @@ -38,6 +38,11 @@ using nlohmann::json; #include #include +#if defined(_MSC_VER) +#pragma warning (push) +#pragma warning (disable : 4189) // local variable is initialized but not referenced +#endif + TEST_CASE("README", "[hide]") { { @@ -298,3 +303,7 @@ TEST_CASE("README", "[hide]") std::cout.rdbuf(old_cout_buffer); } } + +#if defined(_MSC_VER) +#pragma warning (pop) +#endif \ No newline at end of file