1// { dg-do run }
2// { dg-options "-fstrict-enums" }
3
4extern "C" void abort (void);
5class CCUTILS_KeyedScalarLevelPosition
6{
7public:
8
9    typedef enum
10    {
11        UNINITED = 0,
12        AT_BEGIN = 1,
13        AT_END = 2,
14        AT_KEY = 3
15
16    } position_t;
17
18    bool is_init() const
19    { return(m_timestamp != UNINITED); }
20
21    bool is_at_begin() const
22    { return(m_timestamp == AT_BEGIN); }
23
24    position_t get_state() const
25    {
26        return((m_timestamp >= AT_KEY)
27             ? AT_KEY
28             : ((position_t)m_timestamp));
29    }
30
31    void set_at_begin()
32    { m_timestamp = AT_BEGIN; }
33
34    unsigned int get_index() const
35    { return(m_index); }
36
37    void set_pos(unsigned int a_index, unsigned int a_timestmap)
38    {
39        m_index = a_index;
40        m_timestamp = a_timestmap;
41    }
42
43    bool check_pos(unsigned int a_num_entries, unsigned int a_timestamp) const
44    {
45        if (get_state() != AT_KEY)
46            return(false);
47
48        if (m_timestamp != a_timestamp)
49            return(false);
50
51        return(m_index < a_num_entries);
52    }
53
54    void set_not_init()
55    { m_timestamp = 0; }
56
57private:
58
59    unsigned int m_timestamp;
60    unsigned int m_index;
61
62};
63
64class CCUTILS_KeyedScalarPosition
65{
66public:
67
68    CCUTILS_KeyedScalarLevelPosition m_L1;
69    CCUTILS_KeyedScalarLevelPosition m_L2;
70};
71
72class baz
73{
74public:
75    int *n[20];
76    unsigned int m_cur_array_len;
77    unsigned int m_timestamp;
78
79    unsigned int _get_timestamp() const
80    { return(m_timestamp); }
81
82    bool _check_L1_pos(const CCUTILS_KeyedScalarPosition &a_position) const
83    {
84        return(a_position.m_L1.check_pos(
85                   m_cur_array_len, _get_timestamp()));
86    }
87
88    void *next (CCUTILS_KeyedScalarPosition &);
89};
90
91void * baz::next (CCUTILS_KeyedScalarPosition &a_position)
92{
93    if (a_position.m_L1.is_at_begin() || (!a_position.m_L1.is_init()))
94    {
95        a_position.m_L1.set_pos(0, _get_timestamp());
96        a_position.m_L2.set_at_begin();
97    }
98    else if (!_check_L1_pos(a_position))
99        return(0);
100
101    return n[a_position.m_L1.get_index ()];
102}
103
104int main (int, char **)
105{
106    baz obj;
107    CCUTILS_KeyedScalarPosition a_pos;
108    void *ret;
109    int n[5];
110
111    obj.n[0] = n;
112    obj.m_cur_array_len = 1;
113    obj.m_timestamp = 42;
114
115    a_pos.m_L1.set_pos (0, 42);
116
117    ret = obj.next (a_pos);
118    if (ret == 0)
119      abort ();
120    return 0;
121}
122