OSDN Git Service

PR c++/51107
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / range-for15.C
1 // Test for range-based for loop with templates
2 // and begin/end as member (non-)virtual functions
3
4 // { dg-do run }
5 // { dg-options "-std=c++0x" }
6
7 unsigned int g;
8
9 struct A
10 {
11     virtual int *begin()
12     {
13         g |= 1;
14         return 0;
15     }
16     int *end()
17     {
18         g |= 2;
19         return 0;
20     }
21 };
22
23 struct B : A
24 {
25     virtual int *begin()
26     {
27         g |= 4;
28         return 0;
29     }
30     int *end()
31     {
32         g |= 8;
33         return 0;
34     }
35 };
36
37 extern "C" void abort(void);
38
39 int main ()
40 {
41     A a;
42     B b;
43     A &aa = b;
44
45     g = 0;
46     for (int x : a);
47     if (g != (1 | 2))
48         abort();
49
50     g = 0;
51     for (int x : b);
52     if (g != (4 | 8))
53         abort();
54
55     g = 0;
56     for (int x : aa);
57     if (g != (4 | 2))
58         abort();
59 }