1 // Test for other range-based for loops with
2 // begin/end member functions
3 
4 // { dg-do compile { target c++11 } }
5 
6 //These should not be used
begin(T & t)7 template<typename T> int *begin(T &t)
8 {
9     T::fail;
10     return 0;
11 }
end(T & t)12 template<typename T> int *end(T &t)
13 {
14     T::fail;
15     return 0;
16 }
17 
18 //Test for defaults
19 
20 struct default1
21 {
22     int *begin(int x); // { dg-message "note" }
23     int *end();
24 };
25 
26 struct default2
27 {
28     int *begin(int x=0);
29     int *end();
30 };
31 
32 struct default3
33 {
34     template <typename T> T *begin(); // { dg-message "note" }
35     int *end();
36 };
37 
38 struct default4
39 {
40     template <typename T=int> T *begin();
41     int *end();
42 };
43 
44 struct default5
45 {
46     template <typename T=int> T *begin(int x=0);
47     int *end();
48 };
49 
test1()50 void test1()
51 {
52   for (int x : default1()); // { dg-error "no matching function|note" }
53   for (int x : default2());
54   for (int x : default3()); // { dg-error "no matching function|note" }
55   for (int x : default4());
56   for (int x : default5());
57 }
58 
59 //Inheritance tests
60 
61 struct base_begin
62 {
63     int *begin(); // { dg-message "" }
64 };
65 
66 struct base_end
67 {
68     int *end();
69 };
70 
71 struct derived1 : base_begin, base_end
72 {
73 };
74 
75 struct base_begin2 : base_begin
76 {
77 };
78 
79 struct derived2 : base_begin, base_end, base_begin2 // { dg-warning "" }
80 {
81 };
82 
83 struct base_begin3 : virtual base_begin
84 {
85 };
86 
87 struct derived3 : virtual base_begin, base_end, base_begin3
88 {
89 };
90 
test2()91 void test2()
92 {
93   for (int x : derived1());
94   for (int x : derived2()); // { dg-error "is ambiguous" }
95   for (int x : derived3());
96 }
97