Skip to content

Commit d2fc18a

Browse files
committed
Merge pull request open-source-parsers#446 from ya1gaurav/patch-37
NORETURN for throw functions in 0.x.y branch
2 parents 0fc5112 + aec261a commit d2fc18a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
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
*/

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ RuntimeError::RuntimeError(std::string const& msg)
168168
LogicError::LogicError(std::string const& msg)
169169
: Exception(msg)
170170
{}
171-
void throwRuntimeError(std::string const& msg)
171+
JSONCPP_NORETURN void throwRuntimeError(std::string const& msg)
172172
{
173173
throw RuntimeError(msg);
174174
}
175-
void throwLogicError(std::string const& msg)
175+
JSONCPP_NORETURN void throwLogicError(std::string const& msg)
176176
{
177177
throw LogicError(msg);
178178
}

0 commit comments

Comments
 (0)