-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
If you have:
class Exception { };
void foo(void) { throw new Exception(); }
EXPECT_THROW(foo(), Exception);
The report will say that Exception was not thrown. This is because the
GTEST_TEST_THROW only catches "expected_exception const&" instead of also
considering "expected_exception const*".
It may be bad style to throw a pointer to an exception, but there's a lot
of legacy code out there that uses "throw new Exception()" instead of
simply "throw Exception()".
The following patch fixes this, and prevents a memory leak in the case of
pointers to exception.
====
//depot/agent/main/ThirdPartySource/gtest/1.1.0/include/gtest/internal/gtest-int
ernal.h#1
-
C:\depot\agent\main\ThirdPartySource\gtest\1.1.0\include\gtest\internal\gtest-in
ternal.h
====
@@ -728,6 +728,10 @@
catch (expected_exception const&) { \
gtest_caught_expected = true; \
} \
+ catch (expected_exception const* expected_exception_const_pointer) { \
+ delete expected_exception_const_pointer;
+ gtest_caught_expected = true; \
+ } \
catch (...) { \
gtest_msg = "Expected: " #statement " throws an exception of type " \
#expected_exception ".\n Actual: it throws a different " \
Original issue reported on code.google.com by halosta...@gmail.com
on 7 Oct 2008 at 5:45