1/* { dg-do compile } */
2
3template < typename > class basic_stringstream;
4
5struct basic_string {
6  basic_string();
7};
8
9struct ios_base {
10  virtual ~ios_base();
11};
12
13class ostream:ios_base {};
14class istream:virtual ios_base {};
15
16template < typename > struct basic_iostream:public istream, ostream {
17  ~basic_iostream () {}
18};
19extern template class basic_iostream < char >;
20
21template < typename > struct basic_stringstream:public basic_iostream < char > {
22    basic_string _M_stringbuf;
23    ~basic_stringstream () {}
24};
25extern template class basic_stringstream < char >;
26
27template < typename > struct AnyMatrixBase;
28template < typename, int _Rows, int _Cols, int = _Rows, int = _Cols > class Matrix;
29template < typename > class CwiseNullaryOp;
30
31template < typename Derived > struct MatrixBase:public AnyMatrixBase < Derived > {
32  typedef CwiseNullaryOp < Derived > ConstantReturnType;
33  ConstantReturnType Constant ();
34  template < typename > Derived cast ();
35  static CwiseNullaryOp < Derived > Random (int);
36};
37
38template < typename Derived > struct AnyMatrixBase {
39  Derived derived () {}
40  Derived & derived () const {}
41};
42
43template < typename, int > struct ei_matrix_storage {};
44
45template < typename _Scalar, int, int, int _MaxRows, int _MaxCols > struct Matrix:MatrixBase < Matrix < _Scalar, _MaxRows, _MaxCols > > {
46  typedef MatrixBase < Matrix > Base;
47  ei_matrix_storage < int, _MaxCols > m_storage;
48  Matrix operator= (const Matrix other) {
49    _resize_to_match (other);
50    lazyAssign (other.derived ());
51  }
52  template < typename OtherDerived > Matrix lazyAssign (MatrixBase < OtherDerived > other) {
53    _resize_to_match (other);
54    return Base (other.derived ());
55  }
56  Matrix ();
57  template < typename OtherDerived > Matrix (const MatrixBase < OtherDerived > &other) {
58    *this = other;
59  }
60  template < typename OtherDerived > void _resize_to_match (const MatrixBase < OtherDerived > &) {
61    throw 1;
62  }
63};
64
65template < typename MatrixType > class CwiseNullaryOp:
66public MatrixBase < CwiseNullaryOp < MatrixType > > {};
67
68int f()
69{
70  bool align_cols;
71  if (align_cols) {
72    basic_stringstream<char> sstr;
73    f();
74  }
75}
76
77template < typename > struct AutoDiffScalar;
78template < typename Functor > struct AutoDiffJacobian:Functor {
79  AutoDiffJacobian (Functor);
80  typedef typename Functor::InputType InputType;
81  typedef typename Functor::ValueType ValueType;
82  typedef Matrix < int, Functor::InputsAtCompileTime, 1 > DerivativeType;
83  typedef AutoDiffScalar < DerivativeType > ActiveScalar;
84  typedef Matrix < ActiveScalar, Functor::InputsAtCompileTime, 1 > ActiveInput;
85  void operator () (InputType x, ValueType *) {
86    ActiveInput ax = x.template cast < ActiveScalar > ();
87  }
88};
89
90template < int NX, int NY > struct TestFunc1 {
91  enum  {
92    InputsAtCompileTime = NX
93  };
94  typedef Matrix < float, NX, 1 > InputType;
95  typedef Matrix < float, NY, 1 > ValueType;
96  typedef Matrix < float, NY, NX > JacobianType;
97  int inputs ();
98};
99
100template < typename Func > void forward_jacobian (Func f) {
101  typename Func::InputType x = Func::InputType::Random (f.inputs ());
102  typename Func::ValueType y;
103  typename Func::JacobianType jref = jref.Constant ();
104  AutoDiffJacobian < Func > autoj (f);
105  autoj (x, &y);
106}
107
108void test_autodiff_scalar ()
109{
110  forward_jacobian (TestFunc1 < 2, 2 > ());
111  forward_jacobian (TestFunc1 < 3, 2 > ());
112}
113