1 /* { dg-do compile } */
2 /* Origin: Martin Uecker <uecker@eecs.berkeley.edu> */
3 /* { dg-options "-Wdiscarded-array-qualifiers" } */
5 void transpose0(double* out
, const double* in
) { }
6 void transpose1(double out
[2][2], const double in
[2][2]) { }
7 void transpose2(double out
[2][2][2], const double in
[2][2][2]) { }
9 int (*y2(const int x
[3][3]))[3] { return x
; } /* { dg-warning "return discards 'const' qualifier from pointer target type" } */
10 const int (*y3(int x
[3][3]))[3] { return x
; }
19 const double z1
[2][2];
23 const double z2
[2][2][2];
28 tvoid(z0
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
29 tvoid(z1
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
30 tvoid(z2
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
36 p
= z0
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
37 p
= z1
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
38 p
= z2
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
45 transpose0(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose0' discards 'const' qualifier from pointer target type" } */
46 transpose1(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose1' discards 'const' qualifier from pointer target type" } */
47 transpose2(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose2' discards 'const' qualifier from pointer target type" } */
51 // passing as arguments
56 const double (*u0p
) = x0
;
57 const double (*u1p
)[2] = x1
;
58 const double (*u2p
)[2][2] = x2
;
59 double (*v0p
) = z0
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
60 double (*v1p
)[2] = z1
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
61 double (*v2p
)[2][2] = z2
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
80 v0p
= z0
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
81 v1p
= z1
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
82 v2p
= z2
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
83 // conditional expressions
87 (void)(1 ? x0
: x1
); /* { dg-warning "pointer type mismatch in conditional expression" } */
88 (void)(1 ? x1
: x2
); /* { dg-warning "pointer type mismatch in conditional expression" } */
89 (void)(1 ? x2
: x0
); /* { dg-warning "pointer type mismatch in conditional expression" } */
90 v0p
= (1 ? z0
: v0p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
91 v1p
= (1 ? z1
: v1p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
92 v2p
= (1 ? z2
: v2p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
93 v0p
= (1 ? x0
: u0p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
94 v1p
= (1 ? x1
: u1p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
95 v2p
= (1 ? x2
: u2p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
96 (1 ? x0
: z0
)[0] = 1; /* { dg-error "assignment of read-only location" } */
97 (1 ? x1
: z1
)[0][0] = 1; /* { dg-error "assignment of read-only location" } */
98 (1 ? x2
: z2
)[0][0][0] = 1; /* { dg-error "assignment of read-only location" } */
99 v0p
= (1 ? p
: z0
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
100 v1p
= (1 ? p
: z1
); /* { dg-warning "pointer to array loses qualifier in conditional expression" } */
101 v2p
= (1 ? p
: z2
); /* { dg-warning "pointer to array loses qualifier in conditional expression" } */
102 v0p
= (1 ? pc
: x0
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
103 v1p
= (1 ? pc
: x1
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
104 v2p
= (1 ? pc
: x2
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */