Commit 13d4eb3c authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Add FOLLY_HAS_EXCEPTIONS preprocessor symbol

Summary:
[Folly] Add `FOLLY_HAS_EXCEPTIONS` preprocessor symbol.

Add checks for:
* `__cpp_exceptions` and `__has_feature(cxx_exceptions)`.
* MSVC platform.

But avoiding a single unwieldy expression.

And use it in `throw_exception`.

Reviewed By: mnovakovic

Differential Revision: D9732924

fbshipit-source-id: 4ac00e2d84007dfe8307f0e861ab2edfbde80fff
parent a35bd9dd
......@@ -453,3 +453,22 @@ constexpr auto kCpplibVer = 0;
(_MSC_FULL_VER >= 191225816 && _MSVC_LANG > 201402)
#define FOLLY_HAVE_NOEXCEPT_FUNCTION_TYPE 1
#endif
// Define FOLLY_HAS_EXCEPTIONS
#if __cpp_exceptions >= 199711 || FOLLY_HAS_FEATURE(cxx_exceptions)
#define FOLLY_HAS_EXCEPTIONS 1
#elif __GNUC__
#if __EXCEPTIONS
#define FOLLY_HAS_EXCEPTIONS 1
#else // __EXCEPTIONS
#define FOLLY_HAS_EXCEPTIONS 0
#endif // __EXCEPTIONS
#elif FOLLY_MICROSOFT_ABI_VER
#if _CPPUNWIND
#define FOLLY_HAS_EXCEPTIONS 1
#else // _CPPUNWIND
#define FOLLY_HAS_EXCEPTIONS 0
#endif // _CPPUNWIND
#else
#define FOLLY_HAS_EXCEPTIONS 1 // default assumption for unknown platforms
#endif
......@@ -20,6 +20,7 @@
#include <folly/CPortability.h>
#include <folly/CppAttributes.h>
#include <folly/Portability.h>
namespace folly {
......@@ -29,11 +30,11 @@ namespace folly {
/// -fno-exceptions.
template <typename Ex>
[[noreturn]] FOLLY_NOINLINE FOLLY_COLD void throw_exception(Ex&& ex) {
#if (__GNUC__ && !__EXCEPTIONS)
#if FOLLY_HAS_EXCEPTIONS
throw static_cast<Ex&&>(ex);
#else
(void)ex;
std::terminate();
#else
throw static_cast<Ex&&>(ex);
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment