]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/c2x-qual-4.c
1 /* { dg-do compile } */
2 /* { dg-options "-std=c2x" } */
4 void transpose0(double* out
, const double* in
) { }
5 void transpose1(double out
[2][2], const double in
[2][2]) { }
6 void transpose2(double out
[2][2][2], const double in
[2][2][2]) { }
8 int (*y2(const int x
[3][3]))[3] { return x
; } /* { dg-warning "return discards 'const' qualifier from pointer target type" } */
9 const int (*y3(int x
[3][3]))[3] { return x
; }
18 const double z1
[2][2];
22 const double z2
[2][2][2];
27 tvoid(z0
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
28 tvoid(z1
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
29 tvoid(z2
); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
35 p
= z0
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
36 p
= z1
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
37 p
= z2
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
44 transpose0(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose0' discards 'const' qualifier from pointer target type" } */
45 transpose1(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose1' discards 'const' qualifier from pointer target type" } */
46 transpose2(pc
, p
); /* { dg-warning "passing argument 1 of 'transpose2' discards 'const' qualifier from pointer target type" } */
50 // passing as arguments
55 const double (*u0p
) = x0
;
56 const double (*u1p
)[2] = x1
;
57 const double (*u2p
)[2][2] = x2
;
58 double (*v0p
) = z0
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
59 double (*v1p
)[2] = z1
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
60 double (*v2p
)[2][2] = z2
; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
79 v0p
= z0
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
80 v1p
= z1
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
81 v2p
= z2
; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
82 // conditional expressions
86 (void)(1 ? x0
: x1
); /* { dg-warning "pointer type mismatch in conditional expression" } */
87 (void)(1 ? x1
: x2
); /* { dg-warning "pointer type mismatch in conditional expression" } */
88 (void)(1 ? x2
: x0
); /* { dg-warning "pointer type mismatch in conditional expression" } */
89 v0p
= (1 ? z0
: v0p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
90 v1p
= (1 ? z1
: v1p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
91 v2p
= (1 ? z2
: v2p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
92 v0p
= (1 ? x0
: u0p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
93 v1p
= (1 ? x1
: u1p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
94 v2p
= (1 ? x2
: u2p
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
95 (1 ? x0
: z0
)[0] = 1; /* { dg-error "assignment of read-only location" } */
96 (1 ? x1
: z1
)[0][0] = 1; /* { dg-error "assignment of read-only location" } */
97 (1 ? x2
: z2
)[0][0][0] = 1; /* { dg-error "assignment of read-only location" } */
98 v0p
= (1 ? p
: z0
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
99 v1p
= (1 ? p
: z1
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
100 v2p
= (1 ? p
: z2
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
101 v0p
= (1 ? pc
: x0
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
102 v1p
= (1 ? pc
: x1
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
103 v2p
= (1 ? pc
: x2
); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */