From 9c68ce986e8212688b95e14d338affcb0cac5e19 Mon Sep 17 00:00:00 2001 From: "miloyip@gmail.com" Date: Tue, 13 Nov 2012 08:02:22 +0000 Subject: [PATCH] Fixed a lots of vc2008/vs2010 and gcc3/4 warnings with the maximum warning level. git-svn-id: https://rapidjson.googlecode.com/svn/trunk@67 c5894555-1306-4e8d-425f-1f6f381ee07c --- build/premake4.lua | 2 ++ include/rapidjson/allocators.h | 4 +-- include/rapidjson/document.h | 37 +++++++++++++-------- include/rapidjson/encodedstream.h | 18 +++++++++-- include/rapidjson/encodings.h | 6 ++-- include/rapidjson/filereadstream.h | 2 +- include/rapidjson/filewritestream.h | 6 ++-- include/rapidjson/prettywriter.h | 4 +++ include/rapidjson/rapidjson.h | 11 +++++-- include/rapidjson/reader.h | 48 ++++++++++++++++++++------- include/rapidjson/writer.h | 17 ++++++++++ test/perftest/perftest.cpp | 2 +- test/perftest/rapidjsontest.cpp | 48 +++++++++++++++------------ test/unittest/documenttest.cpp | 2 +- test/unittest/encodingstest.cpp | 32 +++++++++--------- test/unittest/jsoncheckertest.cpp | 16 +++++---- test/unittest/readertest.cpp | 50 ++++++++++++++--------------- test/unittest/valuetest.cpp | 46 +++++++++++++------------- test/unittest/writertest.cpp | 4 +-- 19 files changed, 220 insertions(+), 135 deletions(-) diff --git a/build/premake4.lua b/build/premake4.lua index 74064fbc..e472f5a5 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -50,6 +50,7 @@ solution "test" location ("./" .. (_ACTION or "")) language "C++" + flags { "ExtraWarnings" } configuration "debug" defines { "DEBUG" } @@ -134,6 +135,7 @@ solution "example" platforms { "x32", "x64" } location ("./" .. (_ACTION or "")) language "C++" + flags { "ExtraWarnings" } includedirs "../include/" configuration "debug" diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 8a490a66..6dfa85ae 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -49,7 +49,7 @@ class CrtAllocator { public: static const bool kNeedFree = true; void* Malloc(size_t size) { return malloc(size); } - void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { return realloc(originalPtr, newSize); } + void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return realloc(originalPtr, newSize); } static void Free(void *ptr) { free(ptr); } }; @@ -184,7 +184,7 @@ public: } //! Frees a memory block (concept Allocator) - static void Free(void *ptr) {} // Do nothing + static void Free(void *ptr) { (void)ptr; } // Do nothing private: //! Creates a new chunk. diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index fc658384..b42f0278 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -4,6 +4,11 @@ #include "reader.h" #include "internal/strfunc.h" +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4127) // conditional expression is constant +#endif + namespace rapidjson { /////////////////////////////////////////////////////////////////////////////// @@ -413,16 +418,16 @@ int z = a[0u].GetInt(); // This works too. //!@name Number //@{ - int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i; } - unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u; } + int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i.i; } + unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u.u; } int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; } int64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.u64; } double GetDouble() const { RAPIDJSON_ASSERT(IsNumber()); if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion. - if ((flags_ & kIntFlag) != 0) return data_.n.i; // int -> double - if ((flags_ & kUintFlag) != 0) return data_.n.u; // unsigned -> double + if ((flags_ & kIntFlag) != 0) return data_.n.i.i; // int -> double + if ((flags_ & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision) RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision) } @@ -512,8 +517,8 @@ int z = a[0u].GetInt(); // This works too. break; case kNumberType: - if (IsInt()) handler.Int(data_.n.i); - else if (IsUint()) handler.Uint(data_.n.u); + if (IsInt()) handler.Int(data_.n.i.i); + else if (IsUint()) handler.Uint(data_.n.u.u); else if (IsInt64()) handler.Int64(data_.n.i64); else if (IsUint64()) handler.Uint64(data_.n.i64); else handler.Double(data_.n.d); @@ -566,23 +571,23 @@ private: // By using proper binary layout, retrieval of different integer types do not need conversions. union Number { #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN - struct { + struct I { int i; char padding[4]; - }; - struct { + }i; + struct U { unsigned u; char padding2[4]; - }; + }u; #else - struct { + struct I { char padding[4]; int i; - }; - struct { + }i; + struct U { char padding2[4]; unsigned u; - }; + }u; #endif int64_t i64; uint64_t u64; @@ -814,4 +819,8 @@ typedef GenericDocument > Document; } // namespace rapidjson +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif // RAPIDJSON_DOCUMENT_H_ diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index 40f61deb..0deecbbb 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -22,7 +22,7 @@ public: Ch Peek() const { return current_; } Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; } - size_t Tell() const { is_.Tell(); } + size_t Tell() const { return is_.Tell(); } // Not implemented void Put(Ch c) { RAPIDJSON_ASSERT(false); } @@ -31,6 +31,9 @@ public: size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } private: + // Prohibit assignment for VC C4512 warning + EncodedInputStream& operator=(const EncodedInputStream&); + InputByteStream& is_; Ch current_; }; @@ -57,11 +60,14 @@ public: // Not implemented Ch Peek() const { RAPIDJSON_ASSERT(false); } Ch Take() { RAPIDJSON_ASSERT(false); } - size_t Tell() const { RAPIDJSON_ASSERT(false); } + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } private: + // Prohibit assignment for VC C4512 warning + EncodedOutputStream& operator=(const EncodedOutputStream&); + OutputByteStream& os_; }; @@ -149,6 +155,9 @@ private: // RUntime check whether the size of character type is sufficient. It only perform checks with assertion. switch (type_) { + case kUTF8: + // Do nothing + break; case kUTF16LE: case kUTF16BE: RAPIDJSON_ASSERT(sizeof(Ch) >= 2); @@ -196,6 +205,9 @@ public: case kUTF32BE: RAPIDJSON_ASSERT(sizeof(Ch) >= 4); break; + case kUTF8: + // Do nothing + break; } static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; @@ -213,7 +225,7 @@ public: // Not implemented Ch Peek() const { RAPIDJSON_ASSERT(false); } Ch Take() { RAPIDJSON_ASSERT(false); } - size_t Tell() const { RAPIDJSON_ASSERT(false); } + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } diff --git a/include/rapidjson/encodings.h b/include/rapidjson/encodings.h index 80cca970..27bb6e97 100644 --- a/include/rapidjson/encodings.h +++ b/include/rapidjson/encodings.h @@ -193,7 +193,7 @@ struct UTF8 { template static void Put(OutputByteStream& os, Ch c) { RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); - os.Put(c); + os.Put(static_cast(c)); } }; @@ -219,12 +219,12 @@ struct UTF16 { RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2); if (codepoint <= 0xFFFF) { RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair - os.Put(codepoint); + os.Put(static_cast(codepoint)); } else { RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); unsigned v = codepoint - 0x10000; - os.Put((v >> 10) | 0xD800); + os.Put(static_cast((v >> 10) | 0xD800)); os.Put((v & 0x3FF) | 0xDC00); } } diff --git a/include/rapidjson/filereadstream.h b/include/rapidjson/filereadstream.h index d1fc8558..2d208416 100644 --- a/include/rapidjson/filereadstream.h +++ b/include/rapidjson/filereadstream.h @@ -31,7 +31,7 @@ public: size_t Tell() const { return count_ + (current_ - buffer_); } // Not implemented - void Put(Ch c) { RAPIDJSON_ASSERT(false); } + void Put(Ch) { RAPIDJSON_ASSERT(false); } void Flush() { RAPIDJSON_ASSERT(false); } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } diff --git a/include/rapidjson/filewritestream.h b/include/rapidjson/filewritestream.h index 6eca68dc..3d15ea87 100644 --- a/include/rapidjson/filewritestream.h +++ b/include/rapidjson/filewritestream.h @@ -49,9 +49,9 @@ public: } // Not implemented - char Peek() const { RAPIDJSON_ASSERT(false); } - char Take() { RAPIDJSON_ASSERT(false); } - size_t Tell() const { RAPIDJSON_ASSERT(false); } + char Peek() const { RAPIDJSON_ASSERT(false); return 0; } + char Take() { RAPIDJSON_ASSERT(false); return 0; } + size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 3f3e4cda..2a0a505f 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -49,6 +49,7 @@ public: PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; } PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) { + (void)copy; PrettyPrefix(kStringType); Base::WriteString(str, length); return *this; @@ -62,6 +63,7 @@ public: } PrettyWriter& EndObject(SizeType memberCount = 0) { + (void)memberCount; RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray); bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; @@ -84,6 +86,7 @@ public: } PrettyWriter& EndArray(SizeType memberCount = 0) { + (void)memberCount; RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray); bool empty = Base::level_stack_.template Pop(1)->valueCount == 0; @@ -105,6 +108,7 @@ public: protected: void PrettyPrefix(Type type) { + (void)type; if (Base::level_stack_.GetSize() != 0) { // this value is not at root typename Base::Level* level = Base::level_stack_.template Top(); diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 1160c7c3..2ba3c580 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -115,6 +115,13 @@ template struct StaticAssertTest {}; RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) #endif +/////////////////////////////////////////////////////////////////////////////// +// Helpers + +#define RAPIDJSON_MULTILINEMACRO_BEGIN do { +#define RAPIDJSON_MULTILINEMACRO_END \ +} while((void)0, 0) + /////////////////////////////////////////////////////////////////////////////// // Allocators and Encodings @@ -189,9 +196,9 @@ struct GenericStringStream { size_t Tell() const { return src_ - head_; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } - void Put(Ch c) { RAPIDJSON_ASSERT(false); } + void Put(Ch) { RAPIDJSON_ASSERT(false); } void Flush() { RAPIDJSON_ASSERT(false); } - size_t PutEnd(Ch* begin) { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } const Ch* src_; //!< Current read position. const Ch* head_; //!< Original head of the string. diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 72cbf722..c932dea4 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -16,8 +16,18 @@ #include #endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4127) // conditional expression is constant +#endif + #ifndef RAPIDJSON_PARSE_ERROR -#define RAPIDJSON_PARSE_ERROR(msg, offset) do { parseError_ = msg; errorOffset_ = offset; longjmp(jmpbuf_, 1); } while(false) +#define RAPIDJSON_PARSE_ERROR(msg, offset) \ + RAPIDJSON_MULTILINEMACRO_BEGIN \ + parseError_ = msg; \ + errorOffset_ = offset; \ + longjmp(jmpbuf_, 1); \ + RAPIDJSON_MULTILINEMACRO_END #endif namespace rapidjson { @@ -69,17 +79,17 @@ struct BaseReaderHandler { void Default() {} void Null() { Default(); } - void Bool(bool b) { Default(); } - void Int(int i) { Default(); } - void Uint(unsigned i) { Default(); } - void Int64(int64_t i) { Default(); } - void Uint64(uint64_t i) { Default(); } - void Double(double d) { Default(); } - void String(const Ch* str, SizeType length, bool copy) { Default(); } + void Bool(bool) { Default(); } + void Int(int) { Default(); } + void Uint(unsigned) { Default(); } + void Int64(int64_t) { Default(); } + void Uint64(uint64_t) { Default(); } + void Double(double) { Default(); } + void String(const Ch*, SizeType, bool) { Default(); } void StartObject() { Default(); } - void EndObject(SizeType memberCount) { Default(); } + void EndObject(SizeType) { Default(); } void StartArray() { Default(); } - void EndArray(SizeType elementCount) { Default(); } + void EndArray(SizeType) { Default(); } }; /////////////////////////////////////////////////////////////////////////////// @@ -215,7 +225,14 @@ public: parseError_ = 0; errorOffset_ = 0; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable +#endif if (setjmp(jmpbuf_)) { +#ifdef _MSC_VER +#pragma warning(pop) +#endif stack_.Clear(); return false; } @@ -365,7 +382,8 @@ private: return codepoint; } - struct StackStream { + class StackStream { + public: typedef typename TargetEncoding::Ch Ch; StackStream(internal::Stack& stack) : stack_(stack), length_(0) {} @@ -375,6 +393,10 @@ private: } internal::Stack& stack_; SizeType length_; + + private: + // Prohibit assignment for VC C4512 warning + StackStream& operator=(const StackStream&); }; // Parse string and generate String event. Different code paths for kParseInsituFlag. @@ -640,4 +662,8 @@ typedef GenericReader, UTF8<> > Reader; } // namespace rapidjson +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif // RAPIDJSON_READER_H_ diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 516dc338..9fde3e19 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -7,6 +7,11 @@ #include // snprintf() or _sprintf_s() #include // placement new +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4127) // conditional expression is constant +#endif + namespace rapidjson { //! JSON writer @@ -43,6 +48,7 @@ public: Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; } Writer& String(const Ch* str, SizeType length, bool copy = false) { + (void)copy; Prefix(kStringType); WriteString(str, length); return *this; @@ -56,6 +62,7 @@ public: } Writer& EndObject(SizeType memberCount = 0) { + (void)memberCount; RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); RAPIDJSON_ASSERT(!level_stack_.template Top()->inArray); level_stack_.template Pop(1); @@ -73,6 +80,7 @@ public: } Writer& EndArray(SizeType elementCount = 0) { + (void)elementCount; RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); RAPIDJSON_ASSERT(level_stack_.template Top()->inArray); level_stack_.template Pop(1); @@ -207,6 +215,7 @@ protected: void WriteEndArray() { os_.Put(']'); } void Prefix(Type type) { + (void)type; if (level_stack_.GetSize() != 0) { // this value is not at root Level* level = level_stack_.template Top(); if (level->valueCount > 0) { @@ -225,8 +234,16 @@ protected: OutputStream& os_; internal::Stack level_stack_; + +private: + // Prohibit assignment for VC C4512 warning + Writer& operator=(const Writer& w); }; } // namespace rapidjson +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #endif // RAPIDJSON_RAPIDJSON_H_ diff --git a/test/perftest/perftest.cpp b/test/perftest/perftest.cpp index 81f2b4ca..fac4c2f8 100644 --- a/test/perftest/perftest.cpp +++ b/test/perftest/perftest.cpp @@ -7,4 +7,4 @@ int main(int argc, char **argv) { #endif ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index bffc1f2e..15e5912a 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -42,7 +42,7 @@ protected: }; TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { memcpy(temp_, json_, length_ + 1); InsituStringStream s(temp_); BaseReaderHandler<> h; @@ -52,7 +52,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) { } TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { memcpy(temp_, json_, length_ + 1); InsituStringStream s(temp_); BaseReaderHandler<> h; @@ -62,7 +62,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding)) } TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { StringStream s(json_); BaseReaderHandler<> h; Reader reader; @@ -71,7 +71,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) { } TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { StringStream s(json_); BaseReaderHandler<> h; Reader reader; @@ -83,7 +83,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) { //const size_t userBufferSize = 128 * 1024; //char* userBuffer = (char*)malloc(userBufferSize); - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { memcpy(temp_, json_, length_ + 1); //MemoryPoolAllocator<> allocator(userBuffer, userBufferSize); //Document doc(&allocator); @@ -106,7 +106,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { //const size_t userBufferSize = 128 * 1024; //char* userBuffer = (char*)malloc(userBufferSize); - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { //MemoryPoolAllocator<> allocator(userBuffer, userBufferSize); //Document doc(&allocator); Document doc; @@ -125,7 +125,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { } TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_CrtAllocator)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { memcpy(temp_, json_, length_ + 1); GenericDocument, CrtAllocator> doc; doc.Parse<0>(temp_); @@ -148,14 +148,18 @@ size_t Traverse(const T& value) { for (typename T::ConstValueIterator itr = value.Begin(); itr != value.End(); ++itr) count += Traverse(*itr); break; + + default: + // Do nothing. + break; } return count; } TEST_F(RapidJson, DocumentTraverse) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { size_t count = Traverse(doc_); - EXPECT_EQ(4339, count); + EXPECT_EQ(4339u, count); //if (i == 0) // std::cout << count << std::endl; } @@ -171,22 +175,22 @@ struct ValueCounter : public BaseReaderHandler<> { }; TEST_F(RapidJson, DocumentAccept) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { ValueCounter counter; doc_.Accept(counter); - EXPECT_EQ(4339, counter.count_); + EXPECT_EQ(4339u, counter.count_); } } struct NullStream { NullStream() /*: length_(0)*/ {} - void Put(char c) { /*++length_;*/ } + void Put(char) { /*++length_;*/ } void Flush() {} //size_t length_; }; TEST_F(RapidJson, Writer_NullStream) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { NullStream s; Writer writer(s); doc_.Accept(writer); @@ -196,23 +200,25 @@ TEST_F(RapidJson, Writer_NullStream) { } TEST_F(RapidJson, Writer_StringBuffer) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { StringBuffer s(0, 1024 * 1024); Writer writer(s); doc_.Accept(writer); const char* str = s.GetString(); + (void)str; //if (i == 0) // std::cout << strlen(str) << std::endl; } } TEST_F(RapidJson, PrettyWriter_StringBuffer) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { StringBuffer s(0, 2048 * 1024); PrettyWriter writer(s); writer.SetIndent(' ', 1); doc_.Accept(writer); const char* str = s.GetString(); + (void)str; //if (i == 0) // std::cout << strlen(str) << std::endl; } @@ -220,13 +226,13 @@ TEST_F(RapidJson, PrettyWriter_StringBuffer) { TEST_F(RapidJson, internal_Pow10) { double sum = 0; - for (int i = 0; i < kTrialCount * kTrialCount; i++) + for (size_t i = 0; i < kTrialCount * kTrialCount; i++) sum += internal::Pow10(i & 255); EXPECT_GT(sum, 0.0); } TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { Document doc; ASSERT_TRUE(doc.Parse<0>(whitespace_).IsArray()); } @@ -235,7 +241,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) { TEST_F(RapidJson, UTF8_Validate) { NullStream os; - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { StringStream is(json_); bool result = true; while (is.Peek() != '\0') @@ -246,7 +252,7 @@ TEST_F(RapidJson, UTF8_Validate) { // Depreciated. //TEST_F(RapidJson, FileStream_Read) { -// for (int i = 0; i < kTrialCount; i++) { +// for (size_t i = 0; i < kTrialCount; i++) { // FILE *fp = fopen(filename_, "rb"); // FileStream s(fp); // while (s.Take() != '\0') @@ -256,7 +262,7 @@ TEST_F(RapidJson, UTF8_Validate) { //} TEST_F(RapidJson, FileReadStream) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { FILE *fp = fopen(filename_, "rb"); char buffer[65536]; FileReadStream s(fp, buffer, sizeof(buffer)); @@ -267,7 +273,7 @@ TEST_F(RapidJson, FileReadStream) { } TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_FileReadStream)) { - for (int i = 0; i < kTrialCount; i++) { + for (size_t i = 0; i < kTrialCount; i++) { FILE *fp = fopen(filename_, "rb"); char buffer[65536]; FileReadStream s(fp, buffer, sizeof(buffer)); diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 869a71c8..5dd4f352 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -42,7 +42,7 @@ TEST(Document, Parse) { EXPECT_TRUE(doc.HasMember("a")); Value& a = doc["a"]; EXPECT_TRUE(a.IsArray()); - EXPECT_EQ(4, a.Size()); + EXPECT_EQ(4u, a.Size()); for (SizeType i = 0; i < 4; i++) EXPECT_EQ(i + 1, a[i].GetUint()); } diff --git a/test/unittest/encodingstest.cpp b/test/unittest/encodingstest.cpp index 1c3260fe..86c7d6e7 100644 --- a/test/unittest/encodingstest.cpp +++ b/test/unittest/encodingstest.cpp @@ -225,8 +225,8 @@ static const unsigned kCodepointRanges[] = { // Copyright (c) 2008-2010 Bjoern Hoehrmann // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. -#define UTF8_ACCEPT 0 -#define UTF8_REJECT 12 +#define UTF8_ACCEPT 0u +#define UTF8_REJECT 12u static const unsigned char utf8d[] = { // The first part of the table maps bytes to character classes that @@ -260,14 +260,14 @@ static unsigned inline decode(unsigned* state, unsigned* codep, unsigned byte) { return *state; } -static bool IsUTF8(unsigned char* s) { - unsigned codepoint, state = 0; - - while (*s) - decode(&state, &codepoint, *s++); - - return state == UTF8_ACCEPT; -} +//static bool IsUTF8(unsigned char* s) { +// unsigned codepoint, state = 0; +// +// while (*s) +// decode(&state, &codepoint, *s++); +// +// return state == UTF8_ACCEPT; +//} TEST(EncodingsTest, UTF8) { StringBuffer os, os2; @@ -279,7 +279,7 @@ TEST(EncodingsTest, UTF8) { // Decode with Hoehrmann { - unsigned decodedCodepoint; + unsigned decodedCodepoint = 0; unsigned state = 0; unsigned decodedCount = 0; @@ -290,7 +290,7 @@ TEST(EncodingsTest, UTF8) { } if (*encodedStr) // This decoder cannot handle U+0000 - EXPECT_EQ(1, decodedCount); // Should only contain one code point + EXPECT_EQ(1u, decodedCount); // Should only contain one code point EXPECT_EQ(UTF8_ACCEPT, state); if (UTF8_ACCEPT != state) @@ -337,7 +337,7 @@ TEST(EncodingsTest, UTF16) { UTF8<>::Encode(utf8os, codepoint); // transcode from UTF8 to UTF16 with Hoehrmann's code - unsigned decodedCodepoint; + unsigned decodedCodepoint = 0; unsigned state = 0; UTF16<>::Ch buffer[3], *p = &buffer[0]; for (const char* s = utf8os.GetString(); *s; ++s) { @@ -346,11 +346,11 @@ TEST(EncodingsTest, UTF16) { } if (codepoint <= 0xFFFF) - *p++ = decodedCodepoint; + *p++ = static_cast::Ch>(decodedCodepoint); else { // Encode code points above U+FFFF as surrogate pair. - *p++ = 0xD7C0 + (decodedCodepoint >> 10); - *p++ = 0xDC00 + (decodedCodepoint & 0x3FF); + *p++ = static_cast::Ch>(0xD7C0 + (decodedCodepoint >> 10)); + *p++ = static_cast::Ch>(0xDC00 + (decodedCodepoint & 0x3FF)); } *p++ = '\0'; diff --git a/test/unittest/jsoncheckertest.cpp b/test/unittest/jsoncheckertest.cpp index 11fa606f..5c53865b 100644 --- a/test/unittest/jsoncheckertest.cpp +++ b/test/unittest/jsoncheckertest.cpp @@ -30,11 +30,12 @@ TEST(JsonChecker, Reader) { continue; sprintf(filename, "jsonchecker/fail%d.json", i); - char* json; size_t length; - if (!(json = ReadFile(filename, length))) { + char* json = ReadFile(filename, length); + if (!json) { sprintf(filename, "../../bin/jsonchecker/fail%d.json", i); - if (!(json = ReadFile(filename, length))) { + json = ReadFile(filename, length); + if (!json) { printf("jsonchecker file %s not found", filename); continue; } @@ -50,11 +51,12 @@ TEST(JsonChecker, Reader) { // passX.json for (int i = 1; i <= 3; i++) { sprintf(filename, "jsonchecker/pass%d.json", i); - char* json; size_t length; - if (!(json = ReadFile(filename, length))) { + char* json = ReadFile(filename, length); + if (!json) { sprintf(filename, "../../bin/jsonchecker/pass%d.json", i); - if (!(json = ReadFile(filename, length))) { + json = ReadFile(filename, length); + if (!json) { printf("jsonchecker file %s not found", filename); continue; } @@ -65,4 +67,4 @@ TEST(JsonChecker, Reader) { EXPECT_TRUE(!document.HasParseError()); free(json); } -} \ No newline at end of file +} diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index beddd2d7..225c3d09 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -19,7 +19,7 @@ TEST(Reader, ParseTrue) { ParseBoolHandler h; Reader reader; reader.ParseTrue<0>(s, h); - EXPECT_EQ(1, h.step_); + EXPECT_EQ(1u, h.step_); } TEST(Reader, ParseFalse) { @@ -27,7 +27,7 @@ TEST(Reader, ParseFalse) { ParseBoolHandler h; Reader reader; reader.ParseFalse<0>(s, h); - EXPECT_EQ(1, h.step_); + EXPECT_EQ(1u, h.step_); } struct ParseIntHandler : BaseReaderHandler<> { @@ -82,8 +82,8 @@ TEST(Reader, ParseNumberHandler) { Handler h; \ Reader reader; \ reader.ParseNumber<0>(s, h); \ - EXPECT_EQ(1, h.step_); \ - EXPECT_EQ(x, h.actual_); \ + EXPECT_EQ(1u, h.step_); \ + EXPECT_EQ(double(x), h.actual_); \ } #define TEST_DOUBLE(str, x) \ @@ -92,7 +92,7 @@ TEST(Reader, ParseNumberHandler) { ParseDoubleHandler h; \ Reader reader; \ reader.ParseNumber<0>(s, h); \ - EXPECT_EQ(1, h.step_); \ + EXPECT_EQ(1u, h.step_); \ EXPECT_DOUBLE_EQ(x, h.actual_); \ } @@ -273,7 +273,7 @@ TEST(Reader, ParseString) { Reader reader; reader.ParseString<0>(s, h); EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1)); - EXPECT_EQ(11, h.length_); + EXPECT_EQ(11u, h.length_); } } @@ -294,7 +294,7 @@ TEST(Reader, ParseString_NonDestructive) { Reader reader; reader.ParseString<0>(s, h); EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_)); - EXPECT_EQ(11, h.length_); + EXPECT_EQ(11u, h.length_); } bool TestString(const char* str) { @@ -327,8 +327,8 @@ TEST(Reader, ParseString_Error) { char e[] = { '[', '\"', 0, '\"', ']', '\0' }; for (unsigned char c = 0x80u; c <= 0xBFu; c++) { e[2] = c; - bool b; - EXPECT_FALSE(b = TestString(e)); + bool b = TestString(e); + EXPECT_FALSE(b); if (b) std::cout << (unsigned)(unsigned char)c << std::endl; } @@ -381,8 +381,8 @@ struct ParseArrayHandler : BaseReaderHandler<> { void Default() { FAIL(); } void Uint(unsigned i) { EXPECT_EQ(step_, i); step_++; } - void StartArray() { EXPECT_EQ(0, step_); step_++; } - void EndArray(SizeType elementCount) { step_++; } + void StartArray() { EXPECT_EQ(0u, step_); step_++; } + void EndArray(SizeType) { step_++; } unsigned step_; }; @@ -393,7 +393,7 @@ TEST(Reader, ParseEmptyArray) { ParseArrayHandler<0> h; Reader reader; reader.ParseArray<0>(s, h); - EXPECT_EQ(2, h.step_); + EXPECT_EQ(2u, h.step_); free(json); } @@ -403,7 +403,7 @@ TEST(Reader, ParseArray) { ParseArrayHandler<4> h; Reader reader; reader.ParseArray<0>(s, h); - EXPECT_EQ(6, h.step_); + EXPECT_EQ(6u, h.step_); free(json); } @@ -429,7 +429,7 @@ TEST(Reader, ParseArray_Error) { struct ParseObjectHandler : BaseReaderHandler<> { ParseObjectHandler() : step_(0) {} - void Null() { EXPECT_EQ(8, step_); step_++; } + void Null() { EXPECT_EQ(8u, step_); step_++; } void Bool(bool b) { switch(step_) { case 4: EXPECT_TRUE(b); step_++; break; @@ -447,8 +447,8 @@ struct ParseObjectHandler : BaseReaderHandler<> { } } void Uint(unsigned i) { Int(i); } - void Double(double d) { EXPECT_EQ(12, step_); EXPECT_EQ(3.1416, d); step_++; } - void String(const char* str, size_t length, bool copy) { + void Double(double d) { EXPECT_EQ(12u, step_); EXPECT_EQ(3.1416, d); step_++; } + void String(const char* str, size_t, bool) { switch(step_) { case 1: EXPECT_STREQ("hello", str); step_++; break; case 2: EXPECT_STREQ("world", str); step_++; break; @@ -461,10 +461,10 @@ struct ParseObjectHandler : BaseReaderHandler<> { default: FAIL(); } } - void StartObject() { EXPECT_EQ(0, step_); step_++; } - void EndObject(SizeType memberCount) { EXPECT_EQ(19, step_); EXPECT_EQ(7, memberCount); step_++;} - void StartArray() { EXPECT_EQ(14, step_); step_++; } - void EndArray(SizeType elementCount) { EXPECT_EQ(18, step_); EXPECT_EQ(3, elementCount); step_++;} + void StartObject() { EXPECT_EQ(0u, step_); step_++; } + void EndObject(SizeType memberCount) { EXPECT_EQ(19u, step_); EXPECT_EQ(7u, memberCount); step_++;} + void StartArray() { EXPECT_EQ(14u, step_); step_++; } + void EndArray(SizeType elementCount) { EXPECT_EQ(18u, step_); EXPECT_EQ(3u, elementCount); step_++;} unsigned step_; }; @@ -479,7 +479,7 @@ TEST(Reader, ParseObject) { ParseObjectHandler h; Reader reader; reader.ParseObject(s, h); - EXPECT_EQ(20, h.step_); + EXPECT_EQ(20u, h.step_); free(json2); } @@ -489,7 +489,7 @@ TEST(Reader, ParseObject) { ParseObjectHandler h; Reader reader; reader.ParseObject<0>(s, h); - EXPECT_EQ(20, h.step_); + EXPECT_EQ(20u, h.step_); } } @@ -497,8 +497,8 @@ struct ParseEmptyObjectHandler : BaseReaderHandler<> { ParseEmptyObjectHandler() : step_(0) {} void Default() { FAIL(); } - void StartObject() { EXPECT_EQ(0, step_); step_++; } - void EndObject(SizeType memberCount) { EXPECT_EQ(1, step_); step_++; } + void StartObject() { EXPECT_EQ(0u, step_); step_++; } + void EndObject(SizeType) { EXPECT_EQ(1u, step_); step_++; } unsigned step_; }; @@ -508,7 +508,7 @@ TEST(Reader, Parse_EmptyObject) { ParseEmptyObjectHandler h; Reader reader; reader.ParseObject<0>(s, h); - EXPECT_EQ(2, h.step_); + EXPECT_EQ(2u, h.step_); } TEST(Reader, ParseObject_Error) { diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index b0c3c8a5..4505573f 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -105,9 +105,9 @@ TEST(Value, Int) { Value x(1234); EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(1234, x.GetInt()); - EXPECT_EQ(1234, x.GetUint()); + EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234, x.GetInt64()); - EXPECT_EQ(1234, x.GetUint64()); + EXPECT_EQ(1234u, x.GetUint64()); EXPECT_EQ(1234, x.GetDouble()); //EXPECT_EQ(1234, (int)x); //EXPECT_EQ(1234, (unsigned)x); @@ -157,9 +157,9 @@ TEST(Value, Uint) { // Constructor with int Value x(1234u); EXPECT_EQ(kNumberType, x.GetType()); - EXPECT_EQ(1234u, x.GetInt()); + EXPECT_EQ(1234, x.GetInt()); EXPECT_EQ(1234u, x.GetUint()); - EXPECT_EQ(1234u, x.GetInt64()); + EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234u, x.GetUint64()); EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsInt()); @@ -180,11 +180,11 @@ TEST(Value, Uint) { // SetUint() Value z; z.SetUint(1234); - EXPECT_EQ(1234, z.GetUint()); + EXPECT_EQ(1234u, z.GetUint()); // operator=(unsigned) z = 5678u; - EXPECT_EQ(5678, z.GetUint()); + EXPECT_EQ(5678u, z.GetUint()); z = 2147483648u; // 2^31, cannot cast as int EXPECT_EQ(2147483648u, z.GetUint()); @@ -196,9 +196,9 @@ TEST(Value, Int64) { Value x(int64_t(1234LL)); EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(1234, x.GetInt()); - EXPECT_EQ(1234, x.GetUint()); + EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234, x.GetInt64()); - EXPECT_EQ(1234, x.GetUint64()); + EXPECT_EQ(1234u, x.GetUint64()); EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsInt()); EXPECT_TRUE(x.IsUint()); @@ -241,9 +241,9 @@ TEST(Value, Uint64) { Value x(uint64_t(1234LL)); EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(1234, x.GetInt()); - EXPECT_EQ(1234, x.GetUint()); + EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234, x.GetInt64()); - EXPECT_EQ(1234, x.GetUint64()); + EXPECT_EQ(1234u, x.GetUint64()); EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsInt()); EXPECT_TRUE(x.IsUint()); @@ -310,7 +310,7 @@ TEST(Value, String) { EXPECT_EQ(kStringType, x.GetType()); EXPECT_TRUE(x.IsString()); EXPECT_STREQ("Hello", x.GetString()); - EXPECT_EQ(5, x.GetStringLength()); + EXPECT_EQ(5u, x.GetStringLength()); EXPECT_FALSE(x.IsNumber()); EXPECT_FALSE(x.IsNull()); @@ -326,20 +326,20 @@ TEST(Value, String) { //x.SetString("World"); x.SetString("World", 5); EXPECT_STREQ("Hello", c.GetString()); - EXPECT_EQ(5, c.GetStringLength()); + EXPECT_EQ(5u, c.GetStringLength()); // Constructor with type Value y(kStringType); EXPECT_TRUE(y.IsString()); EXPECT_EQ(0, y.GetString()); - EXPECT_EQ(0, y.GetStringLength()); + EXPECT_EQ(0u, y.GetStringLength()); // SetConsttring() Value z; //z.SetString("Hello"); z.SetString("Hello", 5); EXPECT_STREQ("Hello", z.GetString()); - EXPECT_EQ(5, z.GetStringLength()); + EXPECT_EQ(5u, z.GetStringLength()); // SetString() char s[] = "World"; @@ -347,7 +347,7 @@ TEST(Value, String) { w.SetString(s, (SizeType)strlen(s), allocator); s[0] = '\0'; EXPECT_STREQ("World", w.GetString()); - EXPECT_EQ(5, w.GetStringLength()); + EXPECT_EQ(5u, w.GetStringLength()); } TEST(Value, Array) { @@ -358,10 +358,10 @@ TEST(Value, Array) { EXPECT_EQ(kArrayType, x.GetType()); EXPECT_TRUE(x.IsArray()); EXPECT_TRUE(x.Empty()); - EXPECT_EQ(0, x.Size()); + EXPECT_EQ(0u, x.Size()); EXPECT_TRUE(y.IsArray()); EXPECT_TRUE(y.Empty()); - EXPECT_EQ(0, y.Size()); + EXPECT_EQ(0u, y.Size()); EXPECT_FALSE(x.IsNull()); EXPECT_FALSE(x.IsBool()); @@ -381,9 +381,9 @@ TEST(Value, Array) { x.PushBack(v, allocator); EXPECT_FALSE(x.Empty()); - EXPECT_EQ(4, x.Size()); + EXPECT_EQ(4u, x.Size()); EXPECT_FALSE(y.Empty()); - EXPECT_EQ(4, y.Size()); + EXPECT_EQ(4u, y.Size()); EXPECT_TRUE(x[SizeType(0)].IsNull()); EXPECT_TRUE(x[1u].IsTrue()); EXPECT_TRUE(x[2u].IsFalse()); @@ -427,7 +427,7 @@ TEST(Value, Array) { // PopBack() x.PopBack(); - EXPECT_EQ(3, x.Size()); + EXPECT_EQ(3u, x.Size()); EXPECT_TRUE(y[SizeType(0)].IsNull()); EXPECT_TRUE(y[1].IsTrue()); EXPECT_TRUE(y[2].IsFalse()); @@ -435,9 +435,9 @@ TEST(Value, Array) { // Clear() x.Clear(); EXPECT_TRUE(x.Empty()); - EXPECT_EQ(0, x.Size()); + EXPECT_EQ(0u, x.Size()); EXPECT_TRUE(y.Empty()); - EXPECT_EQ(0, y.Size()); + EXPECT_EQ(0u, y.Size()); // SetArray() Value z; @@ -589,4 +589,4 @@ TEST(Value, RemoveLastElement) { EXPECT_TRUE(objVal.HasMember("var3")); objVal.RemoveMember("var3"); // Assertion here in r61 EXPECT_FALSE(objVal.HasMember("var3")); -} \ No newline at end of file +} diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index b7fba1ce..9d81018e 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -12,7 +12,7 @@ TEST(Writer, Compact) { Reader reader; reader.Parse<0>(s, writer); EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.GetString()); - EXPECT_EQ(77, buffer.GetSize()); + EXPECT_EQ(77u, buffer.GetSize()); } // json -> parse -> writer -> json @@ -64,4 +64,4 @@ TEST(Writer, Transcode) { GenericReader, UTF16<> > reader; reader.Parse<0>(s, writer); EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"dollar\":\"\x24\",\"cents\":\"\xC2\xA2\",\"euro\":\"\xE2\x82\xAC\",\"gclef\":\"\xF0\x9D\x84\x9E\"}", buffer.GetString()); -} \ No newline at end of file +}