Debian Codegraph @

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

raw
1 // Test for errors in range-based for loops
2
3 // { dg-do compile { target c++11 } }
4
5 struct container
6 {
7 };
8
9 int *begin(const container &c)
10 {
11 return 0;
12 }
13
14 int end(const container &c) //Ops! wrong type
15 {
16 return 0;
17 }
18
19
20 struct Implicit
21 {
22 Implicit(int x)
23 {}
24 };
25 struct Explicit
26 {
27 explicit Explicit(int x)
28 {}
29 };
30
31 void test1()
32 {
33 container c;
34 for (int x : c) // { dg-error "inconsistent|conversion|comparison" }
35 ;
36
37 int a[2] = {1,2};
38 for (Implicit x : a)
39 ;
40 for (Explicit x : a) // { dg-error "conversion" }
41 ;
42 for (const Implicit &x : a)
43 ;
44 for (Implicit &&x : a)
45 ;
46
47 //Check the correct scopes
48 int i;
49 for (int i : a) // { dg-message "previously declared" }
50 {
51 int i; // { dg-error "redeclaration" }
52 }
53 }