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