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()
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;
41  for(int i = 0; i < g_repeat; i++) {
42  Index rows = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE), cols = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE);
43  Foo::object_limit = internal::random<Index>(0, rows*cols - 2);
44  std::cout << "object_limit =" << Foo::object_limit << std::endl;
45 #ifdef EIGEN_EXCEPTIONS
46  try
47  {
48 #endif
49  std::cout << "\nMatrixX m(" << rows << ", " << cols << ");\n";
50  MatrixX m(rows, cols);
51 #ifdef EIGEN_EXCEPTIONS
52  VERIFY(false); // not reached if exceptions are enabled
53  }
54  catch (const Foo::Fail&) { /* ignore */ }
55 #endif
57 
58  {
59  Foo::object_limit = (rows+1)*(cols+1);
60  MatrixX A(rows, cols);
62  VectorX v=A.row(0);
63  VERIFY_IS_EQUAL(Foo::object_count, (rows+1)*cols);
64  v = A.col(0);
65  VERIFY_IS_EQUAL(Foo::object_count, rows*(cols+1));
66  }
68  }
69 }
Matrix3f m
void test_ctorleak()
Definition: ctorleak.cpp:36
ArrayXcf v
Definition: Cwise_arg.cpp:1
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
static Index object_count
Definition: ctorleak.cpp:7
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:331
static int g_repeat
Definition: main.h:144
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
~Foo()
Definition: ctorleak.cpp:21
#define VERIFY(a)
Definition: main.h:325
int dummy
Definition: ctorleak.cpp:9
The matrix class, also used for vectors and row-vectors.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:54