Skip to content

Commit

Permalink
🔨 using __cpp_exceptions to detect exception support #498
Browse files Browse the repository at this point in the history
I used __EXCEPTIONS to detect whether exceptions are supported.
Apparently, this is a macro that is only used by libstdc++
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64276). It’s much cleaner
to use __cpp_exceptions as it is in the standard since C++98.

Note that compiling the unit-tests with “-fno-exceptions” still does
not work, because Catch uses throw internally. However, the library’s
exceptions can be switched off by defining JSON_NOEXCEPTION.
  • Loading branch information
nlohmann committed Mar 11, 2017
1 parent ff0b18d commit 65dfc97
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SOFTWARE.
#endif

// allow to disable exceptions
#if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS)
#if __cpp_exceptions && not defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
Expand Down
2 changes: 1 addition & 1 deletion src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SOFTWARE.
#endif

// allow to disable exceptions
#if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS)
#if __cpp_exceptions && not defined(JSON_NOEXCEPTION)
#define JSON_THROW(exception) throw exception
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
Expand Down

0 comments on commit 65dfc97

Please sign in to comment.