aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/range-for13.C
blob: ab7bdde478e98feec659e3ceb3bc232e5233f6db (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Test for errors in range-based for loops
// with member begin/end

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

//These should not be used
template<typename T> int *begin(T &t)
{
    T::fail;
}
template<typename T> int *end(T &t)
{
    T::fail;
}

struct container1
{
    int *begin();
    //no end
};

struct container2
{
    int *end();
    //no begin
};

struct container3
{
private:
    int *begin(); // { dg-error "is private" }
    int *end(); // { dg-error "is private" }
};

struct container4
{
    int *begin;
    int *end;
};

struct container5
{
    typedef int *begin;
    typedef int *end;
};

struct callable
{
    int *operator()();
};

struct container6
{
    callable begin;
    callable end;
};

struct container7
{
    static callable begin;
    static callable end;
};

struct container8
{
    static int *begin();
    int *end();
};

struct private_callable
{
private:
    int *operator()(); // { dg-error "is private" }
};

struct container9
{
    private_callable begin;
    private_callable end;
};

struct container10
{
    typedef int *(*function)();

    function begin;
    static function end;
};

void test1()
{
  for (int x : container1()); // { dg-error "member but not" }
  for (int x : container2()); // { dg-error "member but not" }
  for (int x : container3()); // { dg-error "within this context" }
  for (int x : container4()); // { dg-error "cannot be used as a function" }
  for (int x : container5()); // { dg-error "invalid use of" }
  for (int x : container6());
  for (int x : container7());
  for (int x : container8());
  for (int x : container9()); // { dg-error "within this context" }
  for (int x : container10());
}