ctorleak.cpp
Go to the documentation of this file.
1 #include "main.h"
2 
3 #include <exception> // std::exception
4 
5 struct Foo
6 {
9  int dummy;
10 
11  Foo() : dummy(0)
12  {
13 #ifdef EIGEN_EXCEPTIONS
14  // TODO: Is this the correct way to handle this?
15  if (Foo::object_count > Foo::object_limit) { std::cout << "\nThrow!\n"; throw Foo::Fail(); }
16 #endif
17  std::cout << '+';
19  }
20 
21  ~Foo()
22  {
23  std::cout << '-';
25  }
26 
27  class Fail : public std::exception {};
28 };
29 
32 
33 #undef EIGEN_TEST_MAX_SIZE
34 #define EIGEN_TEST_MAX_SIZE 3
35 
37 {
38  typedef Matrix<Foo, Dynamic, Dynamic> MatrixX;
40 
42  for(int i = 0; i < g_repeat; i++) {
43  Index rows = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE), cols = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE);
44  Foo::object_limit = rows*cols;
45  {
46  MatrixX r(rows, cols);
47  Foo::object_limit = r.size()+internal::random<Index>(0, rows*cols - 2);
48  std::cout << "object_limit =" << Foo::object_limit << std::endl;
49 #ifdef EIGEN_EXCEPTIONS
50  try
51  {
52 #endif
53  if(internal::random<bool>()) {
54  std::cout << "\nMatrixX m(" << rows << ", " << cols << ");\n";
55  MatrixX m(rows, cols);
56  }
57  else {
58  std::cout << "\nMatrixX m(r);\n";
59  MatrixX m(r);
60  }
61 #ifdef EIGEN_EXCEPTIONS
62  VERIFY(false); // not reached if exceptions are enabled
63  }
64  catch (const Foo::Fail&) { /* ignore */ }
65 #endif
66  }
68 
69  {
70  Foo::object_limit = (rows+1)*(cols+1);
71  MatrixX A(rows, cols);
73  VectorX v=A.row(0);
74  VERIFY_IS_EQUAL(Foo::object_count, (rows+1)*cols);
75  v = A.col(0);
76  VERIFY_IS_EQUAL(Foo::object_count, rows*(cols+1));
77  }
79  }
80  std::cout << "\n";
81 }
Matrix3f m
EIGEN_DECLARE_TEST(ctorleak)
Definition: ctorleak.cpp:36
Matrix< Scalar, Dynamic, 1 > VectorX
Definition: sparse_lu.cpp:41
Foo()
Definition: ctorleak.cpp:11
static Index object_limit
Definition: ctorleak.cpp:8
#define EIGEN_TEST_MAX_SIZE
Definition: ctorleak.cpp:34
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
static Index object_count
Definition: ctorleak.cpp:7
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
static int g_repeat
Definition: main.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Array< int, Dynamic, 1 > v
~Foo()
Definition: ctorleak.cpp:21
#define VERIFY(a)
Definition: main.h:380
int dummy
Definition: ctorleak.cpp:9
The matrix class, also used for vectors and row-vectors.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:06