| 1 |
/* Test qualification of components of qualified structures or unions: |
| 2 |
should have qualifiers from both the component and the structure or |
| 3 |
union. Bug 27697 from Frank Victor Fischer. */ |
| 4 |
/* Origin: Joseph Myers <[email protected]> */ |
| 5 |
/* { dg-do compile } */ |
| 6 |
/* { dg-options "-std=gnu17 -pedantic -Wdiscarded-array-qualifiers" } */ |
| 7 |
|
| 8 |
struct s { |
| 9 |
int a; |
| 10 |
int b[1]; |
| 11 |
int c[2][3]; |
| 12 |
const int d; |
| 13 |
const int e[1]; |
| 14 |
const int f[2][3]; |
| 15 |
}; |
| 16 |
|
| 17 |
union u { |
| 18 |
int a; |
| 19 |
int b[1]; |
| 20 |
int c[2][3]; |
| 21 |
const int d; |
| 22 |
const int e[1]; |
| 23 |
const int f[2][3]; |
| 24 |
}; |
| 25 |
|
| 26 |
struct cs { |
| 27 |
const struct s x; |
| 28 |
}; |
| 29 |
|
| 30 |
struct s v1; |
| 31 |
union u *v2; |
| 32 |
const struct s *v3; |
| 33 |
const union u v4; |
| 34 |
struct cs v5; |
| 35 |
|
| 36 |
void |
| 37 |
f (void) |
| 38 |
{ |
| 39 |
v1.a = 0; |
| 40 |
v1.b[0] = 0; |
| 41 |
*v1.b = 0; |
| 42 |
v1.c[0][0] = 0; |
| 43 |
*v1.c[0] = 0; |
| 44 |
**v1.c = 0; |
| 45 |
v1.d = 0; /* { dg-error "assignment of read-only" } */ |
| 46 |
v1.e[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 47 |
*v1.e = 0; /* { dg-error "assignment of read-only" } */ |
| 48 |
v1.f[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 49 |
*v1.f[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 50 |
**v1.f = 0; /* { dg-error "assignment of read-only" } */ |
| 51 |
|
| 52 |
v2->a = 0; |
| 53 |
v2->b[0] = 0; |
| 54 |
*v2->b = 0; |
| 55 |
v2->c[0][0] = 0; |
| 56 |
*v2->c[0] = 0; |
| 57 |
**v2->c = 0; |
| 58 |
v2->d = 0; /* { dg-error "assignment of read-only" } */ |
| 59 |
v2->e[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 60 |
*v2->e = 0; /* { dg-error "assignment of read-only" } */ |
| 61 |
v2->f[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 62 |
*v2->f[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 63 |
**v2->f = 0; /* { dg-error "assignment of read-only" } */ |
| 64 |
|
| 65 |
v3->a = 0; /* { dg-error "assignment of member" } */ |
| 66 |
v3->b[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 67 |
*v3->b = 0; /* { dg-error "assignment of read-only" } */ |
| 68 |
v3->c[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 69 |
*v3->c[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 70 |
**v3->c = 0; /* { dg-error "assignment of read-only" } */ |
| 71 |
v3->d = 0; /* { dg-error "assignment of member" } */ |
| 72 |
v3->e[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 73 |
*v3->e = 0; /* { dg-error "assignment of read-only" } */ |
| 74 |
v3->f[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 75 |
*v3->f[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 76 |
**v3->f = 0; /* { dg-error "assignment of read-only" } */ |
| 77 |
|
| 78 |
v4.a = 0; /* { dg-error "assignment of member" } */ |
| 79 |
v4.b[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 80 |
*v4.b = 0; /* { dg-error "assignment of read-only" } */ |
| 81 |
v4.c[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 82 |
*v4.c[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 83 |
**v4.c = 0; /* { dg-error "assignment of read-only" } */ |
| 84 |
v4.d = 0; /* { dg-error "assignment of member" } */ |
| 85 |
v4.e[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 86 |
*v4.e = 0; /* { dg-error "assignment of read-only" } */ |
| 87 |
v4.f[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 88 |
*v4.f[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 89 |
**v4.f = 0; /* { dg-error "assignment of read-only" } */ |
| 90 |
|
| 91 |
v5.x.a = 0; /* { dg-error "assignment of member" } */ |
| 92 |
v5.x.b[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 93 |
*v5.x.b = 0; /* { dg-error "assignment of read-only" } */ |
| 94 |
v5.x.c[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 95 |
*v5.x.c[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 96 |
**v5.x.c = 0; /* { dg-error "assignment of read-only" } */ |
| 97 |
v5.x.d = 0; /* { dg-error "assignment of member" } */ |
| 98 |
v5.x.e[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 99 |
*v5.x.e = 0; /* { dg-error "assignment of read-only" } */ |
| 100 |
v5.x.f[0][0] = 0; /* { dg-error "assignment of read-only" } */ |
| 101 |
*v5.x.f[0] = 0; /* { dg-error "assignment of read-only" } */ |
| 102 |
**v5.x.f = 0; /* { dg-error "assignment of read-only" } */ |
| 103 |
} |
| 104 |
|
| 105 |
void |
| 106 |
g (void) |
| 107 |
{ |
| 108 |
{ |
| 109 |
int *a = &v1.a; |
| 110 |
int (*b)[1] = &v1.b; |
| 111 |
int (*c)[2][3] = &v1.c; |
| 112 |
int (*cc)[3] = v1.c; |
| 113 |
const int (*ff)[3] = v1.c; /* { dg-warning "pointers to arrays with different qualifiers" } */ |
| 114 |
a = &v1.a; |
| 115 |
b = &v1.b; |
| 116 |
c = &v1.c; |
| 117 |
cc = v1.c; |
| 118 |
ff = v1.c; /* { dg-warning "pointers to arrays with different qualifiers" } */ |
| 119 |
} |
| 120 |
{ |
| 121 |
const int *d = &v1.d; |
| 122 |
const int (*e)[1] = &v1.e; |
| 123 |
const int (*f)[2][3] = &v1.f; |
| 124 |
const int (*ff)[3] = v1.f; |
| 125 |
int (*cc)[3] = v1.f; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 126 |
d = &v1.d; |
| 127 |
e = &v1.e; |
| 128 |
f = &v1.f; |
| 129 |
ff = v1.f; |
| 130 |
cc = v1.f; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 131 |
} |
| 132 |
|
| 133 |
{ |
| 134 |
int *a = &v2->a; |
| 135 |
int (*b)[1] = &v2->b; |
| 136 |
int (*c)[2][3] = &v2->c; |
| 137 |
int (*cc)[3] = v2->c; |
| 138 |
const int (*ff)[3] = v2->c; /* { dg-warning "pointers to arrays with different qualifiers" } */ |
| 139 |
a = &v2->a; |
| 140 |
b = &v2->b; |
| 141 |
c = &v2->c; |
| 142 |
cc = v2->c; |
| 143 |
ff = v2->c; /* { dg-warning "pointers to arrays with different qualifiers" } */ |
| 144 |
} |
| 145 |
{ |
| 146 |
const int *d = &v2->d; |
| 147 |
const int (*e)[1] = &v2->e; |
| 148 |
const int (*f)[2][3] = &v2->f; |
| 149 |
const int (*ff)[3] = v2->f; |
| 150 |
int (*cc)[3] = v2->f; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 151 |
d = &v2->d; |
| 152 |
e = &v2->e; |
| 153 |
f = &v2->f; |
| 154 |
ff = v2->f; |
| 155 |
cc = v2->f; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 156 |
} |
| 157 |
|
| 158 |
{ |
| 159 |
const int *d = &v3->a; |
| 160 |
const int (*e)[1] = &v3->b; |
| 161 |
const int (*f)[2][3] = &v3->c; |
| 162 |
const int (*ff)[3] = v3->c; |
| 163 |
int (*cc)[3] = v3->c; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 164 |
d = &v3->a; |
| 165 |
e = &v3->b; |
| 166 |
f = &v3->c; |
| 167 |
ff = v3->c; |
| 168 |
cc = v3->c; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 169 |
} |
| 170 |
{ |
| 171 |
const int *d = &v3->d; |
| 172 |
const int (*e)[1] = &v3->e; |
| 173 |
const int (*f)[2][3] = &v3->f; |
| 174 |
const int (*ff)[3] = v3->f; |
| 175 |
int (*cc)[3] = v3->f; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 176 |
d = &v3->d; |
| 177 |
e = &v3->e; |
| 178 |
f = &v3->f; |
| 179 |
ff = v3->f; |
| 180 |
cc = v3->f; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 181 |
} |
| 182 |
|
| 183 |
{ |
| 184 |
const int *d = &v4.a; |
| 185 |
const int (*e)[1] = &v4.b; |
| 186 |
const int (*f)[2][3] = &v4.c; |
| 187 |
const int (*ff)[3] = v4.c; |
| 188 |
int (*cc)[3] = v4.c; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 189 |
d = &v4.a; |
| 190 |
e = &v4.b; |
| 191 |
f = &v4.c; |
| 192 |
ff = v4.c; |
| 193 |
cc = v4.c; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 194 |
} |
| 195 |
{ |
| 196 |
const int *d = &v4.d; |
| 197 |
const int (*e)[1] = &v4.e; |
| 198 |
const int (*f)[2][3] = &v4.f; |
| 199 |
const int (*ff)[3] = v4.f; |
| 200 |
int (*cc)[3] = v4.f; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 201 |
d = &v4.d; |
| 202 |
e = &v4.e; |
| 203 |
f = &v4.f; |
| 204 |
ff = v4.f; |
| 205 |
cc = v4.f; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 206 |
} |
| 207 |
|
| 208 |
{ |
| 209 |
const int *d = &v5.x.a; |
| 210 |
const int (*e)[1] = &v5.x.b; |
| 211 |
const int (*f)[2][3] = &v5.x.c; |
| 212 |
const int (*ff)[3] = v5.x.c; |
| 213 |
int (*cc)[3] = v5.x.c; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 214 |
d = &v5.x.a; |
| 215 |
e = &v5.x.b; |
| 216 |
f = &v5.x.c; |
| 217 |
ff = v5.x.c; |
| 218 |
cc = v5.x.c; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 219 |
} |
| 220 |
{ |
| 221 |
const int *d = &v5.x.d; |
| 222 |
const int (*e)[1] = &v5.x.e; |
| 223 |
const int (*f)[2][3] = &v5.x.f; |
| 224 |
const int (*ff)[3] = v5.x.f; |
| 225 |
int (*cc)[3] = v5.x.f; /* { dg-warning "pointers to arrays with different qualifiers|initialization discards" } */ |
| 226 |
d = &v5.x.d; |
| 227 |
e = &v5.x.e; |
| 228 |
f = &v5.x.f; |
| 229 |
ff = v5.x.f; |
| 230 |
cc = v5.x.f; /* { dg-warning "pointers to arrays with different qualifiers|assignment discards" } */ |
| 231 |
} |
| 232 |
} |