Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning C4706 on Visual Studio 2017 #785

Merged
merged 5 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,11 +3034,19 @@ class parser
{
case token_type::begin_object:
{
if (keep and (not callback or ((keep = callback(depth++, parse_event_t::object_start, result)))))
if (keep)
{
// explicitly set result to object to cope with {}
result.m_type = value_t::object;
result.m_value = value_t::object;
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
Expand Down Expand Up @@ -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 array to cope with []
result.m_type = value_t::array;
result.m_value = value_t::array;
}
}

// read next token
Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to force the /W4 flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With /W4 always enabled we can ensure no warnings will be emitted when adding this library to an existing project. It feels like a library such as this one should support /W4 with no issues. There are other warnings in unit tests even with /W3, but that would be for another PR. At least there is visibility now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks. I realized we're up to some 50 warnings now...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really appreciate any help with MSVC regarding this warnings, as I have no experience here.

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
#############################################################################
Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down