Rebase.
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr50189.C
blob06f1d3695c1d476235fc10d01001515f05628fd0
1 // { dg-do run }
2 // { dg-options "-fstrict-enums" }
4 extern "C" void abort (void);
5 class CCUTILS_KeyedScalarLevelPosition
7 public:
9     typedef enum
10     {
11         UNINITED = 0,
12         AT_BEGIN = 1,
13         AT_END = 2,
14         AT_KEY = 3
16     } position_t;
18     bool is_init() const
19     { return(m_timestamp != UNINITED); }
21     bool is_at_begin() const
22     { return(m_timestamp == AT_BEGIN); }
24     position_t get_state() const
25     {
26         return((m_timestamp >= AT_KEY)
27              ? AT_KEY
28              : ((position_t)m_timestamp));
29     }
31     void set_at_begin()
32     { m_timestamp = AT_BEGIN; }
34     unsigned int get_index() const
35     { return(m_index); }
37     void set_pos(unsigned int a_index, unsigned int a_timestmap)
38     {
39         m_index = a_index;
40         m_timestamp = a_timestmap;
41     }
43     bool check_pos(unsigned int a_num_entries, unsigned int a_timestamp) const
44     {
45         if (get_state() != AT_KEY)
46             return(false);
48         if (m_timestamp != a_timestamp)
49             return(false);
51         return(m_index < a_num_entries);
52     }
54     void set_not_init()
55     { m_timestamp = 0; }
57 private:
59     unsigned int m_timestamp;
60     unsigned int m_index;
64 class CCUTILS_KeyedScalarPosition
66 public:
68     CCUTILS_KeyedScalarLevelPosition m_L1;
69     CCUTILS_KeyedScalarLevelPosition m_L2;
72 class baz
74 public:
75     int *n[20];
76     unsigned int m_cur_array_len;
77     unsigned int m_timestamp;
79     unsigned int _get_timestamp() const
80     { return(m_timestamp); }
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     }
88     void *next (CCUTILS_KeyedScalarPosition &);
91 void * baz::next (CCUTILS_KeyedScalarPosition &a_position)
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);
101     return n[a_position.m_L1.get_index ()];
104 int main (int, char **)
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;