aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.old-deja/g++.bugs/900428_01.C
blob: a806ef0706e02de250bc556b3d981bb6d43e69a2 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// { dg-do assemble  }
// g++ 1.37.1 bug 900428_01

// g++ fails to issue error messages for cases where an incomplete type
// object must be evaluated if the value of such an evaluation is not
// actually used in the given context.

// In the case where such an object is volatile, it is obvious that this
// could be a problem, however I believe that errors should be issued
// for such cases regardless of whether or not such values are volatile
// because the abstract semantics seem to require the evaluation of such
// values whether they are volatile or not.

// [expr.static.cast/4, stmt.expr/1, expr.comma/1] show that expressions do
// not under go lvalue to rvalue decay, unless the value is actually used.
// This can be surprising when the object is volatile. We interpret a
// dereference of pointer to volatile to be a read.

// keywords: incomplete types, evaluation, volatile qualifier

int *ip_fn ();
int &ir_fn ();
volatile int *vip_fn ();
volatile int &vir_fn ();

void int_test (int i, int *p, volatile int *vp, int &r, volatile int &vr)
{
  int j;
  volatile int vj;
  
  *p;				// ok, no warning
  (void)*p;			// ok, no warning
  (void)(i ? j : *p);	        // ok, no warning
  (void)(i ? *p : j);	        // ok, no warning
  (void)((void)1, *p);	        // ok, no warning

  *vp;				// ok, no warning
  (void)*vp;			// ok, no warning
  (void)(i ? vj : *vp);	        // ok, no warning
  (void)(i ? *vp : vj);	        // ok, no warning
  (void)((void)1, *vp);         // ok, no warning

  r;				// ok, no warning
  (void)r;			// ok, no warning
  (void)(i ? j : r);	        // ok, no warning
  (void)(i ? r : j);	        // ok, no warning
  (void)((void)1, r);	        // ok, no warning

  vr;				// { dg-warning "" } reference not accessed
  (void)vr;			// { dg-warning "" } reference not accessed
  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
  
  *ip_fn ();			// ok, no warning
  *vip_fn ();			// ok, no warning
  ir_fn ();			// ok, no warning
  vir_fn ();			// { dg-warning "" } reference not accessed
}

struct S;
S *sp_fn ();
S &sr_fn ();
volatile S *vsp_fn ();
volatile S &vsr_fn ();

void incomplete_test (int i, S *p, volatile S *vp, S &r, volatile S &vr)
{
  extern S j;
  extern volatile S vj;
  
  *p;				// ok, no warning
  (void)*p;			// ok, no warning
  (void)(i ? j : *p);	        // ok, no warning
  (void)(i ? *p : j);	        // ok, no warning
  (void)((void)1, *p);	        // ok, no warning

  *vp;				// { dg-warning "" } incomplete not accessed
  (void)*vp;			// { dg-warning "" } incomplete not accessed
  (void)(i ? vj : *vp);	        // { dg-warning "" } incomplete not accessed
  (void)(i ? *vp : vj);	        // { dg-warning "" } incomplete not accessed
  (void)((void)1, *vp);         // { dg-warning "" } incomplete not accessed

  r;				// ok, no warning
  (void)r;			// ok, no warning
  (void)(i ? j : r);	        // ok, no warning
  (void)(i ? r : j);	        // ok, no warning
  (void)((void)1, r);	        // ok, no warning

  vr;				// { dg-warning "" } reference not accessed
  (void)vr;			// { dg-warning "" } reference not accessed
  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
  
  *sp_fn ();			// ok, no warning
  *vsp_fn ();			// { dg-warning "" } incomplete not accessed
  sr_fn ();			// ok, no warning
  vsr_fn ();			// { dg-warning "" } reference not accessed
}

struct T {int m;};
T *tp_fn ();
T &tr_fn ();
volatile T *vtp_fn ();
volatile T &vtr_fn ();

void complete_test (int i, T *p, volatile T *vp, T &r, volatile T &vr)
{
  T j;
  volatile T vj;
  
  *p;				// ok, no warning
  (void)*p;			// ok, no warning
  (void)(i ? j : *p);	        // ok, no warning
  (void)(i ? *p : j);	        // ok, no warning
  (void)((void)1, *p);	        // ok, no warning

  *vp;				// ok, no warning
  (void)*vp;			// ok, no warning
  (void)(i ? vj : *vp);	        // ok, no warning
  (void)(i ? *vp : vj);	        // ok, no warning
  (void)((void)1, *vp);         // ok, no warning

  r;				// ok, no warning
  (void)r;			// ok, no warning
  (void)(i ? j : r);	        // ok, no warning
  (void)(i ? r : j);	        // ok, no warning
  (void)((void)1, r);	        // ok, no warning

  vr;				// { dg-warning "" } reference not accessed
  (void)vr;			// { dg-warning "" } reference not accessed
  (void)(i ? vj : vr);	        // { dg-warning "" } reference not accessed
  (void)(i ? vr : vj);	        // { dg-warning "" } reference not accessed
  (void)((void)1, vr);          // { dg-warning "" } reference not accessed
  
  *tp_fn ();			// ok, no warning
  *vtp_fn ();			// ok, no warning
  tr_fn ();			// ok, no warning
  vtr_fn ();			// ok, no warning{ dg-warning "" } reference not accessed
}

void extern_test ()
{
  extern S es;
  extern volatile S ves;
  extern T et;
  extern volatile T vet;
  
  extern S &esr;
  extern volatile S &vesr;
  extern T &etr;
  extern volatile T &vetr;
  
  es;				// ok, no warning
  ves;				// { dg-warning "" } incomplete not accessed
  et;				// ok, no warning
  vet;				// ok, no warning
  
  esr;				// ok, no warning
  vesr;				// { dg-warning "" } incomplete not accessed
  etr;				// ok, no warning
  vetr;				// { dg-warning "" } reference not accessed
}