-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
consider using __cpp_exceptions and/or __EXCEPTIONS to disable/enable exception support #498
Comments
Thanks, I did not find these macros. Do you know which compilers are covered with them? |
gcc and clang definitely, others I don't know. You can test for a specific compiler than go on from there. But it is a proposed standard extension too. |
I guess you could also do #if defined(__cpp_exceptions) && (1 == __cpp_exceptions) No need to a specific compiler test then. |
I'm checking for |
If you do it doesn't work too well :) I tried to compile without exception support and it didn't work, I checked and saw I'd have to define some macro manually to get your library to compile. |
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.
@user1095108 I added a fix (see 65dfc97). Does this work for you? |
Sigh... MSVC seems not to use |
I'd still check if __cpp_exceptions is defined. The macro is not part of c++98, just the exceptions themselves. Otherwise, great. |
What do you mean? |
From https://msdn.microsoft.com/en-us/library/b0084kay.aspx:
|
It is a proposed extension of c++, gcc and clang already implement it, but MSVC has its own thing as you noticed. |
I see. If the fix works for you, I can close the ticket. |
sure, but you won't put this into the main branch? I think you want a
generic solution.
2017-03-11 18:21 GMT+01:00 Niels Lohmann <[email protected]>:
… I see. If the fix works for you, I can close the ticket.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH6jVGjolDowt0m-MvgkoO2kWEv2h4ITks5rktgUgaJpZM4MaOyK>
.
|
I will, but first I wanted your OK, and I want to wait for Travis to finish. |
ok, as I wrote earlier, I'd check #if defined(__cpp_exceptions) && (1 ==
__cpp_exceptions) ...
You may have your preferences though, maybe an existent macro definition
could override everything.
2017-03-11 18:36 GMT+01:00 Niels Lohmann <[email protected]>:
… I will, but first I wanted your OK, and I want to wait for Travis to
finish.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH6jVOPlw9gr1YvjtAsyXfYDM-SQ-xynks5rktuQgaJpZM4MaOyK>
.
|
You're right, it is better to used |
I'm ok with this.
g++ -x c++ -dM -E - < /dev/null | grep _cpp_exceptions
2017-03-11 18:44 GMT+01:00 Niels Lohmann <[email protected]>:
… You're right, it is better to used defined(). But I would not care about
the value of the macro - if someone defines it, it better has the standard
semantics.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH6jVExKCs_UCxw8ct0NT0k7BLxVQptfks5rkt2SgaJpZM4MaOyK>
.
|
|
Yes, you might want to use that or just check if it is defined :)
2017-03-11 18:53 GMT+01:00 Niels Lohmann <[email protected]>:
… $ g++ -x c++ -dM -E - < /dev/null | grep _cpp_exceptions
#define __cpp_exceptions 199711
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH6jVF8yJZ-EN3yL0VIot22yO8x-IsXpks5rkt-agaJpZM4MaOyK>
.
|
GCC 4.9 does not define |
It's your library, I personally don't care about 4.9 anymore.
2017-03-11 20:09 GMT+01:00 Niels Lohmann <[email protected]>:
… GCC 4.9 does not define __cpp_exceptions. I might need __EXCEPTIONS there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AH6jVGHAETwHtKvUrOvksE6PsHh0fk6aks5rkvFpgaJpZM4MaOyK>
.
|
It is much more user-friendly if exception support is automatically detected.
resources:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
http://en.cppreference.com/w/cpp/experimental/feature_test
The text was updated successfully, but these errors were encountered: