1 /* { dg-do compile } */
2 /* { dg-options "-pedantic-errors" } */
3 /* Origin: Martin Uecker <uecker@eecs.berkeley.edu> */
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 (*x2(const int x
[3][3]))[3] { return x
; } /* { dg-error "pointers to arrays with different qualifiers|return discards" } */
10 const int (*x3(int x
[3][3]))[3] { return x
; } /* { dg-error "pointers to arrays with different qualifiers" } */
19 const double z1
[2][2];
23 const double z2
[2][2][2];
25 tvoid(z0
); /* { dg-error "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
26 tvoid(z1
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
27 tvoid(z2
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
33 p
= z0
; /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
34 p
= z1
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
35 p
= z2
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
42 transpose0(pc
, p
); /* { dg-error "passing argument 1 of 'transpose0' discards 'const' qualifier from pointer target type" } */
43 transpose1(pc
, p
); /* { dg-error "passing argument 1 of 'transpose1' discards 'const' qualifier from pointer target type" } */
44 transpose2(pc
, p
); /* { dg-error "passing argument 1 of 'transpose2' discards 'const' qualifier from pointer target type" } */
46 transpose1(p
, pc
); /* { dg-error "passing argument 2 of 'transpose1' discards 'const' qualifier from pointer target type" } */
47 transpose2(p
, pc
); /* { dg-error "passing argument 2 of 'transpose2' discards 'const' qualifier from pointer target type" } */
48 // passing as arguments
50 transpose1(y1
, o1
); /* { dg-error "passing argument 2 of 'transpose1' from incompatible pointer type" } */
51 transpose1(y1
, x1
); /* { dg-error "pointers to arrays with different qualifiers" } */
52 transpose2(y2
, o2
); /* { dg-error "passing argument 2 of 'transpose2' from incompatible pointer type" } */
53 transpose2(y2
, x2
); /* { dg-error "pointers to arrays with different qualifiers" } */
55 const double (*x0p
) = x0
;
56 const double (*x1p
)[2] = x1
; /* { dg-error "pointers to arrays with different qualifiers" } */
57 const double (*x2p
)[2][2] = x2
; /* { dg-error "pointers to arrays with different qualifiers" } */
58 double (*v0p
) = z0
; /* { dg-error "initialization discards 'const' qualifier from pointer target type" } */
59 double (*v1p
)[2] = z1
; /* { dg-error "pointers to arrays with different qualifiers|initialization discards" } */
60 double (*v2p
)[2][2] = z2
; /* { dg-error "pointers to arrays with different qualifiers|initialization discards" } */
63 x1p
= x1
; /* { dg-error "pointers to arrays with different qualifiers" } */
64 x2p
= x2
; /* { dg-error "pointers to arrays with different qualifiers" } */
67 &(x1
[1]) - &(z1
[0]); /* { dg-error "pointers to arrays with different qualifiers" } */
68 &(x2
[1]) - &(z2
[0]); /* { dg-error "pointers to arrays with different qualifiers" } */
71 x1
== z1
; /* { dg-error "pointers to arrays with different qualifiers" } */
72 x2
== z2
; /* { dg-error "pointers to arrays with different qualifiers" } */
74 x1
< z1
; /* { dg-error "pointers to arrays with different qualifiers" } */
75 x2
< z2
; /* { dg-error "pointers to arrays with different qualifiers" } */
77 x1
> z1
; /* { dg-error "pointers to arrays with different qualifiers" } */
78 x2
> z2
; /* { dg-error "pointers to arrays with different qualifiers" } */
79 // conditional expressions
81 (void)(1 ? x1
: z1
); /* { dg-error "pointers to arrays with different qualifiers" } */
82 (void)(1 ? x2
: z2
); /* { dg-error "pointers to arrays with different qualifiers" } */
83 (void)(1 ? x0
: x1
); /* { dg-error "pointer type mismatch in conditional expression" } */
84 (void)(1 ? x1
: x2
); /* { dg-error "pointer type mismatch in conditional expression" } */
85 (void)(1 ? x2
: x0
); /* { dg-error "pointer type mismatch in conditional expression" } */
86 v0p
= (1 ? z0
: v0p
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
87 v1p
= (1 ? z1
: v1p
); /* { dg-error "pointers to arrays with different qualifiers|assignment discards" } */
88 v2p
= (1 ? z2
: v2p
); /* { dg-error "pointers to arrays with different qualifiers|assignment discards" } */
89 v0p
= (1 ? x0
: x0p
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
90 v1p
= (1 ? x1
: x1p
); /* { dg-error "pointers to arrays with different qualifiers|assignment discards" } */
91 v2p
= (1 ? x2
: x2p
); /* { dg-error "pointers to arrays with different qualifiers|assignment discards" } */
92 (1 ? x0
: z0
)[0] = 1; /* { dg-error "assignment of read-only location" } */
93 (1 ? x1
: z1
)[0][0] = 1; /* { dg-error "assignment of read-only location|pointers to arrays" } */
94 (1 ? x2
: z2
)[0][0][0] = 1; /* { dg-error "assignment of read-only location|pointers to arrays" } */
95 v0p
= (1 ? p
: z0
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
96 v1p
= (1 ? p
: z1
); /* { dg-warning "pointer to array loses qualifier in conditional expression" } */
97 v2p
= (1 ? p
: z2
); /* { dg-warning "pointer to array loses qualifier in conditional expression" } */
98 v0p
= (1 ? pc
: x0
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
99 v1p
= (1 ? pc
: x1
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */
100 v2p
= (1 ? pc
: x2
); /* { dg-error "assignment discards 'const' qualifier from pointer target type" } */