Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/range-for13.C

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