From 529e6cb5529f626b7c5cf781bdcd5a5720f904c1 Mon Sep 17 00:00:00 2001 From: Moritz Klammler Date: Fri, 18 Jul 2014 23:19:56 +0200 Subject: Applied changes suggested by Christoph Hertzberg to c'tor leak fix. - Enclose exception handling in '#ifdef EIGEN_EXCEPTIONS'. - Use an object counter to demonstrate the bug more readily. --- test/ctorleak.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'test/ctorleak.cpp') diff --git a/test/ctorleak.cpp b/test/ctorleak.cpp index 72ab94b66..f3f4411c8 100644 --- a/test/ctorleak.cpp +++ b/test/ctorleak.cpp @@ -4,11 +4,30 @@ struct Foo { + static unsigned object_count; + static unsigned object_limit; int dummy; - Foo() { if (!internal::random(0, 10)) throw Foo::Fail(); } + + Foo() + { +#ifdef EIGEN_EXCEPTIONS + // TODO: Is this the correct way to handle this? + if (Foo::object_count > Foo::object_limit) { throw Foo::Fail(); } +#endif + ++Foo::object_count; + } + + ~Foo() + { + --Foo::object_count; + } + class Fail : public std::exception {}; }; +unsigned Foo::object_count = 0; +unsigned Foo::object_limit = 0; + namespace Eigen { template<> @@ -34,10 +53,17 @@ namespace Eigen void test_ctorleak() { + Foo::object_count = 0; + Foo::object_limit = internal::random(0, 14 * 92 - 2); +#ifdef EIGEN_EXCEPTIONS try +#endif { Matrix m(14, 92); eigen_assert(false); // not reached } +#ifdef EIGEN_EXCEPTIONS catch (const Foo::Fail&) { /* ignore */ } +#endif + VERIFY_IS_EQUAL(static_cast(0), Foo::object_count); } -- cgit v1.2.3