Skip to content

Commit da0c50f

Browse files
committed
Merge pull request open-source-parsers#416 from cdunn2001/fix-gcc6-errors
Fix gcc6 errors
2 parents 9a4b1e3 + 02bc3d7 commit da0c50f

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ endif()
103103

104104
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
105105
# using regular Clang or AppleClang
106-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion -Werror=conversion")
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")
107107
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
108108
# using GCC
109109
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Werror=conversion")

include/json/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
#define JSONCPP_DEPRECATED(message)
115115
#endif // if !defined(JSONCPP_DEPRECATED)
116116

117+
#if __GNUC__ >= 6
118+
# define JSON_USE_INT64_DOUBLE_CONVERSION 1
119+
#endif
120+
117121
namespace Json {
118122
typedef int Int;
119123
typedef unsigned int UInt;

src/lib_json/json_value.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Value::CZString::CZString(const CZString& other)
231231
: cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0
232232
? duplicateStringValue(other.cstr_, other.storage_.length_)
233233
: other.cstr_) {
234-
storage_.policy_ = (other.cstr_
234+
storage_.policy_ = static_cast<unsigned>(other.cstr_
235235
? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
236236
? noDuplication : duplicate)
237237
: static_cast<DuplicationPolicy>(other.storage_.policy_));
@@ -784,7 +784,8 @@ float Value::asFloat() const {
784784
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
785785
return static_cast<float>(value_.uint_);
786786
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
787-
return integerToDouble(value_.uint_);
787+
// This can fail (silently?) if the value is bigger than MAX_FLOAT.
788+
return static_cast<float>(integerToDouble(value_.uint_));
788789
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
789790
case realValue:
790791
return static_cast<float>(value_.real_);

src/lib_json/json_writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ void StyledWriter::writeWithIndent(const std::string& value) {
560560
void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); }
561561

562562
void StyledWriter::unindent() {
563-
assert(int(indentString_.size()) >= indentSize_);
563+
assert(indentString_.size() >= indentSize_);
564564
indentString_.resize(indentString_.size() - indentSize_);
565565
}
566566

@@ -857,7 +857,7 @@ struct BuiltStyledStreamWriter : public StreamWriter
857857

858858
ChildValues childValues_;
859859
std::string indentString_;
860-
int rightMargin_;
860+
unsigned int rightMargin_;
861861
std::string indentation_;
862862
CommentStyle::Enum cs_;
863863
std::string colonSymbol_;

0 commit comments

Comments
 (0)