From 590aec8fab5ea17755ecc532fe302b7b9b8dbf49 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 23 Nov 2018 15:37:09 +0100 Subject: [PATCH] check two ctors (cherry picked from commit 572d62697dd33acbf97e4a14e8aea06e82d6095d) --- test/ctorleak.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/ctorleak.cpp b/test/ctorleak.cpp index c158f5e4e..d73fecfe2 100644 --- a/test/ctorleak.cpp +++ b/test/ctorleak.cpp @@ -8,7 +8,7 @@ struct Foo static Index object_limit; int dummy; - Foo() + Foo() : dummy(0) { #ifdef EIGEN_EXCEPTIONS // TODO: Is this the correct way to handle this? @@ -37,22 +37,33 @@ void test_ctorleak() { typedef Matrix MatrixX; typedef Matrix VectorX; + Foo::object_count = 0; for(int i = 0; i < g_repeat; i++) { Index rows = internal::random(2,EIGEN_TEST_MAX_SIZE), cols = internal::random(2,EIGEN_TEST_MAX_SIZE); - Foo::object_limit = internal::random(0, rows*cols - 2); + Foo::object_limit = rows*cols; + { + MatrixX r(rows, cols); + Foo::object_limit = r.size()+internal::random(0, rows*cols - 2); std::cout << "object_limit =" << Foo::object_limit << std::endl; #ifdef EIGEN_EXCEPTIONS try { #endif - std::cout << "\nMatrixX m(" << rows << ", " << cols << ");\n"; - MatrixX m(rows, cols); + if(internal::random()) { + std::cout << "\nMatrixX m(" << rows << ", " << cols << ");\n"; + MatrixX m(rows, cols); + } + else { + std::cout << "\nMatrixX m(r);\n"; + MatrixX m(r); + } #ifdef EIGEN_EXCEPTIONS VERIFY(false); // not reached if exceptions are enabled } catch (const Foo::Fail&) { /* ignore */ } #endif + } VERIFY_IS_EQUAL(Index(0), Foo::object_count); { @@ -66,4 +77,5 @@ void test_ctorleak() } VERIFY_IS_EQUAL(Index(0), Foo::object_count); } + std::cout << "\n"; }