111
|
1 // { dg-do assemble }
|
|
2 // Copyright (C) 1999 Free Software Foundation, Inc.
|
|
3 // Contributed by Nathan Sidwell 12 Dec 1999 <nathan@acm.org>
|
|
4
|
|
5 // static_cast should not cast _away_ constness ([expr.static.cast]/6),
|
|
6 // but nothing bans _adding_ constness. [expr.static.cast]/10 states that a
|
|
7 // pointer of type cv void can be cast to pointer to object type.
|
|
8
|
|
9 struct X;
|
|
10 struct Y {};
|
|
11 struct Z : Y {};
|
|
12
|
|
13 void fn (void *p, void const *cp, Y *yp, Y const *ycp, Z *zp, Z const *zcp)
|
|
14 {
|
|
15 static_cast <X *> (p);
|
|
16 static_cast <X const *> (p);
|
|
17 static_cast <int *> (p);
|
|
18 static_cast <int const *> (p);
|
|
19 static_cast <int **> (p);
|
|
20 static_cast <int const **> (p);
|
|
21 static_cast <int *const *> (p);
|
|
22 static_cast <int const *const *> (p);
|
|
23
|
145
|
24 static_cast <X *> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .X\\*. casts away qualifiers" } lose const
|
111
|
25 static_cast <X const *> (cp);
|
145
|
26 static_cast <int *> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*. casts away qualifiers" } lose const
|
111
|
27 static_cast <int const *> (cp);
|
145
|
28 static_cast <int **> (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*\\*. casts away qualifiers" } lose const
|
|
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
|
30 static_cast <int *const *> (cp);
|
|
31 static_cast <int const *const *> (cp);
|
|
32
|
|
33 static_cast <Z *> (yp);
|
|
34 static_cast <Z const *> (yp);
|
|
35
|
145
|
36 static_cast <Z *> (ycp); // { dg-error "3:.static_cast. from type .const Y\\*. to type .Z\\*. casts away qualifiers" } lose const
|
111
|
37 static_cast <Z const *> (ycp);
|
|
38
|
|
39 static_cast <Y *> (zp);
|
|
40 static_cast <Y const *> (zp);
|
|
41
|
145
|
42 static_cast <Y *> (zcp); // { dg-error "3:invalid .static_cast. from type .const Z\\*. to type .Y\\*." } lose const
|
111
|
43 static_cast <Y const *> (zcp);
|
|
44 }
|