From b4538b53637b7caf41cd8ce993514d1d54b2d1fb Mon Sep 17 00:00:00 2001 From: ylavic Date: Sun, 28 Apr 2019 00:51:20 +0200 Subject: [PATCH 1/2] Fix compilation of sortkeys.cpp with MSVC 2013 (hopefully). --- example/sortkeys/sortkeys.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/sortkeys/sortkeys.cpp b/example/sortkeys/sortkeys.cpp index c473784..7ede9fb 100644 --- a/example/sortkeys/sortkeys.cpp +++ b/example/sortkeys/sortkeys.cpp @@ -45,9 +45,8 @@ int main() { // C++11 supports std::move() of Value so it always have no problem for std::sort(). // Some C++03 implementations of std::sort() requires copy constructor which causes compilation error. // Needs a sorting function only depends on std::swap() instead. -#if __cplusplus >= 201103L || !defined(__GLIBCXX__) +#if __cplusplus >= 201103L || (!defined(__GLIBCXX__) && (!defined(_MSC_VER) || _MSC_VER >= 1900)) std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator()); -#endif printIt(d); @@ -59,4 +58,5 @@ int main() { "zeta": false } */ +#endif } From 92f99bc2ee1c04669036ba2a35ef76ad1c2cad79 Mon Sep 17 00:00:00 2001 From: ylavic Date: Fri, 12 Apr 2019 00:31:28 +0200 Subject: [PATCH 2/2] RAPIDJSON_NOEXCEPT_ASSERT() should never throw. clang warns about throwing from RAPIDJSON_NOEXCEPT_ASSERT() in a nothrow context. If RAPIDJSON_ASSERT() throws it can never be used for _NOEXCEPT_ASSERT(), so use C assert() instead. Finally (and originally), since RAPIDJSON_ASSERT() in "unittest.h" throws, make it define RAPIDJSON_ASSERT_THROWS for RAPIDJSON_NOEXCEPT_ASSERT() to now do the right thing. --- include/rapidjson/rapidjson.h | 3 ++- test/unittest/unittest.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 549936f..330803e 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -612,7 +612,8 @@ RAPIDJSON_NAMESPACE_END #if RAPIDJSON_HAS_CXX11_NOEXCEPT #define RAPIDJSON_NOEXCEPT_ASSERT(x) #else -#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x) +#include +#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x) #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT #else #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x) diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index 84c1b73..0afac09 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -122,6 +122,9 @@ public: #ifndef RAPIDJSON_ASSERT #define RAPIDJSON_ASSERT(x) (!(x) ? throw AssertException(RAPIDJSON_STRINGIFY(x)) : (void)0u) +#ifndef RAPIDJSON_ASSERT_THROWS +#define RAPIDJSON_ASSERT_THROWS +#endif #endif class Random {