Upgrade ScopeGuard for Visual Studio 2015
authorJeremy Wright <jwright@itracs.com>
Sat, 19 Mar 2016 00:11:23 +0000 (17:11 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Sat, 19 Mar 2016 00:20:20 +0000 (17:20 -0700)
Summary:Upgrade UncaughtExceptionCounter to use std::uncaught_exceptions on Visual Studio 2015 Update 1
Closes https://github.com/facebook/folly/pull/358

Reviewed By: yfeldblum

Differential Revision: D3066005

Pulled By: Orvid

fb-gh-sync-id: 6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
shipit-source-id: 6bc7129aa794257b1f6e7a084139d8a3a52fa4a8

folly/ScopeGuard.h
folly/detail/UncaughtExceptionCounter.h

index 3822e4d130d777f81edb060d5df583ee4bc21581..8b16fae1e1deed2d330d8aa12809356530c8155d 100644 (file)
@@ -173,7 +173,8 @@ typedef ScopeGuardImplBase&& ScopeGuard;
 namespace detail {
 
 #if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
-    defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
+    defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD) ||          \
+    defined(FOLLY_EXCEPTION_COUNT_USE_STD)
 
 /**
  * ScopeGuard used for executing a function when leaving the current scope
@@ -265,7 +266,8 @@ operator+(detail::ScopeGuardOnExit, FunctionType&& fn) {
   = ::folly::detail::ScopeGuardOnExit() + [&]() noexcept
 
 #if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
-    defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
+    defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD) ||          \
+    defined(FOLLY_EXCEPTION_COUNT_USE_STD)
 #define SCOPE_FAIL \
   auto FB_ANONYMOUS_VARIABLE(SCOPE_FAIL_STATE) \
   = ::folly::detail::ScopeGuardOnFail() + [&]() noexcept
index 7399e18e1f362f9bb492be3898376c860122e71d..b0119c0646e79da54d8882559ff6acd01b0299c6 100644 (file)
@@ -27,11 +27,14 @@ struct __cxa_eh_globals;
 // declared in cxxabi.h from libstdc++-v3
 extern "C" __cxa_eh_globals* __cxa_get_globals() noexcept;
 }
-#elif defined(_MSC_VER) && (_MSC_VER >= 1400) // MSVC++ 8.0 or greater
+#elif defined(_MSC_VER) && (_MSC_VER >= 1400) && \
+    (_MSC_VER < 1900) // MSVC++ 8.0 or greater
 #define FOLLY_EXCEPTION_COUNT_USE_GETPTD
 // forward declaration (originally defined in mtdll.h from MSVCRT)
 struct _tiddata;
 extern "C" _tiddata* _getptd(); // declared in mtdll.h from MSVCRT
+#elif defined(_MSC_VER) && (_MSC_VER >= 1900) // MSVC++ 2015
+#define FOLLY_EXCEPTION_COUNT_USE_STD
 #else
 // Raise an error when trying to use this on unsupported platforms.
 #error "Unsupported platform, don't include this header."
@@ -84,6 +87,8 @@ inline int UncaughtExceptionCounter::getUncaughtExceptionCount() noexcept {
   // The offset below returns _tiddata::_ProcessingThrow.
   return *(reinterpret_cast<int*>(static_cast<char*>(
       static_cast<void*>(_getptd())) + sizeof(void*) * 28 + 0x4 * 8));
+#elif defined(FOLLY_EXCEPTION_COUNT_USE_STD)
+  return std::uncaught_exceptions();
 #endif
 }