1 // Test for range-based for loop with templates
3 // { dg-do run { target c++11 } }
5 /* Preliminary declarations */
11 iterator (int v) :x(v) {}
12 iterator &operator ++() { ++x; return *this; }
13 int operator *() { return x; }
14 bool operator != (const iterator &o) { return x != o.x; }
20 container(int a, int b) :min(a), max(b) {}
23 iterator begin(const container &c)
25 return iterator(c.min);
28 iterator end(const container &c)
30 return iterator(c.max);
36 extern "C" void abort(void);
38 container run_me_just_once()
40 static bool run = false;
44 return container(1,2);
47 /* Template with dependent expression. */
48 template<typename T> int test1(const T &r)
56 /* Template with non-dependent expression and dependent declaration. */
57 template<typename T> int test2(const container &r)
65 /* Template with non-dependent expression (array) and dependent declaration. */
66 template<typename T> int test2(const int (&r)[4])
74 /* Template with non-dependent expression and auto declaration. */
75 template<typename T> int test3(const container &r)
83 /* Template with non-dependent expression (array) and auto declaration. */
84 template<typename T> int test3(const int (&r)[4])
97 for (auto x : run_me_just_once())
105 if (test2<int> (c) != 10)
107 if (test2<int> (a) != 26)
110 if (test3<int> (c) != 10)
112 if (test3<int> (a) != 26)