Skip to content

Commit 20564b3

Browse files
committed
NORETURN for throw functions in 0.x.y branch
Resolve issue - open-source-parsers#389
1 parent 0fc5112 commit 20564b3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

include/json/value.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929
#pragma warning(disable : 4251)
3030
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
3131

32+
//Conditional NORETURN attribute on the throw functions would:
33+
// a) suppress false positives from static code analysis
34+
// b) possibly improve optimization opportunities.
35+
#if !defined(JSONCPP_NORETURN)
36+
# if defined(_MSC_VER)
37+
# define JSONCPP_NORETURN __declspec(noreturn)
38+
# elif defined(__GNUC__)
39+
# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
40+
# else
41+
# define JSONCPP_NORETURN
42+
# endif
43+
#endif
44+
3245
/** \brief JSON (JavaScript Object Notation).
3346
*/
3447
namespace Json {
@@ -69,9 +82,9 @@ class JSON_API LogicError : public Exception {
6982
};
7083

7184
/// used internally
72-
void throwRuntimeError(std::string const& msg);
85+
JSONCPP_NORETURN void throwRuntimeError(std::string const& msg);
7386
/// used internally
74-
void throwLogicError(std::string const& msg);
87+
JSONCPP_NORETURN void throwLogicError(std::string const& msg);
7588

7689
/** \brief Type of the value held by a Value object.
7790
*/

0 commit comments

Comments
 (0)