Merge pull request #62 from pah/fixes/msvc

Fixes and cleanups for MSVC
This commit is contained in:
Milo Yip 2014-07-11 07:39:44 +08:00
commit e440b695a1
8 changed files with 23 additions and 17 deletions

View File

@ -64,7 +64,7 @@ solution "test"
defines { "_CRT_SECURE_NO_WARNINGS" } defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "gmake" configuration "gmake"
buildoptions "-msse4.2 -Werror -Wall -Wextra -Wswitch-default" buildoptions "-msse4.2 -Werror -Wall -Wextra"
project "gtest" project "gtest"
kind "StaticLib" kind "StaticLib"
@ -87,7 +87,7 @@ solution "test"
kind "ConsoleApp" kind "ConsoleApp"
if _ACTION == "gmake" then if _ACTION == "gmake" then
buildoptions "-Weffc++" buildoptions "-Weffc++ -Wswitch-default"
end end
files { files {

View File

@ -501,7 +501,7 @@ public:
\see GenericStringRef, operator=(T) \see GenericStringRef, operator=(T)
*/ */
GenericValue& operator=(StringRefType str) { GenericValue& operator=(StringRefType str) {
return (*this).template operator=<StringRefType>(str); return (*this).operator=<StringRefType>(str);
} }
//! Assignment with primitive types. //! Assignment with primitive types.

View File

@ -3,7 +3,10 @@
#include "rapidjson.h" #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_PUSH
RAPIDJSON_DIAG_OFF(effc++) RAPIDJSON_DIAG_OFF(effc++)
#endif #endif
@ -529,7 +532,7 @@ struct Transcoder<Encoding, Encoding> {
} // namespace rapidjson } // namespace rapidjson
#ifdef __GNUC__ #if defined(__GNUC__) || defined(_MSV_VER)
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif

View File

@ -13,8 +13,7 @@ namespace internal {
template <typename Ch> template <typename Ch>
inline SizeType StrLen(const Ch* s) { inline SizeType StrLen(const Ch* s) {
const Ch* p = s; const Ch* p = s;
while (*p != '\0') while (*p) ++p;
++p;
return SizeType(p - s); return SizeType(p - s);
} }

View File

@ -9,6 +9,10 @@
#include "internal/pow10.h" #include "internal/pow10.h"
#include "internal/stack.h" #include "internal/stack.h"
#if defined(RAPIDJSON_SIMD) && defined(_MSC_VER)
#include <intrin.h>
#pragma intrinsic(_BitScanForward)
#endif
#ifdef RAPIDJSON_SSE42 #ifdef RAPIDJSON_SSE42
#include <nmmintrin.h> #include <nmmintrin.h>
#elif defined(RAPIDJSON_SSE2) #elif defined(RAPIDJSON_SSE2)
@ -16,8 +20,8 @@
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) RAPIDJSON_DIAG_PUSH
#pragma warning(disable : 4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
#endif #endif
#ifndef RAPIDJSON_PARSE_ERROR_NORETURN #ifndef RAPIDJSON_PARSE_ERROR_NORETURN
@ -769,7 +773,7 @@ typedef GenericReader<UTF8<>, UTF8<> > Reader;
} // namespace rapidjson } // namespace rapidjson
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) RAPIDJSON_DIAG_POP
#endif #endif
#endif // RAPIDJSON_READER_H_ #endif // RAPIDJSON_READER_H_

View File

@ -8,8 +8,8 @@
#include <new> // placement new #include <new> // placement new
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) RAPIDJSON_DIAG_PUSH
#pragma warning(disable : 4127) // conditional expression is constant RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
#endif #endif
namespace rapidjson { namespace rapidjson {
@ -185,7 +185,7 @@ protected:
char buffer[10]; char buffer[10];
char *p = buffer; char *p = buffer;
do { do {
*p++ = (u % 10) + '0'; *p++ = char(u % 10) + '0';
u /= 10; u /= 10;
} while (u > 0); } while (u > 0);
@ -306,7 +306,7 @@ private:
} // namespace rapidjson } // namespace rapidjson
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) RAPIDJSON_DIAG_POP
#endif #endif
#endif // RAPIDJSON_RAPIDJSON_H_ #endif // RAPIDJSON_RAPIDJSON_H_

View File

@ -242,7 +242,7 @@ TEST_F(RapidJson, PrettyWriter_StringBuffer) {
TEST_F(RapidJson, internal_Pow10) { TEST_F(RapidJson, internal_Pow10) {
double sum = 0; double sum = 0;
for (size_t i = 0; i < kTrialCount * kTrialCount; i++) 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); EXPECT_GT(sum, 0.0);
} }

View File

@ -27,10 +27,10 @@
#endif #endif
template <typename Ch> template <typename Ch>
inline size_t StrLen(const Ch* s) { inline unsigned StrLen(const Ch* s) {
const Ch* p = s; const Ch* p = s;
while (*p) p++; while (*p) p++;
return p - s; return unsigned(p - s);
} }
template<typename Ch> template<typename Ch>