@@ -863,30 +863,39 @@ bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name,
863
863
}
864
864
865
865
#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) {
870
875
// Google Test should handle a SEH exception if:
871
876
// 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
873
878
// 3. this is not a C++ exception (VC++ implements them via SEH,
874
879
// apparently).
875
880
//
876
881
// SEH exception code for C++ exceptions.
877
882
// (see http://support.microsoft.com/kb/185294 for more information).
878
883
const DWORD kCxxExceptionCode = 0xe06d7363 ;
879
884
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
+ }
881
890
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 )) ;
888
897
889
- return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ;
898
+ return EXCEPTION_EXECUTE_HANDLER;
890
899
}
891
900
#endif // GTEST_HAS_SEH
892
901
@@ -2553,23 +2562,6 @@ bool Test::HasSameFixtureClass() {
2553
2562
return true ;
2554
2563
}
2555
2564
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
-
2573
2565
namespace internal {
2574
2566
2575
2567
#if GTEST_HAS_EXCEPTIONS
@@ -2611,16 +2603,8 @@ Result HandleSehExceptionsInMethodIfSupported(T* object, Result (T::*method)(),
2611
2603
#if GTEST_HAS_SEH
2612
2604
__try {
2613
2605
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)) {
2624
2608
return static_cast <Result>(0 );
2625
2609
}
2626
2610
#else
@@ -5655,8 +5639,10 @@ void UnitTestImpl::ConfigureXmlOutput() {
5655
5639
<< output_format << " \" ignored." ;
5656
5640
}
5657
5641
#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
+ }
5660
5646
#endif // GTEST_HAS_FILE_SYSTEM
5661
5647
}
5662
5648
0 commit comments