Re-add JSONCPP_NORETURN (#1041)

Fixes Visual Studio 2013 compatibility.
This commit is contained in:
es1x 2019-10-11 21:33:36 +03:00 committed by Jordan Bayles
parent f34bf24bbd
commit 2ee3b1dbb1
2 changed files with 18 additions and 6 deletions

View File

@ -9,6 +9,18 @@
#if !defined(JSON_IS_AMALGAMATION) #if !defined(JSON_IS_AMALGAMATION)
#include "forwards.h" #include "forwards.h"
#endif // if !defined(JSON_IS_AMALGAMATION) #endif // if !defined(JSON_IS_AMALGAMATION)
// 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) && _MSC_VER == 1800
#define JSONCPP_NORETURN __declspec(noreturn)
#else
#define JSONCPP_NORETURN [[noreturn]]
#endif
#endif
#include <array> #include <array>
#include <exception> #include <exception>
#include <memory> #include <memory>
@ -76,9 +88,9 @@ public:
#endif #endif
/// used internally /// used internally
[[noreturn]] void throwRuntimeError(String const& msg); JSONCPP_NORETURN void throwRuntimeError(String const& msg);
/// used internally /// used internally
[[noreturn]] void throwLogicError(String const& msg); JSONCPP_NORETURN void throwLogicError(String const& msg);
/** \brief Type of the value held by a Value object. /** \brief Type of the value held by a Value object.
*/ */

View File

@ -207,13 +207,13 @@ Exception::~Exception() JSONCPP_NOEXCEPT {}
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); } char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {} RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
LogicError::LogicError(String const& msg) : Exception(msg) {} LogicError::LogicError(String const& msg) : Exception(msg) {}
[[noreturn]] void throwRuntimeError(String const& msg) { JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
throw RuntimeError(msg); throw RuntimeError(msg);
} }
[[noreturn]] void throwLogicError(String const& msg) { throw LogicError(msg); } JSONCPP_NORETURN void throwLogicError(String const& msg) { throw LogicError(msg); }
#else // !JSON_USE_EXCEPTION #else // !JSON_USE_EXCEPTION
[[noreturn]] void throwRuntimeError(String const& msg) { abort(); } JSONCPP_NORETURN void throwRuntimeError(String const& msg) { abort(); }
[[noreturn]] void throwLogicError(String const& msg) { abort(); } JSONCPP_NORETURN void throwLogicError(String const& msg) { abort(); }
#endif #endif
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////