1 // Test for errors in range-based for loops
2 // with member begin/end
3 
4 // { dg-do compile }
5 // { dg-options "-std=c++0x" }
6 
7 //These should not be used
begin(T & t)8 template<typename T> int *begin(T &t)
9 {
10     T::fail;
11 }
end(T & t)12 template<typename T> int *end(T &t)
13 {
14     T::fail;
15 }
16 
17 struct container1
18 {
19     int *begin();
20     //no end
21 };
22 
23 struct container2
24 {
25     int *end();
26     //no begin
27 };
28 
29 struct container3
30 {
31 private:
32     int *begin(); // { dg-error "is private" }
33     int *end(); // { dg-error "is private" }
34 };
35 
36 struct container4
37 {
38     int *begin;
39     int *end;
40 };
41 
42 struct container5
43 {
44     typedef int *begin;
45     typedef int *end;
46 };
47 
48 struct callable
49 {
50     int *operator()();
51 };
52 
53 struct container6
54 {
55     callable begin;
56     callable end;
57 };
58 
59 struct container7
60 {
61     static callable begin;
62     static callable end;
63 };
64 
65 struct container8
66 {
67     static int *begin();
68     int *end();
69 };
70 
71 struct private_callable
72 {
73 private:
74     int *operator()(); // { dg-error "is private" }
75 };
76 
77 struct container9
78 {
79     private_callable begin;
80     private_callable end;
81 };
82 
83 struct container10
84 {
85     typedef int *(*function)();
86 
87     function begin;
88     static function end;
89 };
90 
test1()91 void test1()
92 {
93   for (int x : container1()); // { dg-error "member but not" }
94   for (int x : container2()); // { dg-error "member but not" }
95   for (int x : container3()); // { dg-error "within this context" }
96   for (int x : container4()); // { dg-error "cannot be used as a function" }
97   for (int x : container5()); // { dg-error "invalid use of" }
98   for (int x : container6());
99   for (int x : container7());
100   for (int x : container8());
101   for (int x : container9()); // { dg-error "within this context" }
102   for (int x : container10());
103 }
104