From f57da48f48422365291ee33cb1141161c5da5645 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 5 Mar 2015 14:41:39 -0600 Subject: [PATCH 1/3] maybe address warning cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=OFF -DJSONCPP_LIB_BUILD_SHARED=ON -G "Visual Studio 10" ../.. `potentially uninitialized local variable 'dist' (line 2212 of test_lib_json/main.cpp)` --- src/test_lib_json/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 69ecae3..25a334b 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -2203,7 +2203,7 @@ JSONTEST_FIXTURE(IteratorTest, distance) { Json::Value json; json["k1"] = "a"; json["k2"] = "b"; - int dist; + int dist = 0; std::string str; for (Json::ValueIterator it = json.begin(); it != json.end(); ++it) { dist = it - json.begin(); From 13e063c336facbb2d32b6f3128a2ddf1f48f823b Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 5 Mar 2015 14:57:41 -0600 Subject: [PATCH 2/3] copy .dll for unit-test Fix 2nd problem in issue #200. * http://stackoverflow.com/questions/10671916/how-to-copy-dll-files-into-the-same-folder-as-the-executable-using-cmake Q: What about the Python tests? A: They are not normally run in Visual Studio. If desired, one can set PATH. --- src/test_lib_json/CMakeLists.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test_lib_json/CMakeLists.txt b/src/test_lib_json/CMakeLists.txt index df5a924..f925ce0 100644 --- a/src/test_lib_json/CMakeLists.txt +++ b/src/test_lib_json/CMakeLists.txt @@ -1,3 +1,4 @@ +# vim: et ts=4 sts=4 sw=4 tw=0 IF(JSONCPP_LIB_BUILD_SHARED) ADD_DEFINITIONS( -DJSON_DLL ) @@ -22,9 +23,19 @@ ENDIF(JSONCPP_LIB_BUILD_SHARED) # Run unit tests in post-build # (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?) IF(JSONCPP_WITH_POST_BUILD_UNITTEST) - ADD_CUSTOM_COMMAND( TARGET jsoncpp_test - POST_BUILD - COMMAND $) + IF(JSONCPP_LIB_BUILD_SHARED) + # First, copy the shared lib, for Microsoft. + # Then, run the test executable. + ADD_CUSTOM_COMMAND( TARGET jsoncpp_test + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND $) + ELSE(JSONCPP_LIB_BUILD_SHARED) + # Just run the test executable. + ADD_CUSTOM_COMMAND( TARGET jsoncpp_test + POST_BUILD + COMMAND $) + ENDIF(JSONCPP_LIB_BUILD_SHARED) ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST) SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test) From b3e6f3d70fae1ea47bd86ff864204c0416bfd980 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 5 Mar 2015 15:19:43 -0600 Subject: [PATCH 3/3] drop `do{}while(0)` idiom Rationale: * http://stackoverflow.com/questions/154136/do-while-and-if-else-statements-in-c-c-macros/154138#154138 But Visual Studio issues a warning: `warning C4127: conditional expression is constant` * http://stackoverflow.com/questions/1946445/c-c-how-to-use-the-do-while0-construct-without-compiler-warnings-like-c412 --- include/json/assertions.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/json/assertions.h b/include/json/assertions.h index a88ac0a..d5fd661 100644 --- a/include/json/assertions.h +++ b/include/json/assertions.h @@ -16,11 +16,15 @@ #if JSON_USE_EXCEPTION #include #define JSON_ASSERT(condition) \ - if (!(condition)) {throw std::logic_error( "assert json failed" );} // @todo <= add detail about condition in exception -#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::logic_error(oss.str());}while(0) + {if (!(condition)) {throw std::logic_error( "assert json failed" );}} // @todo <= add detail about condition in exception +#define JSON_FAIL_MESSAGE(message) \ + { \ + std::ostringstream oss; oss << message; \ + throw std::logic_error(oss.str()); \ + } //#define JSON_FAIL_MESSAGE(message) throw std::logic_error(message) #else // JSON_USE_EXCEPTION -#define JSON_ASSERT(condition) assert(condition); +#define JSON_ASSERT(condition) assert(condition) // The call to assert() will show the failure message in debug builds. In // release bugs we abort, for a core-dump or debugger.