Implement range-based for-statements.
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / range-for5.C
blob9c97ad5faf08d32d6436bc178f2c2c446483edc2
1 // Test for errors in range-based for loops
3 // { dg-do compile }
4 // { dg-options "-std=c++0x" }
6 struct container
8 };
10 int *begin(const container &c)
12   return 0;
15 int end(const container &c) //Ops! wrong type
17   return 0;
21 struct Implicit
23   Implicit(int x)
24   {}
26 struct Explicit
28   explicit Explicit(int x)
29   {}
32 void test1()
34   container c;
35   for (int x : c) // { dg-error "inconsistent|conversion" }
36     ;
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     ;
48   //Check the correct scopes
49   int i;
50   for (int i : a)
51   {
52     int i;
53   }