From e63125f1a1c03abbaabb489a00d88fc9224fb095 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 13:09:15 +0200 Subject: [PATCH 1/8] MSVC: fix SSE/intrinsic support MSVC with enabled RAPIDJSON_SSE2/RAPIDJSON_SSE42 requires the explicit definition of the `_BitScanForward` intrinsic. This can be reliably ensured by including "intrin.h" and properly marking '_BitScanForward' as intrinsic. Confirmed on MSVC 2005, 2008. Should fix https://code.google.com/p/rapidjson/issues/detail?id=96 --- include/rapidjson/reader.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 59d03b6..bd141a1 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -9,6 +9,10 @@ #include "internal/pow10.h" #include "internal/stack.h" +#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER) +#include +#pragma intrinsic(_BitScanForward) +#endif #ifdef RAPIDJSON_SSE42 #include #elif defined(RAPIDJSON_SSE2) @@ -16,8 +20,8 @@ #endif #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4127) // conditional expression is constant +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant #endif #ifndef RAPIDJSON_PARSE_ERROR_NORETURN @@ -769,7 +773,7 @@ typedef GenericReader, UTF8<> > Reader; } // namespace rapidjson #ifdef _MSC_VER -#pragma warning(pop) +RAPIDJSON_DIAG_POP #endif #endif // RAPIDJSON_READER_H_ From 04f9c5020f29592d6a9e45baf1c74071c6ab3b8a Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 18:12:46 +0200 Subject: [PATCH 2/8] encodings.h: hide narrowing conversion warnings on MSVC --- include/rapidjson/encodings.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/encodings.h b/include/rapidjson/encodings.h index 9e1623d..dcf21e4 100644 --- a/include/rapidjson/encodings.h +++ b/include/rapidjson/encodings.h @@ -3,7 +3,10 @@ #include "rapidjson.h" -#ifdef __GNUC__ +#ifdef _MSC_VER +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4244) // conversion from 'type1' to 'type2', possible loss of data +#elif defined(__GNUC__) RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) #endif @@ -529,7 +532,7 @@ struct Transcoder { } // namespace rapidjson -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(_MSV_VER) RAPIDJSON_DIAG_POP #endif From bde95eca04c7b683146460ffaca0e757dabca115 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 16:49:20 +0200 Subject: [PATCH 3/8] Writer::WriteUint: add cast to hide warning C4244 on MSVC --- include/rapidjson/writer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 979b781..4fd0427 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -185,7 +185,7 @@ protected: char buffer[10]; char *p = buffer; do { - *p++ = (u % 10) + '0'; + *p++ = char(u % 10) + '0'; u /= 10; } while (u > 0); From 3cdfb0dafe02f9edf041555f1ce2c428e7dfe1c5 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 19:38:57 +0200 Subject: [PATCH 4/8] rapidjsontest.cpp: silence a warning (C4244) on MSVC --- test/perftest/rapidjsontest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index dd8bc30..7c58077 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -242,7 +242,7 @@ TEST_F(RapidJson, PrettyWriter_StringBuffer) { TEST_F(RapidJson, internal_Pow10) { double sum = 0; for (size_t i = 0; i < kTrialCount * kTrialCount; i++) - sum += internal::Pow10(i & 255); + sum += internal::Pow10(int(i & 255)); EXPECT_GT(sum, 0.0); } From 4f40ed64b6940b4d003d09f5fe0408a1ce641555 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 19:41:08 +0200 Subject: [PATCH 5/8] MSVC: fix compiler error in GenericDocument The `StringRefType` assignment operator overload leads to a compiler error on MSVC 2005 and later: ..\..\include\rapidjson/document.h(504) : error C2951: template declarations are only permitted at global, namespace, or class scope Drop the unneeded 'template' keyword here. --- include/rapidjson/document.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 74e5c66..8406598 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -501,7 +501,7 @@ public: \see GenericStringRef, operator=(T) */ GenericValue& operator=(StringRefType str) { - return (*this).template operator=(str); + return (*this).operator=(str); } //! Assignment with primitive types. From 7a2e6e79c64d322875f6ad565fc60024c9f40752 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 16:46:42 +0200 Subject: [PATCH 6/8] StrLen: align implementations There are two copies of `StrLen` in the RapidJSON code base * strfunc.h: rapidjson::internal::StrLen * unittest.h: Strlen To hide a warning on MSVC, align both implementations to use 'unsigned/SizeType' as return type and add an explicit cast. --- include/rapidjson/internal/strfunc.h | 3 +-- test/unittest/unittest.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/internal/strfunc.h b/include/rapidjson/internal/strfunc.h index 47b8ac0..0a20c56 100644 --- a/include/rapidjson/internal/strfunc.h +++ b/include/rapidjson/internal/strfunc.h @@ -13,8 +13,7 @@ namespace internal { template inline SizeType StrLen(const Ch* s) { const Ch* p = s; - while (*p != '\0') - ++p; + while (*p) ++p; return SizeType(p - s); } diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index 75d2bc4..0234319 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -27,10 +27,10 @@ #endif template -inline size_t StrLen(const Ch* s) { +inline unsigned StrLen(const Ch* s) { const Ch* p = s; while (*p) p++; - return p - s; + return unsigned(p - s); } template From ca36a2e66eb87a6caed5889f6adbc72e5568f820 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 19:49:52 +0200 Subject: [PATCH 7/8] writer.h: use warning macros for MSVC --- include/rapidjson/writer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 4fd0427..9652000 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -8,8 +8,8 @@ #include // placement new #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4127) // conditional expression is constant +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant #endif namespace rapidjson { @@ -306,7 +306,7 @@ private: } // namespace rapidjson #ifdef _MSC_VER -#pragma warning(pop) +RAPIDJSON_DIAG_POP #endif #endif // RAPIDJSON_RAPIDJSON_H_ From 6d5583628a537a7ce96cf5037c6872dc6bcf8dd0 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 10 Jul 2014 20:48:54 +0200 Subject: [PATCH 8/8] premake4.lua: only enable "-Wswitch-default" in unittest There's no need to enforce this flag during the build of the perftest or the GoogleTest library, as both include third-party code. --- build/premake4.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/premake4.lua b/build/premake4.lua index 1ef7ff5..0b5dbb1 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -64,7 +64,7 @@ solution "test" defines { "_CRT_SECURE_NO_WARNINGS" } configuration "gmake" - buildoptions "-msse4.2 -Werror -Wall -Wextra -Wswitch-default" + buildoptions "-msse4.2 -Werror -Wall -Wextra" project "gtest" kind "StaticLib" @@ -87,7 +87,7 @@ solution "test" kind "ConsoleApp" if _ACTION == "gmake" then - buildoptions "-Weffc++" + buildoptions "-Weffc++ -Wswitch-default" end files {