annotate gcc/testsuite/g++.old-deja/g++.other/cast3.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // { dg-do assemble }
kono
parents:
diff changeset
2 // Copyright (C) 1999 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 // Contributed by Nathan Sidwell 12 Dec 1999 <nathan@acm.org>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 // static_cast should not cast _away_ constness ([expr.static.cast]/6),
kono
parents:
diff changeset
6 // but nothing bans _adding_ constness. [expr.static.cast]/10 states that a
kono
parents:
diff changeset
7 // pointer of type cv void can be cast to pointer to object type.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 struct X;
kono
parents:
diff changeset
10 struct Y {};
kono
parents:
diff changeset
11 struct Z : Y {};
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 void fn (void *p, void const *cp, Y *yp, Y const *ycp, Z *zp, Z const *zcp)
kono
parents:
diff changeset
14 {
kono
parents:
diff changeset
15 static_cast <X *> (p);
kono
parents:
diff changeset
16 static_cast <X const *> (p);
kono
parents:
diff changeset
17 static_cast <int *> (p);
kono
parents:
diff changeset
18 static_cast <int const *> (p);
kono
parents:
diff changeset
19 static_cast <int **> (p);
kono
parents:
diff changeset
20 static_cast <int const **> (p);
kono
parents:
diff changeset
21 static_cast <int *const *> (p);
kono
parents:
diff changeset
22 static_cast <int const *const *> (p);
kono
parents:
diff changeset
23
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
24 static_cast <X *> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .X\\*. casts away qualifiers" } lose const
111
kono
parents:
diff changeset
25 static_cast <X const *> (cp);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
26 static_cast <int *> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*. casts away qualifiers" } lose const
111
kono
parents:
diff changeset
27 static_cast <int const *> (cp);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
28 static_cast <int **> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*\\*. casts away qualifiers" } lose const
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
29 static_cast <int const **> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .const int\\*\\*. casts away qualifiers" } lose const
111
kono
parents:
diff changeset
30 static_cast <int *const *> (cp);
kono
parents:
diff changeset
31 static_cast <int const *const *> (cp);
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 static_cast <Z *> (yp);
kono
parents:
diff changeset
34 static_cast <Z const *> (yp);
kono
parents:
diff changeset
35
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
36 static_cast <Z *> (ycp); // { dg-error "3:.static_cast. from type .const Y\\*. to type .Z\\*. casts away qualifiers" } lose const
111
kono
parents:
diff changeset
37 static_cast <Z const *> (ycp);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 static_cast <Y *> (zp);
kono
parents:
diff changeset
40 static_cast <Y const *> (zp);
kono
parents:
diff changeset
41
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
42 static_cast <Y *> (zcp); // { dg-error "3:invalid .static_cast. from type .const Z\\*. to type .Y\\*." } lose const
111
kono
parents:
diff changeset
43 static_cast <Y const *> (zcp);
kono
parents:
diff changeset
44 }