From 95f120f68eee1215e17b6c4110553fdb6cb51f4d Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:09:41 -0600 Subject: [PATCH 1/5] For gcc>=6 JSON_USE_INT64_DOUBLE_CONVERSION --- include/json/config.h | 4 ++++ src/lib_json/json_value.cpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/json/config.h b/include/json/config.h index 1b0581f..51027dd 100644 --- a/include/json/config.h +++ b/include/json/config.h @@ -114,6 +114,10 @@ #define JSONCPP_DEPRECATED(message) #endif // if !defined(JSONCPP_DEPRECATED) +#if __GNUC__ >= 6 +# define JSON_USE_INT64_DOUBLE_CONVERSION 1 +#endif + namespace Json { typedef int Int; typedef unsigned int UInt; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a1962e6..1f6425f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -784,7 +784,8 @@ float Value::asFloat() const { #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return static_cast(value_.uint_); #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return integerToDouble(value_.uint_); + // This can fail (silently?) if the value is bigger than MAX_FLOAT. + return static_cast(integerToDouble(value_.uint_)); #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) case realValue: return static_cast(value_.real_); From 83bc9c7cf613267364b900fff8c68b74130f81e0 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:12:25 -0600 Subject: [PATCH 2/5] Errors for sign-compare, since gcc6 is stricter --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1583daa..97e4de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion -Werror=conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion -Werror=conversion -Werror=sign-compare") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Werror=conversion") From 2713f4f4566338849de53ac8a91516d0dd6bac55 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:16:04 -0600 Subject: [PATCH 3/5] Fix a sign-compare --- src/lib_json/json_writer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index a2facee..9f11367 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -560,7 +560,7 @@ void StyledWriter::writeWithIndent(const std::string& value) { void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); } void StyledWriter::unindent() { - assert(int(indentString_.size()) >= indentSize_); + assert(indentString_.size() >= indentSize_); indentString_.resize(indentString_.size() - indentSize_); } @@ -857,7 +857,7 @@ private: ChildValues childValues_; std::string indentString_; - int rightMargin_; + unsigned int rightMargin_; std::string indentation_; CommentStyle::Enum cs_; std::string colonSymbol_; From 6b562c850dc88aeb6a47df1462b1e5517d69fee7 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:19:04 -0600 Subject: [PATCH 4/5] Drop -Wno-sign-conversion suppression --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97e4de0..22567b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion -Werror=conversion -Werror=sign-compare") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Werror=conversion") From 02bc3d77de93088e065ede2f9c07fb023f54d3a9 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 7 Feb 2016 11:28:50 -0600 Subject: [PATCH 5/5] This *might* fix the last gcc-6 error. See https://github.com/open-source-parsers/jsoncpp/issues/411#issuecomment-180974558 I was unable to produce a warning in Clang, so I am not certain. But based on a [SO answer](http://stackoverflow.com/questions/25480059/gcc-conversion-warning-when-assigning-to-a-bitfield), I think I've fixed the following: ``` /tmp/jsoncpp/src/lib_json/json_value.cpp: In copy constructor 'Json::Value::CZString::CZString(const Json::Value::CZString&)': /tmp/jsoncpp/src/lib_json/json_value.cpp:235:18: error: conversion to 'unsigned char:2' from 'unsigned int' may alter its value [-Werror=conversion] storage_.policy_ = (other.cstr_ ~~~~~~~~~~~~ ? (static_cast(other.storage_.policy_) == noDuplication ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ? noDuplication : duplicate) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : static_cast(other.storage_.policy_)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` --- src/lib_json/json_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 1f6425f..f598491 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -231,7 +231,7 @@ Value::CZString::CZString(const CZString& other) : cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0 ? duplicateStringValue(other.cstr_, other.storage_.length_) : other.cstr_) { - storage_.policy_ = (other.cstr_ + storage_.policy_ = static_cast(other.cstr_ ? (static_cast(other.storage_.policy_) == noDuplication ? noDuplication : duplicate) : static_cast(other.storage_.policy_));