| 1 |
// PR target/70098 |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-options -O2 } |
| 4 |
// { dg-require-effective-target c++11 } |
| 5 |
|
| 6 |
template < typename > struct traits; |
| 7 |
template < typename, int _Rows, int _Cols, int = 0, int = _Rows, |
| 8 |
int = _Cols > class Matrix; |
| 9 |
template < typename > class G; |
| 10 |
template < typename Derived > struct A { |
| 11 |
typedef G < Derived > type; |
| 12 |
}; |
| 13 |
|
| 14 |
template < typename Derived > class C { |
| 15 |
public: |
| 16 |
enum { RowsAtCompileTime = |
| 17 |
traits < Derived >::RowsAtCompileTime } static Zero; |
| 18 |
}; |
| 19 |
|
| 20 |
template < typename Derived > class G:public C < Derived > { |
| 21 |
}; |
| 22 |
|
| 23 |
template < int _Rows > class D { |
| 24 |
public: |
| 25 |
long rows() { |
| 26 |
return _Rows; |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
template < typename Derived > class PlainObjectBase:public A < Derived >::type { |
| 31 |
typedef typename A < Derived >::type Base; |
| 32 |
D < Base::RowsAtCompileTime > m_storage; |
| 33 |
|
| 34 |
public: |
| 35 |
long rows() { |
| 36 |
return m_storage.rows(); |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
int fn1(); |
| 41 |
|
| 42 |
struct B { |
| 43 |
static long run(long x, long) { |
| 44 |
int offset(fn1()); |
| 45 |
return x + offset; |
| 46 |
}}; |
| 47 |
|
| 48 |
long fn2(int x) |
| 49 |
{ |
| 50 |
return B::run(x, 0); |
| 51 |
} |
| 52 |
|
| 53 |
template < typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, |
| 54 |
int _MaxCols > |
| 55 |
struct traits <Matrix < _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >> { |
| 56 |
enum { RowsAtCompileTime = _Rows }; |
| 57 |
}; |
| 58 |
|
| 59 |
template < typename, int, int, int, int _MaxRows, int _MaxCols > |
| 60 |
class Matrix:public PlainObjectBase < Matrix < double, _MaxRows, |
| 61 |
_MaxCols >> { |
| 62 |
public: |
| 63 |
template < typename OtherDerived > Matrix(OtherDerived); |
| 64 |
}; |
| 65 |
|
| 66 |
struct F { |
| 67 |
static Matrix < double, 2, 2 > run(long size) { |
| 68 |
Matrix < double, 2, 2 > diag = Matrix < double, 2, 2 >::Zero; |
| 69 |
long i = 0; |
| 70 |
while (i < size) { |
| 71 |
long randomInt = fn2(-1); |
| 72 |
if (randomInt == 0) |
| 73 |
++i; |
| 74 |
else { |
| 75 |
double alpha(randomInt); |
| 76 |
diag = alpha; |
| 77 |
i = 2; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return diag; |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
void fn3(Matrix < double, 2, 2 > m) |
| 86 |
{ |
| 87 |
long size = m.rows(); |
| 88 |
F::run(size); |
| 89 |
} |