Skip to content

Commit 59e327f

Browse files
committed
Merge pull request #445 from ya1gaurav/patch-36
Added NORETURN for throw functions.
2 parents e29b671 + 0b597b4 commit 59e327f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Diff for: include/json/value.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
#include <cpptl/forwards.h>
2323
#endif
2424

25+
//Conditional NORETURN attribute on the throw functions would:
26+
// a) suppress false positives from static code analysis
27+
// b) possibly improve optimization opportunities.
28+
#if !defined(JSONCPP_NORETURN)
29+
# if defined(_MSC_VER)
30+
# define JSONCPP_NORETURN __declspec(noreturn)
31+
# elif defined(__GNUC__)
32+
# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
33+
# else
34+
# define JSONCPP_NORETURN
35+
# endif
36+
#endif
37+
2538
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
2639
// be used by...
2740
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
@@ -69,9 +82,9 @@ class JSON_API LogicError : public Exception {
6982
};
7083

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

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

Diff for: src/lib_json/json_value.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ RuntimeError::RuntimeError(JSONCPP_STRING const& msg)
171171
LogicError::LogicError(JSONCPP_STRING const& msg)
172172
: Exception(msg)
173173
{}
174-
void throwRuntimeError(JSONCPP_STRING const& msg)
174+
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg)
175175
{
176176
throw RuntimeError(msg);
177177
}
178-
void throwLogicError(JSONCPP_STRING const& msg)
178+
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg)
179179
{
180180
throw LogicError(msg);
181181
}

0 commit comments

Comments
 (0)