From f97723dbb78ed4878f73f9e9b3cdf9c81b3e24e6 Mon Sep 17 00:00:00 2001 From: Matthias Loy Date: Wed, 13 Aug 2014 13:19:02 +0200 Subject: [PATCH 1/2] provoke compile error: "dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]" --- src/lib_json/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 39aa0b371..dc3d9772e 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -7,6 +7,10 @@ ELSE(JSONCPP_LIB_BUILD_SHARED) ENDIF(JSONCPP_LIB_BUILD_SHARED) +if( CMAKE_COMPILER_IS_GNUCXX ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing") +endif( CMAKE_COMPILER_IS_GNUCXX ) + SET( JSONCPP_INCLUDE_DIR ../../include ) SET( PUBLIC_HEADERS From 48d9a92a1b4621e69533af543c1f0611abc47ddc Mon Sep 17 00:00:00 2001 From: Matthias Loy Date: Wed, 13 Aug 2014 13:20:29 +0200 Subject: [PATCH 2/2] do intermediate step in order to omit "dereferencing type-punned pointer" error --- src/lib_json/json_value.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 0010f6f5e..637016f3b 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -34,7 +34,8 @@ namespace Json { #define ALIGNAS(byte_alignment) #endif static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = {0}; -const Value& Value::null = reinterpret_cast(kNull); +const unsigned char& kNullRef = kNull[0]; +const Value& Value::null = reinterpret_cast(kNullRef); const Int Value::minInt = Int(~(UInt(-1) / 2)); const Int Value::maxInt = Int(UInt(-1) / 2);