[C++ PATCH] Deprecate -ffriend-injection
[official-gcc.git] / gcc / testsuite / g++.dg / debug / pr46240.cc
blobc12a6988af8f66bf41ce763786618f1d70ff6492
1 // { dg-do compile }
2 // { dg-options "-O3 -g" }
4 template <typename T>
5 T &max (T &a, T &b)
7 if (a < b) return b; else return a;
9 int foo (double);
10 struct S
12 struct T
14 int dims, count;
15 T (int, int) : dims (), count () {}
17 T *rep;
18 S () {}
19 S (int r, int c) : rep (new T (r, c)) {}
20 ~S () { delete rep; }
22 template <typename T>
23 struct U
25 static T epsilon () throw ();
27 template <class T>
28 struct V
30 struct W
32 T * data;
33 int count;
34 W (int n) : data (new T[n]), count () {}
36 V::W *rep;
37 S dimensions;
38 int slice_len;
39 V (S s) : rep (new V <T>::W (get_size (s))) {}
40 int capacity () { return slice_len; }
41 int get_size (S);
43 template <class T>
44 struct Z : public V <T>
46 Z () : V <T> (S (0, 0)) {}
47 Z (int r, int c) : V <T> (S (r, c)) {}
49 template <class T>
50 struct A : public Z <T>
52 A () : Z <T> () {}
53 A (int n, int m) : Z <T> (n, m) {}
55 template <class T>
56 struct B : public V <T>
59 struct C : public A <double>
61 C () : A <double> () {}
62 C (int r, int c) : A <double> (r, c) {}
64 struct D : public B <double>
67 template <class T>
68 struct E
71 template <class T>
72 struct G : public E <T>
75 struct H : public G <double>
78 template <class R>
79 struct I
81 R scl, sum;
82 void accum (R val)
84 R t = __builtin_fabs (val);
85 if (scl == t)
86 sum += 1;
88 operator R () { __builtin_sqrt (sum); return R (); }
90 template <class R>
91 struct J
93 template < class U > void accum (U val) {}
94 operator R () { return R (); }
96 template <class R>
97 struct K
99 R max;
100 template <class U> void accum (U val)
102 double z = __builtin_fabs (val);
103 max = ::max (max, z);
105 operator R () { return max; }
107 template <class R>
108 struct L
110 unsigned num;
111 template <class U> void accum (U) {}
112 operator R () { return num; }
114 template <class T, class R, class S>
115 void bar (V <T> &v, R &res, S acc)
117 for (int i = 0; i < v.capacity (); i++)
118 acc.accum ((i));
119 res = acc;
121 template <class T, class R>
122 void bar (B <T> &v, R)
124 R res;
125 bar (v, res, I <R> ());
127 template <class T, class R>
128 R bar (A <T> &v, R p)
130 R res;
131 if (p == 2)
132 bar (v, res, I <R> ());
133 else if (p == 1)
134 bar (v, res, J <R> ());
135 else if (p == sizeof (float) ? (p) : foo (p))
137 if (p > 0)
138 bar (v, res, K <R> ());
140 else if (p == 0)
141 bar (v, res, L <R> ());
142 return res;
144 template <class CT, class VectorT, class R>
145 void
146 baz (CT m, R p, R tol, int maxiter, VectorT)
148 VectorT y (0, 0), z (0, 1);
149 R q = 0;
150 R gamma = 0, gamma1 = 0;
151 gamma = bar (y, p);
152 (void) (bar (z, q) <= (gamma1 <= gamma));
154 int a = 100;
155 template <class CT, class VectorT, class R>
156 void
157 test (CT m, R p, VectorT)
159 VectorT x;
160 R sqrteps (U <R>::epsilon ());
161 baz (m, p, sqrteps, a, x);
163 void
164 fn (D x, double p)
166 bar (x, p);
168 void
169 fn (H x, double p)
171 test (x, p, C ());