* decl.c (make_typename_type): s/parameters/arguments/.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / range-for12.C
blob5a2a7d1907c2f120490fcb2db6b93b75b1b88333
1 // Test for range-based for loop with templates
2 // and begin/end as member functions
4 // { dg-do run { target c++11 } }
6 /* Preliminary declarations */
7 namespace pre
9   struct iterator
10   {
11     int x;
12     explicit iterator (int v) :x(v) {}
13     iterator &operator ++() { ++x; return *this; }
14     int operator *() { return x; }
15     bool operator != (const iterator &o) { return x != o.x; }
16   };
18   struct container
19   {
20     int min, max;
21     container(int a, int b) :min(a), max(b) {}
22     iterator begin() const
23     {
24         return iterator(min);
25     }
26     iterator end() const
27     {
28         return iterator(max);
29     }
31   };
33 } //namespace pre
35 using pre::container;
36 extern "C" void abort(void);
38 container run_me_just_once()
40     static bool run = false;
41     if (run)
42         abort();
43     run = true;
44     return container(1,2);
47 /* Template with dependent expression. */
48 template<typename T> int test1(const T &r)
50   int t = 0;
51   for (int i : r)
52     t += i;
53   return t;
56 /* Template with non-dependent expression and dependent declaration. */
57 template<typename T> int test2(const container &r)
59   int t = 0;
60   for (T i : r)
61     t += i;
62   return t;
65 /* Template with non-dependent expression (array) and dependent declaration. */
66 template<typename T> int test2(const int (&r)[4])
68   int t = 0;
69   for (T i : r)
70     t += i;
71   return t;
74 /* Template with non-dependent expression and auto declaration. */
75 template<typename T> int test3(const container &r)
77   int t = 0;
78   for (auto i : r)
79     t += i;
80   return t;
83 /* Template with non-dependent expression (array) and auto declaration. */
84 template<typename T> int test3(const int (&r)[4])
86   int t = 0;
87   for (auto i : r)
88     t += i;
89   return t;
92 int main ()
94   container c(1,5);
95   int a[4] = {5,6,7,8};
97   for (auto x : run_me_just_once())
98       ;
100   if (test1 (c) != 10)
101     abort();
102   if (test1 (a) != 26)
103     abort();
105   if (test2<int> (c) != 10)
106     abort();
107   if (test2<int> (a) != 26)
108     abort();
110   if (test3<int> (c) != 10)
111     abort();
112   if (test3<int> (a) != 26)
113     abort();
114   return 0;