2 // g++ 1.37.1 bug 900428_01
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.
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.
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.
19 // keywords: incomplete types, evaluation, volatile qualifier
23 volatile int *vip_fn ();
24 volatile int &vir_fn ();
26 void int_test (int i, int *p, volatile int *vp, int &r, volatile int &vr)
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
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
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
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
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
64 volatile S *vsp_fn ();
65 volatile S &vsr_fn ();
67 void incomplete_test (int i, S *p, volatile S *vp, S &r, volatile S &vr)
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
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
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
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
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
105 volatile T *vtp_fn ();
106 volatile T &vtr_fn ();
108 void complete_test (int i, T *p, volatile T *vp, T &r, volatile T &vr)
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
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
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
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
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
146 extern volatile S ves;
148 extern volatile T vet;
151 extern volatile S &vesr;
153 extern volatile T &vetr;
155 es; // ok, no warning
156 ves; // { dg-warning "" } incomplete not accessed
157 et; // ok, no warning
158 vet; // ok, no warning
160 esr; // ok, no warning
161 vesr; // { dg-warning "" } incomplete not accessed
162 etr; // ok, no warning
163 vetr; // { dg-warning "" } reference not accessed