Fix xfail for 32-bit hppa*-*-* in gcc.dg/pr84877.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / imperfect-template-1.C
blob4ed96c8319bb209a50a22981f8c13351ca71a5cb
1 // { dg-do run }
2 // Test that template class iterators and imperfectly-nested loops
3 // work together.
4 // This variant tests initialization by assignment.
6 typedef __PTRDIFF_TYPE__ ptrdiff_t;
7 extern "C" void abort ();
9 template <typename T>
10 class I
12 public:
13   typedef ptrdiff_t difference_type;
14   I ();
15   ~I ();
16   I (T *);
17   I (const I &);
18   T &operator * ();
19   T *operator -> ();
20   T &operator [] (const difference_type &) const;
21   I &operator = (const I &);
22   I &operator ++ ();
23   I operator ++ (int);
24   I &operator -- ();
25   I operator -- (int);
26   I &operator += (const difference_type &);
27   I &operator -= (const difference_type &);
28   I operator + (const difference_type &) const;
29   I operator - (const difference_type &) const;
30   template <typename S> friend bool operator == (I<S> &, I<S> &);
31   template <typename S> friend bool operator == (const I<S> &, const I<S> &);
32   template <typename S> friend bool operator < (I<S> &, I<S> &);
33   template <typename S> friend bool operator < (const I<S> &, const I<S> &);
34   template <typename S> friend bool operator <= (I<S> &, I<S> &);
35   template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
36   template <typename S> friend bool operator > (I<S> &, I<S> &);
37   template <typename S> friend bool operator > (const I<S> &, const I<S> &);
38   template <typename S> friend bool operator >= (I<S> &, I<S> &);
39   template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
40   template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
41   template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
42   template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
43 private:
44   T *p;
46 template <typename T> I<T>::I () : p (0) {}
47 template <typename T> I<T>::~I () { p = (T *) 0; }
48 template <typename T> I<T>::I (T *x) : p (x) {}
49 template <typename T> I<T>::I (const I &x) : p (x.p) {}
50 template <typename T> T &I<T>::operator * () { return *p; }
51 template <typename T> T *I<T>::operator -> () { return p; }
52 template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; }
53 template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; }
54 template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; }
55 template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); }
56 template <typename T> I<T> &I<T>::operator -- () { --p; return *this; }
57 template <typename T> I<T> I<T>::operator -- (int) { return I (p--); }
58 template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; }
59 template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; }
60 template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); }
61 template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); }
62 template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; }
63 template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; }
64 template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); }
65 template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); }
66 template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; }
67 template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; }
68 template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; }
69 template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; }
70 template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; }
71 template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; }
72 template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; }
73 template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; }
74 template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; }
75 template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; }
76 template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); }
78 template <typename T>
79 class J
81 public:
82   J(const I<T> &x, const I<T> &y) : b (x), e (y) {}
83   const I<T> &begin ();
84   const I<T> &end ();
85 private:
86   I<T> b, e;
89 template <typename T> const I<T> &J<T>::begin () { return b; }
90 template <typename T> const I<T> &J<T>::end () { return e; }
92 static int f1count[3], f2count[3];
94 #ifndef __cplusplus
95 extern void abort (void);
96 #else
97 extern "C" void abort (void);
98 #endif
100 void f1 (int depth)
102   f1count[depth]++;
105 void f2 (int depth)
107   f2count[depth]++;
110 template <typename T>
111 void s1 (J<T> a1, J<T> a2, J<T> a3)
113   I<T> i, j, k;
115 #pragma omp for collapse(3)
116   for (i = a1.begin (); i < a1.end (); i++)
117     {
118       f1 (0);
119       for (j = a2.begin (); j < a2.end (); j++)
120         {
121           f1 (1);
122           for (k = a3.begin (); k < a3.end (); k++)
123             {
124               f1 (2);
125               f2 (2);
126             }
127           f2 (1);
128         }
129       f2 (0);
130     }
135 main (void)
138   int index[] = {0, 1, 2, 3, 4, 5};
140   J<int> x (&index[0], &index[3]);
141   J<int> y (&index[0], &index[4]);
142   J<int> z (&index[0], &index[5]);
144   f1count[0] = 0;
145   f1count[1] = 0;
146   f1count[2] = 0;
147   f2count[0] = 0;
148   f2count[1] = 0;
149   f2count[2] = 0;
151   s1<int> (x, y, z);
153   /* All intervening code at the same depth must be executed the same
154      number of times. */
155   if (f1count[0] != f2count[0]) abort ();
156   if (f1count[1] != f2count[1]) abort ();
157   if (f1count[2] != f2count[2]) abort ();
159   /* Intervening code must be executed at least as many times as the loop
160      that encloses it. */
161   if (f1count[0] < 3) abort ();
162   if (f1count[1] < 3 * 4) abort ();
164   /* Intervening code must not be executed more times than the number
165      of logical iterations. */
166   if (f1count[0] > 3 * 4 * 5) abort ();
167   if (f1count[1] > 3 * 4 * 5) abort ();
169   /* Check that the innermost loop body is executed exactly the number
170      of logical iterations expected. */
171   if (f1count[2] != 3 * 4 * 5) abort ();