aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for5.C
blob: bf044068ba6bf1ad4099269cdde31a3781ca3193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Test for errors in range-based for loops

// { dg-do compile { target c++11 } }

struct container
{
};

int *begin(const container &c)
{
  return 0;
}

int end(const container &c) //Ops! wrong type
{
  return 0;
}


struct Implicit
{
  Implicit(int x)
  {}
};
struct Explicit
{
  explicit Explicit(int x)
  {}
};

void test1()
{
  container c;
  for (int x : c) // { dg-error "inconsistent|conversion" }
    ;

  int a[2] = {1,2};
  for (Implicit x : a)
    ;
  for (Explicit x : a) // { dg-error "conversion" }
    ;
  for (const Implicit &x : a)
    ;
  for (Implicit &&x : a)
    ;

  //Check the correct scopes
  int i;
  for (int i : a)		// { dg-message "previously declared" }
  {
    int i;			// { dg-error "redeclaration" }
  }
}