aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/pr70098.C
blob: c7b4f63ef844c821ff38883b44a8cca386ae62ff (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
// PR target/70098
// { dg-do compile }
// { dg-options -O2 }
// { dg-require-effective-target c++11 }

template < typename > struct traits;
template < typename, int _Rows, int _Cols, int = 0, int = _Rows,
	int = _Cols > class Matrix;
template < typename > class G;
template < typename Derived > struct A {
	typedef G < Derived > type;
};

template < typename Derived > class C {
public:
	enum { RowsAtCompileTime =
		    traits < Derived >::RowsAtCompileTime } static Zero;
};

template < typename Derived > class G:public C < Derived > {
};

template < int _Rows > class D {
public:
	long rows() {
		return _Rows;
	}
};

template < typename Derived > class PlainObjectBase:public A < Derived >::type {
	typedef typename A < Derived >::type Base;
	D < Base::RowsAtCompileTime > m_storage;

public:
	long rows() {
		return m_storage.rows();
	}
};

int fn1();

struct B {
	static long run(long x, long) {
		int offset(fn1());
		 return x + offset;
}};

long fn2(int x)
{
	return B::run(x, 0);
}

template < typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows,
    int _MaxCols >
    struct traits <Matrix < _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >> {
	enum { RowsAtCompileTime = _Rows };
};

template < typename, int, int, int, int _MaxRows, int _MaxCols >
	class Matrix:public PlainObjectBase < Matrix < double, _MaxRows,
	_MaxCols >> {
public:
	template < typename OtherDerived > Matrix(OtherDerived);
};

struct F {
	static Matrix < double, 2, 2 > run(long size) {
		Matrix < double, 2, 2 > diag = Matrix < double, 2, 2 >::Zero;
		long i = 0;
		while (i < size) {
			long randomInt = fn2(-1);
			if (randomInt == 0)
				++i;
			else {
				double alpha(randomInt);
				 diag = alpha;
				 i = 2;
			}
		}

		return diag;
	}
};

void fn3(Matrix < double, 2, 2 > m)
{
	long size = m.rows();
	F::run(size);
}