aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/ctorleak.cpp
diff options
context:
space:
mode:
authorGravatar Moritz Klammler <moritz@klammler.eu>2014-07-18 23:19:56 +0200
committerGravatar Moritz Klammler <moritz@klammler.eu>2014-07-18 23:19:56 +0200
commit529e6cb5529f626b7c5cf781bdcd5a5720f904c1 (patch)
tree5e813fb4f58d6de3709329e1e34c4797f78a3795 /test/ctorleak.cpp
parent58687aa5e638d365d5e41c1e6c66cbfc44fce85f (diff)
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.
Diffstat (limited to 'test/ctorleak.cpp')
-rw-r--r--test/ctorleak.cpp28
1 files changed, 27 insertions, 1 deletions
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<Foo, Dynamic, Dynamic> m(14, 92);
eigen_assert(false); // not reached
}
+#ifdef EIGEN_EXCEPTIONS
catch (const Foo::Fail&) { /* ignore */ }
+#endif
+ VERIFY_IS_EQUAL(static_cast<unsigned>(0), Foo::object_count);
}