Skip to content

Commit 2ee3b1d

Browse files
es1xbaylesj
es1x
authored andcommittedOct 11, 2019
Re-add JSONCPP_NORETURN (#1041)
Fixes Visual Studio 2013 compatibility.
1 parent f34bf24 commit 2ee3b1d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
 

‎include/json/value.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
#if !defined(JSON_IS_AMALGAMATION)
1010
#include "forwards.h"
1111
#endif // if !defined(JSON_IS_AMALGAMATION)
12+
13+
// Conditional NORETURN attribute on the throw functions would:
14+
// a) suppress false positives from static code analysis
15+
// b) possibly improve optimization opportunities.
16+
#if !defined(JSONCPP_NORETURN)
17+
#if defined(_MSC_VER) && _MSC_VER == 1800
18+
#define JSONCPP_NORETURN __declspec(noreturn)
19+
#else
20+
#define JSONCPP_NORETURN [[noreturn]]
21+
#endif
22+
#endif
23+
1224
#include <array>
1325
#include <exception>
1426
#include <memory>
@@ -76,9 +88,9 @@ class JSON_API LogicError : public Exception {
7688
#endif
7789

7890
/// used internally
79-
[[noreturn]] void throwRuntimeError(String const& msg);
91+
JSONCPP_NORETURN void throwRuntimeError(String const& msg);
8092
/// used internally
81-
[[noreturn]] void throwLogicError(String const& msg);
93+
JSONCPP_NORETURN void throwLogicError(String const& msg);
8294

8395
/** \brief Type of the value held by a Value object.
8496
*/

‎src/lib_json/json_value.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ Exception::~Exception() JSONCPP_NOEXCEPT {}
207207
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
208208
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
209209
LogicError::LogicError(String const& msg) : Exception(msg) {}
210-
[[noreturn]] void throwRuntimeError(String const& msg) {
210+
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
211211
throw RuntimeError(msg);
212212
}
213-
[[noreturn]] void throwLogicError(String const& msg) { throw LogicError(msg); }
213+
JSONCPP_NORETURN void throwLogicError(String const& msg) { throw LogicError(msg); }
214214
#else // !JSON_USE_EXCEPTION
215-
[[noreturn]] void throwRuntimeError(String const& msg) { abort(); }
216-
[[noreturn]] void throwLogicError(String const& msg) { abort(); }
215+
JSONCPP_NORETURN void throwRuntimeError(String const& msg) { abort(); }
216+
JSONCPP_NORETURN void throwLogicError(String const& msg) { abort(); }
217217
#endif
218218

219219
// //////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)
Please sign in to comment.