summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/torture/pr42450.C
blob: f630fa2b7e28a04806fe7c9ca2cebab284f34bf5 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* { dg-do compile } */

template < typename > class basic_stringstream;

struct basic_string {
  basic_string();
};

struct ios_base {
  virtual ~ios_base();
};

class ostream:ios_base {};
class istream:virtual ios_base {};

template < typename > struct basic_iostream:public istream, ostream {
  ~basic_iostream () {}
};
extern template class basic_iostream < char >;

template < typename > struct basic_stringstream:public basic_iostream < char > {
    basic_string _M_stringbuf;
    ~basic_stringstream () {}
};
extern template class basic_stringstream < char >;

template < typename > struct AnyMatrixBase;
template < typename, int _Rows, int _Cols, int = _Rows, int = _Cols > class Matrix;
template < typename > class CwiseNullaryOp;

template < typename Derived > struct MatrixBase:public AnyMatrixBase < Derived > {
  typedef CwiseNullaryOp < Derived > ConstantReturnType;
  ConstantReturnType Constant ();
  template < typename > Derived cast ();
  static CwiseNullaryOp < Derived > Random (int);
};

template < typename Derived > struct AnyMatrixBase {
  Derived derived () {}
  Derived & derived () const {}
};

template < typename, int > struct ei_matrix_storage {};

template < typename _Scalar, int, int, int _MaxRows, int _MaxCols > struct Matrix:MatrixBase < Matrix < _Scalar, _MaxRows, _MaxCols > > {
  typedef MatrixBase < Matrix > Base;
  ei_matrix_storage < int, _MaxCols > m_storage;
  Matrix operator= (const Matrix other) {
    _resize_to_match (other);
    lazyAssign (other.derived ());
  }
  template < typename OtherDerived > Matrix lazyAssign (MatrixBase < OtherDerived > other) {
    _resize_to_match (other);
    return Base (other.derived ());
  }
  Matrix ();
  template < typename OtherDerived > Matrix (const MatrixBase < OtherDerived > &other) {
    *this = other;
  }
  template < typename OtherDerived > void _resize_to_match (const MatrixBase < OtherDerived > &) {
    throw 1;
  }
};

template < typename MatrixType > class CwiseNullaryOp:
public MatrixBase < CwiseNullaryOp < MatrixType > > {};

int f()
{
  bool align_cols;
  if (align_cols) {
    basic_stringstream<char> sstr;
    f();
  }
}

template < typename > struct AutoDiffScalar;
template < typename Functor > struct AutoDiffJacobian:Functor {
  AutoDiffJacobian (Functor);
  typedef typename Functor::InputType InputType;
  typedef typename Functor::ValueType ValueType;
  typedef Matrix < int, Functor::InputsAtCompileTime, 1 > DerivativeType;
  typedef AutoDiffScalar < DerivativeType > ActiveScalar;
  typedef Matrix < ActiveScalar, Functor::InputsAtCompileTime, 1 > ActiveInput;
  void operator () (InputType x, ValueType *) {
    ActiveInput ax = x.template cast < ActiveScalar > ();
  }
};

template < int NX, int NY > struct TestFunc1 {
  enum  {
    InputsAtCompileTime = NX
  };
  typedef Matrix < float, NX, 1 > InputType;
  typedef Matrix < float, NY, 1 > ValueType;
  typedef Matrix < float, NY, NX > JacobianType;
  int inputs ();
};

template < typename Func > void forward_jacobian (Func f) {
  typename Func::InputType x = Func::InputType::Random (f.inputs ());
  typename Func::ValueType y;
  typename Func::JacobianType jref = jref.Constant ();
  AutoDiffJacobian < Func > autoj (f);
  autoj (x, &y);
}

void test_autodiff_scalar ()
{
  forward_jacobian (TestFunc1 < 2, 2 > ());
  forward_jacobian (TestFunc1 < 3, 2 > ());
}