summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/debug/pr46240.cc
blob: c12a6988af8f66bf41ce763786618f1d70ff6492 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// { dg-do compile }
// { dg-options "-O3 -g" }

template <typename T>
T &max (T &a, T &b)
{
  if (a < b) return b; else return a;
}
int foo (double);
struct S
{
  struct T
  {
    int dims, count;
    T (int, int) : dims (), count () {}
  };
  T *rep;
  S () {}
  S (int r, int c) : rep (new T (r, c)) {}
  ~S () { delete rep; }
};
template <typename T>
struct U
{
  static T epsilon () throw ();
};
template <class T>
struct V
{
  struct W
  {
    T * data;
    int count;
    W (int n) : data (new T[n]), count () {}
  };
  V::W *rep;
  S dimensions;
  int slice_len;
  V (S s) : rep (new V <T>::W (get_size (s))) {}
  int capacity () { return slice_len; }
  int get_size (S);
};
template <class T>
struct Z : public V <T>
{
  Z () : V <T> (S (0, 0)) {}
  Z (int r, int c) : V <T> (S (r, c)) {}
};
template <class T>
struct A : public Z <T>
{
  A () : Z <T> () {}
  A (int n, int m) : Z <T> (n, m) {}
};
template <class T>
struct B : public V <T>
{
};
struct C : public A <double>
{
  C () : A <double> () {}
  C (int r, int c) : A <double> (r, c) {}
};
struct D : public B <double>
{
};
template <class T>
struct E
{
};
template <class T>
struct G : public E <T>
{
};
struct H : public G <double>
{
};
template <class R>
struct I
{
  R scl, sum;
  void accum (R val)
  {
    R t = __builtin_fabs (val);
    if (scl == t)
      sum += 1;
  }
  operator R () { __builtin_sqrt (sum); return R (); }
};
template <class R>
struct J
{
  template < class U > void accum (U val) {}
  operator R () { return R (); }
};
template <class R>
struct K
{
  R max;
  template <class U> void accum (U val)
  {
    double z = __builtin_fabs (val);
    max = ::max (max, z);
  }
  operator R () { return max; }
};
template <class R>
struct L
{
  unsigned num;
  template <class U> void accum (U) {}
  operator R () { return num; }
};
template <class T, class R, class S>
void bar (V <T> &v, R &res, S acc)
{
  for (int i = 0; i < v.capacity (); i++)
    acc.accum ((i));
  res = acc;
}
template <class T, class R>
void bar (B <T> &v, R)
{
  R res;
  bar (v, res, I <R> ());
}
template <class T, class R>
R bar (A <T> &v, R p)
{
  R res;
  if (p == 2)
    bar (v, res, I <R> ());
  else if (p == 1)
    bar (v, res, J <R> ());
  else if (p == sizeof (float) ? (p) : foo (p))
    {
      if (p > 0)
	bar (v, res, K <R> ());
    }
  else if (p == 0)
    bar (v, res, L <R> ());
  return res;
}
template <class CT, class VectorT, class R>
void
baz (CT m, R p, R tol, int maxiter, VectorT)
{
  VectorT y (0, 0), z (0, 1);
  R q = 0;
  R gamma = 0, gamma1 = 0;
  gamma = bar (y, p);
  (void) (bar (z, q) <= (gamma1 <= gamma));
}
int a = 100;
template <class CT, class VectorT, class R>
void
test (CT m, R p, VectorT)
{
  VectorT x;
  R sqrteps (U <R>::epsilon ());
  baz (m, p, sqrteps, a, x);
}
void
fn (D x, double p)
{
  bar (x, p);
}
void
fn (H x, double p)
{
  test (x, p, C ());
}