From e2cd486e6e0ea76cb39f2a322bcd12bcfb1829fd Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 4 Jul 2014 17:25:33 +0800 Subject: [PATCH] Fixes -Wswitch-default warnings --- build/premake4.lua | 4 ++-- include/rapidjson/document.h | 6 ++++++ include/rapidjson/encodedstream.h | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build/premake4.lua b/build/premake4.lua index 4c3dd0f..1ef7ff5 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" + buildoptions "-msse4.2 -Werror -Wall -Wextra -Wswitch-default" project "gtest" kind "StaticLib" @@ -154,7 +154,7 @@ solution "example" defines { "_CRT_SECURE_NO_WARNINGS" } configuration "gmake" - buildoptions "-Werror -Wall -Wextra -Weffc++" + buildoptions "-Werror -Wall -Wextra -Weffc++ -Wswitch-default" project "condense" kind "ConsoleApp" diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index e735983..d351fce 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -319,6 +319,9 @@ public: case kCopyStringFlag: Allocator::Free(const_cast(data_.s.str)); break; + + default: + break; // Do nothing for other types. } } } @@ -794,6 +797,9 @@ int z = a[0u].GetInt(); // This works too. else if (IsUint64()) handler.Uint64(data_.n.u64); else handler.Double(data_.n.d); break; + + default: + RAPIDJSON_ASSERT(false); } return *this; } diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index 3be89f9..a11547a 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -158,10 +158,11 @@ private: case 0x01: type_ = kUTF32LE; break; case 0x05: type_ = kUTF16LE; break; case 0x0F: type_ = kUTF8; break; + default: break; // Use type defined by user. } } - // RUntime check whether the size of character type is sufficient. It only perform checks with assertion. + // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. switch (type_) { case kUTF8: // Do nothing @@ -174,6 +175,8 @@ private: case kUTF32BE: RAPIDJSON_ASSERT(sizeof(Ch) >= 4); break; + default: + RAPIDJSON_ASSERT(false); // Invalid type } } @@ -216,6 +219,8 @@ public: case kUTF8: // Do nothing break; + default: + RAPIDJSON_ASSERT(false); // Invalid UTFType } static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) };