Skip to content

Commit 92f99bc

Browse files
committed
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.
1 parent b4538b5 commit 92f99bc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/rapidjson/rapidjson.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ RAPIDJSON_NAMESPACE_END
612612
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
613613
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
614614
#else
615-
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
615+
#include <cassert>
616+
#define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
616617
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
617618
#else
618619
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)

test/unittest/unittest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class AssertException : public std::logic_error {
122122

123123
#ifndef RAPIDJSON_ASSERT
124124
#define RAPIDJSON_ASSERT(x) (!(x) ? throw AssertException(RAPIDJSON_STRINGIFY(x)) : (void)0u)
125+
#ifndef RAPIDJSON_ASSERT_THROWS
126+
#define RAPIDJSON_ASSERT_THROWS
127+
#endif
125128
#endif
126129

127130
class Random {

0 commit comments

Comments
 (0)