Skip to content

Commit 5b0610a

Browse files
author
Benjamin Lee
committed
Handle non-throwing exception specifications that can still throw Tencent#1280
1 parent c0daf75 commit 5b0610a

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
@@ -591,6 +591,19 @@ RAPIDJSON_NAMESPACE_END
591591

592592
//!@endcond
593593

594+
///////////////////////////////////////////////////////////////////////////////
595+
// RAPIDJSON_NOEXCEPT_ASSERT
596+
597+
#ifdef RAPIDJSON_ASSERT_THROWS
598+
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
599+
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
600+
#else
601+
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
602+
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
603+
#else
604+
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
605+
#endif // RAPIDJSON_ASSERT_THROWS
606+
594607
///////////////////////////////////////////////////////////////////////////////
595608
// new/delete
596609

0 commit comments

Comments
 (0)