Skip to content

NORETURN for throw functions in 0.x.y branch #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)

//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)
# define JSONCPP_NORETURN __declspec(noreturn)
# elif defined(__GNUC__)
# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
# else
# define JSONCPP_NORETURN
# endif
#endif

/** \brief JSON (JavaScript Object Notation).
*/
namespace Json {
Expand Down Expand Up @@ -69,9 +82,9 @@ class JSON_API LogicError : public Exception {
};

/// used internally
void throwRuntimeError(std::string const& msg);
JSONCPP_NORETURN void throwRuntimeError(std::string const& msg);
/// used internally
void throwLogicError(std::string const& msg);
JSONCPP_NORETURN void throwLogicError(std::string const& msg);

/** \brief Type of the value held by a Value object.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ RuntimeError::RuntimeError(std::string const& msg)
LogicError::LogicError(std::string const& msg)
: Exception(msg)
{}
void throwRuntimeError(std::string const& msg)
JSONCPP_NORETURN void throwRuntimeError(std::string const& msg)
{
throw RuntimeError(msg);
}
void throwLogicError(std::string const& msg)
JSONCPP_NORETURN void throwLogicError(std::string const& msg)
{
throw LogicError(msg);
}
Expand Down