Skip to content

Commit 81af404

Browse files
authored
Merge pull request Tencent#1284 from mobileben/noexcept-assert
Handle non-throwing exception specifications that can still throw Tencent#1280
2 parents 73063f5 + 5b0610a commit 81af404

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/rapidjson/document.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class GenericValue {
629629
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
630630
kNumberAnyFlag
631631
};
632-
RAPIDJSON_ASSERT(type >= kNullType && type <= kNumberType);
632+
RAPIDJSON_NOEXCEPT_ASSERT(type >= kNullType && type <= kNumberType);
633633
data_.f.flags = defaultFlags[type];
634634

635635
// Use ShortString to store empty string.
@@ -831,9 +831,10 @@ class GenericValue {
831831
/*! \param rhs Source of the assignment. It will become a null value after assignment.
832832
*/
833833
GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
834-
RAPIDJSON_ASSERT(this != &rhs);
835-
this->~GenericValue();
836-
RawAssign(rhs);
834+
if (this != &rhs) {
835+
this->~GenericValue();
836+
RawAssign(rhs);
837+
}
837838
return *this;
838839
}
839840

include/rapidjson/rapidjson.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,19 @@ RAPIDJSON_NAMESPACE_END
593593

594594
//!@endcond
595595

596+
///////////////////////////////////////////////////////////////////////////////
597+
// RAPIDJSON_NOEXCEPT_ASSERT
598+
599+
#ifdef RAPIDJSON_ASSERT_THROWS
600+
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
601+
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
602+
#else
603+
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
604+
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
605+
#else
606+
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
607+
#endif // RAPIDJSON_ASSERT_THROWS
608+
596609
///////////////////////////////////////////////////////////////////////////////
597610
// new/delete
598611

0 commit comments

Comments
 (0)