1// { dg-do assemble  }
2// g++ 1.37.1 bug 900428_01
3
4// g++ fails to issue error messages for cases where an incomplete type
5// object must be evaluated if the value of such an evaluation is not
6// actually used in the given context.
7
8// In the case where such an object is volatile, it is obvious that this
9// could be a problem, however I believe that errors should be issued
10// for such cases regardless of whether or not such values are volatile
11// because the abstract semantics seem to require the evaluation of such
12// values whether they are volatile or not.
13
14// [expr.static.cast/4, stmt.expr/1, expr.comma/1] show that expressions do
15// not under go lvalue to rvalue decay, unless the value is actually used.
16// This can be surprising when the object is volatile. We interpret a
17// dereference of pointer to volatile to be a read.
18
19// keywords: incomplete types, evaluation, volatile qualifier
20
21int *ip_fn ();
22int &ir_fn ();
23volatile int *vip_fn ();
24volatile int &vir_fn ();
25
26void int_test (int i, int *p, volatile int *vp, int &r, volatile int &vr)
27{
28  int j;
29  volatile int vj;
30
31  *p;				// ok, no warning
32  (void)*p;			// ok, no warning
33  (void)(i ? j : *p);	        // ok, no warning
34  (void)(i ? *p : j);	        // ok, no warning
35  (void)((void)1, *p);	        // ok, no warning
36
37  *vp;				// ok, no warning
38  (void)*vp;			// ok, no warning
39  (void)(i ? vj : *vp);	        // ok, no warning
40  (void)(i ? *vp : vj);	        // ok, no warning
41  (void)((void)1, *vp);         // ok, no warning
42
43  r;				// ok, no warning
44  (void)r;			// ok, no warning
45  (void)(i ? j : r);	        // ok, no warning
46  (void)(i ? r : j);	        // ok, no warning
47  (void)((void)1, r);	        // ok, no warning
48
49  vr;				// { dg-warning "" } reference not accessed
50  (void)vr;			// { dg-warning "" } reference not accessed
51  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
52  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
53  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
54
55  *ip_fn ();			// ok, no warning
56  *vip_fn ();			// ok, no warning
57  ir_fn ();			// ok, no warning
58  vir_fn ();			// { dg-warning "" } reference not accessed
59}
60
61struct S;
62S *sp_fn ();
63S &sr_fn ();
64volatile S *vsp_fn ();
65volatile S &vsr_fn ();
66
67void incomplete_test (int i, S *p, volatile S *vp, S &r, volatile S &vr)
68{
69  extern S j;
70  extern volatile S vj;
71
72  *p;				// ok, no warning
73  (void)*p;			// ok, no warning
74  (void)(i ? j : *p);	        // ok, no warning
75  (void)(i ? *p : j);	        // ok, no warning
76  (void)((void)1, *p);	        // ok, no warning
77
78  *vp;				// { dg-warning "" } incomplete not accessed
79  (void)*vp;			// { dg-warning "" } incomplete not accessed
80  (void)(i ? vj : *vp);	        // { dg-warning "" } incomplete not accessed
81  (void)(i ? *vp : vj);	        // { dg-warning "" } incomplete not accessed
82  (void)((void)1, *vp);         // { dg-warning "" } incomplete not accessed
83
84  r;				// ok, no warning
85  (void)r;			// ok, no warning
86  (void)(i ? j : r);	        // ok, no warning
87  (void)(i ? r : j);	        // ok, no warning
88  (void)((void)1, r);	        // ok, no warning
89
90  vr;				// { dg-warning "" } reference not accessed
91  (void)vr;			// { dg-warning "" } reference not accessed
92  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
93  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
94  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
95
96  *sp_fn ();			// ok, no warning
97  *vsp_fn ();			// { dg-warning "" } incomplete not accessed
98  sr_fn ();			// ok, no warning
99  vsr_fn ();			// { dg-warning "" } reference not accessed
100}
101
102struct T {int m;};
103T *tp_fn ();
104T &tr_fn ();
105volatile T *vtp_fn ();
106volatile T &vtr_fn ();
107
108void complete_test (int i, T *p, volatile T *vp, T &r, volatile T &vr)
109{
110  T j;
111  volatile T vj;
112
113  *p;				// ok, no warning
114  (void)*p;			// ok, no warning
115  (void)(i ? j : *p);	        // ok, no warning
116  (void)(i ? *p : j);	        // ok, no warning
117  (void)((void)1, *p);	        // ok, no warning
118
119  *vp;				// ok, no warning
120  (void)*vp;			// ok, no warning
121  (void)(i ? vj : *vp);	        // ok, no warning
122  (void)(i ? *vp : vj);	        // ok, no warning
123  (void)((void)1, *vp);         // ok, no warning
124
125  r;				// ok, no warning
126  (void)r;			// ok, no warning
127  (void)(i ? j : r);	        // ok, no warning
128  (void)(i ? r : j);	        // ok, no warning
129  (void)((void)1, r);	        // ok, no warning
130
131  vr;				// { dg-warning "" } reference not accessed
132  (void)vr;			// { dg-warning "" } reference not accessed
133  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
134  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
135  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
136
137  *tp_fn ();			// ok, no warning
138  *vtp_fn ();			// ok, no warning
139  tr_fn ();			// ok, no warning
140  vtr_fn ();			// ok, no warning{ dg-warning "" } reference not accessed
141}
142
143void extern_test ()
144{
145  extern S es;
146  extern volatile S ves;
147  extern T et;
148  extern volatile T vet;
149
150  extern S &esr;
151  extern volatile S &vesr;
152  extern T &etr;
153  extern volatile T &vetr;
154
155  es;				// ok, no warning
156  ves;				// { dg-warning "" } incomplete not accessed
157  et;				// ok, no warning
158  vet;				// ok, no warning
159
160  esr;				// ok, no warning
161  vesr;				// { dg-warning "" } incomplete not accessed
162  etr;				// ok, no warning
163  vetr;				// { dg-warning "" } reference not accessed
164}
165