Skip to content

Commit d97ea5b

Browse files
committed
Added NORETURN for throw functions.
Resolve Issue - #389
1 parent e29b671 commit d97ea5b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
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
*/

0 commit comments

Comments
 (0)