aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/ctorleak.cpp
blob: 72ab94b66cdd7ca033ea2e13f43424bbb9720d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "main.h"

#include <exception>  // std::exception

struct Foo
{
  int dummy;
  Foo() { if (!internal::random(0, 10)) throw Foo::Fail(); }
  class Fail : public std::exception {};
};

namespace Eigen
{
  template<>
  struct NumTraits<Foo>
  {
    typedef double Real;
    typedef double NonInteger;
    typedef double Nested;
    enum
      {
        IsComplex             =  0,
        IsInteger             =  1,
        ReadCost              = -1,
        AddCost               = -1,
        MulCost               = -1,
        IsSigned              =  1,
        RequireInitialization =  1
      };
    static inline Real epsilon() { return 1.0; }
    static inline Real dummy_epsilon() { return 0.0; }
  };
}

void test_ctorleak()
{
  try
    {
      Matrix<Foo, Dynamic, Dynamic> m(14, 92);
      eigen_assert(false);  // not reached
    }
  catch (const Foo::Fail&) { /* ignore */ }
}