Skip to content

Commit c0ca05f

Browse files
authored
Merge pull request Tencent#1329 from pah/fix-noexcept
Add RAPIDJSON_NOEXCEPT_ASSERT
2 parents c2aa79d + 783b819 commit c0ca05f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

include/rapidjson/document.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo
3737

3838
#ifdef __GNUC__
3939
RAPIDJSON_DIAG_OFF(effc++)
40-
#if __GNUC__ >= 6
41-
RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_NOEXCEPT functions
42-
#endif
4340
#endif // __GNUC__
4441

4542
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
@@ -625,7 +622,7 @@ class GenericValue {
625622
\note Default content for number is zero.
626623
*/
627624
explicit GenericValue(Type type) RAPIDJSON_NOEXCEPT : data_() {
628-
static const uint16_t defaultFlags[7] = {
625+
static const uint16_t defaultFlags[] = {
629626
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kShortStringFlag,
630627
kNumberAnyFlag
631628
};
@@ -831,7 +828,7 @@ class GenericValue {
831828
/*! \param rhs Source of the assignment. It will become a null value after assignment.
832829
*/
833830
GenericValue& operator=(GenericValue& rhs) RAPIDJSON_NOEXCEPT {
834-
if (this != &rhs) {
831+
if (RAPIDJSON_LIKELY(this != &rhs)) {
835832
this->~GenericValue();
836833
RawAssign(rhs);
837834
}

include/rapidjson/rapidjson.h

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

594594
//!@endcond
595595

596+
//! Assertion (in non-throwing contexts).
597+
/*! \ingroup RAPIDJSON_CONFIG
598+
Some functions provide a \c noexcept guarantee, if the compiler supports it.
599+
In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to
600+
throw an exception. This macro adds a separate customization point for
601+
such cases.
602+
603+
Defaults to C \c assert() (as \ref RAPIDJSON_ASSERT), if \c noexcept is
604+
supported, and to \ref RAPIDJSON_ASSERT otherwise.
605+
*/
606+
596607
///////////////////////////////////////////////////////////////////////////////
597608
// RAPIDJSON_NOEXCEPT_ASSERT
598609

0 commit comments

Comments
 (0)