From 20564b3f0c745b775693f68dc7d1f1d089bcc0df Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 16 Mar 2016 11:22:18 +0530 Subject: [PATCH 1/2] NORETURN for throw functions in 0.x.y branch Resolve issue - https://github.com/open-source-parsers/jsoncpp/issues/389 --- include/json/value.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index fe55bfd..2c5667a 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -29,6 +29,19 @@ #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +//Conditional NORETURN attribute on the throw functions would: +// a) suppress false positives from static code analysis +// b) possibly improve optimization opportunities. +#if !defined(JSONCPP_NORETURN) +# if defined(_MSC_VER) +# define JSONCPP_NORETURN __declspec(noreturn) +# elif defined(__GNUC__) +# define JSONCPP_NORETURN __attribute__ ((__noreturn__)) +# else +# define JSONCPP_NORETURN +# endif +#endif + /** \brief JSON (JavaScript Object Notation). */ namespace Json { @@ -69,9 +82,9 @@ public: }; /// used internally -void throwRuntimeError(std::string const& msg); +JSONCPP_NORETURN void throwRuntimeError(std::string const& msg); /// used internally -void throwLogicError(std::string const& msg); +JSONCPP_NORETURN void throwLogicError(std::string const& msg); /** \brief Type of the value held by a Value object. */ From aec261a899f028892efebb04bf7f1dfa01b095a4 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 16 Mar 2016 11:23:36 +0530 Subject: [PATCH 2/2] NORETURN for throw functions in 0.x.y branch Added in definition also. --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 4a77d00..018b9cd 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -168,11 +168,11 @@ RuntimeError::RuntimeError(std::string const& msg) LogicError::LogicError(std::string const& msg) : Exception(msg) {} -void throwRuntimeError(std::string const& msg) +JSONCPP_NORETURN void throwRuntimeError(std::string const& msg) { throw RuntimeError(msg); } -void throwLogicError(std::string const& msg) +JSONCPP_NORETURN void throwLogicError(std::string const& msg) { throw LogicError(msg); }