1 // Test for range-based for loop with templates
4 // { dg-options "-std=c++0x" }
8 /* Preliminary declarations */
14 iterator (int v) :x(v) {}
15 iterator &operator ++() { ++x; return *this; }
16 int operator *() { return x; }
17 bool operator != (const iterator &o) { return x != o.x; }
23 container(int a, int b) :min(a), max(b) {}
26 iterator begin(const container &c)
28 return iterator(c.min);
31 iterator end(const container &c)
33 return iterator(c.max);
39 extern "C" void abort(void);
41 container run_me_just_once()
43 static bool run = false;
47 return container(1,2);
50 /* Template with dependent expression. */
51 /* Template with dependent expression. */
52 template<typename T> int test1(const T &r)
60 /* Template with non-dependent expression and dependent declaration. */
61 template<typename T> int test2(const container &r)
69 /* Template with non-dependent expression (array) and dependent declaration. */
70 template<typename T> int test2(const int (&r)[4])
78 /* Template with non-dependent expression and auto declaration. */
79 template<typename T> int test3(const container &r)
87 /* Template with non-dependent expression (array) and auto declaration. */
88 template<typename T> int test3(const int (&r)[4])
101 for (auto x : run_me_just_once())
109 if (test2<int> (c) != 10)
111 if (test2<int> (a) != 26)
114 if (test3<int> (c) != 10)
116 if (test3<int> (a) != 26)