@@ -863,30 +863,39 @@ bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name,
863863}
864864
865865#if GTEST_HAS_SEH
866- // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
867- // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
868- // This function is useful as an __except condition.
869- int UnitTestOptions::GTestShouldProcessSEH (DWORD exception_code) {
866+ static std::string FormatSehExceptionMessage (DWORD exception_code,
867+ const char * location) {
868+ Message message;
869+ message << " SEH exception with code 0x" << std::setbase (16 ) << exception_code
870+ << std::setbase (10 ) << " thrown in " << location << " ." ;
871+ return message.GetString ();
872+ }
873+
874+ int UnitTestOptions::GTestProcessSEH (DWORD seh_code, const char * location) {
870875 // Google Test should handle a SEH exception if:
871876 // 1. the user wants it to, AND
872- // 2. this is not a breakpoint exception, AND
877+ // 2. this is not a breakpoint exception or stack overflow , AND
873878 // 3. this is not a C++ exception (VC++ implements them via SEH,
874879 // apparently).
875880 //
876881 // SEH exception code for C++ exceptions.
877882 // (see http://support.microsoft.com/kb/185294 for more information).
878883 const DWORD kCxxExceptionCode = 0xe06d7363 ;
879884
880- bool should_handle = true ;
885+ if (!GTEST_FLAG_GET (catch_exceptions) || seh_code == kCxxExceptionCode ||
886+ seh_code == EXCEPTION_BREAKPOINT ||
887+ seh_code == EXCEPTION_STACK_OVERFLOW) {
888+ return EXCEPTION_CONTINUE_SEARCH; // Don't handle these exceptions
889+ }
881890
882- if (! GTEST_FLAG_GET (catch_exceptions))
883- should_handle = false ;
884- else if (exception_code == EXCEPTION_BREAKPOINT)
885- should_handle = false ;
886- else if (exception_code == kCxxExceptionCode )
887- should_handle = false ;
891+ internal::ReportFailureInUnknownLocation (
892+ TestPartResult:: kFatalFailure ,
893+ FormatSehExceptionMessage (seh_code, location) +
894+ " \n "
895+ " Stack trace: \n " +
896+ ::testing::internal::GetCurrentOsStackTraceExceptTop ( 1 )) ;
888897
889- return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ;
898+ return EXCEPTION_EXECUTE_HANDLER;
890899}
891900#endif // GTEST_HAS_SEH
892901
@@ -2553,23 +2562,6 @@ bool Test::HasSameFixtureClass() {
25532562 return true ;
25542563}
25552564
2556- #if GTEST_HAS_SEH
2557-
2558- // Adds an "exception thrown" fatal failure to the current test. This
2559- // function returns its result via an output parameter pointer because VC++
2560- // prohibits creation of objects with destructors on stack in functions
2561- // using __try (see error C2712).
2562- static std::string* FormatSehExceptionMessage (DWORD exception_code,
2563- const char * location) {
2564- Message message;
2565- message << " SEH exception with code 0x" << std::setbase (16 ) << exception_code
2566- << std::setbase (10 ) << " thrown in " << location << " ." ;
2567-
2568- return new std::string (message.GetString ());
2569- }
2570-
2571- #endif // GTEST_HAS_SEH
2572-
25732565namespace internal {
25742566
25752567#if GTEST_HAS_EXCEPTIONS
@@ -2611,16 +2603,8 @@ Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(),
26112603#if GTEST_HAS_SEH
26122604 __try {
26132605 return (object->*method)();
2614- } __except (internal::UnitTestOptions::GTestShouldProcessSEH ( // NOLINT
2615- GetExceptionCode ())) {
2616- // We create the exception message on the heap because VC++ prohibits
2617- // creation of objects with destructors on stack in functions using __try
2618- // (see error C2712).
2619- std::string* exception_message =
2620- FormatSehExceptionMessage (GetExceptionCode (), location);
2621- internal::ReportFailureInUnknownLocation (TestPartResult::kFatalFailure ,
2622- *exception_message);
2623- delete exception_message;
2606+ } __except (internal::UnitTestOptions::GTestProcessSEH ( // NOLINT
2607+ GetExceptionCode (), location)) {
26242608 return static_cast <Result>(0 );
26252609 }
26262610#else
@@ -5655,8 +5639,10 @@ void UnitTestImpl::ConfigureXmlOutput() {
56555639 << output_format << " \" ignored." ;
56565640 }
56575641#else
5658- GTEST_LOG_ (ERROR) << " ERROR: alternative output formats require "
5659- << " GTEST_HAS_FILE_SYSTEM to be enabled" ;
5642+ if (!output_format.empty ()) {
5643+ GTEST_LOG_ (ERROR) << " ERROR: alternative output formats require "
5644+ << " GTEST_HAS_FILE_SYSTEM to be enabled" ;
5645+ }
56605646#endif // GTEST_HAS_FILE_SYSTEM
56615647}
56625648
0 commit comments