From 83cc92161be96d7f2113a3ec9f62109d828e1eec Mon Sep 17 00:00:00 2001 From: Jordan Bayles Date: Thu, 6 Jun 2019 13:41:47 -0700 Subject: [PATCH] Fix JSON_USE_EXCEPTION=0 use case This patch fixes the JSON_USE_EXCEPTION flag. Currently, due to the throwRuntimeError and throwLogicError methods implemented in json_value, even if JSON_USE_EXCEPTION is set to 0 jsoncpp will still throw. This breaks integration into projects with -fno-exceptions set, such as Chromium. --- include/json/value.h | 2 ++ src/lib_json/json_value.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/json/value.h b/include/json/value.h index 5f8d214..06d89ae 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -50,6 +50,7 @@ */ namespace Json { +#if JSON_USE_EXCEPTION /** Base class for all exceptions we throw. * * We use nothing but these internally. Of course, STL can throw others. @@ -85,6 +86,7 @@ class JSON_API LogicError : public Exception { public: LogicError(String const& msg); }; +#endif /// used internally JSONCPP_NORETURN void throwRuntimeError(String const& msg); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index b046c19..cc92d44 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -226,6 +226,7 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); } namespace Json { +#if JSON_USE_EXCEPTION Exception::Exception(String msg) : msg_(std::move(msg)) {} Exception::~Exception() JSONCPP_NOEXCEPT {} char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); } @@ -237,6 +238,14 @@ JSONCPP_NORETURN void throwRuntimeError(String const& msg) { JSONCPP_NORETURN void throwLogicError(String const& msg) { throw LogicError(msg); } +# else // !JSON_USE_EXCEPTION +JSONCPP_NORETURN void throwRuntimeError(String const& msg) { + abort(); +} +JSONCPP_NORETURN void throwLogicError(String const& msg) { + abort(); +} +#endif // ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////