1 // { dg-options "-Wold-style-cast -fdiagnostics-show-caret" }
4 struct bar { const foo *field; };
6 void test_1 (void *ptr)
8 foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
9 /* { dg-begin-multiline-output "" }
13 static_cast<foo *> (ptr)
14 { dg-end-multiline-output "" } */
17 void test_2 (const foo *ptr)
19 foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
20 /* { dg-begin-multiline-output "" }
24 const_cast<foo *> (ptr)
25 { dg-end-multiline-output "" } */
28 void test_3 (bar *ptr)
30 foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
31 /* { dg-begin-multiline-output "" }
35 reinterpret_cast<foo *> (ptr)
36 { dg-end-multiline-output "" } */
39 void test_4 (bar *ptr)
41 foo *f = (foo *)ptr->field; // { dg-warning "old-style cast" }
42 /* { dg-begin-multiline-output "" }
43 foo *f = (foo *)ptr->field;
46 const_cast<foo *> (ptr->field)
47 { dg-end-multiline-output "" } */
53 foo *f = (foo *)&b_inst; // { dg-warning "old-style cast" }
54 /* { dg-begin-multiline-output "" }
55 foo *f = (foo *)&b_inst;
58 reinterpret_cast<foo *> (&b_inst)
59 { dg-end-multiline-output "" } */
62 /* We don't offer suggestions for templates. */
65 void test_6 (void *ptr)
67 foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
68 /* { dg-begin-multiline-output "" }
71 { dg-end-multiline-output "" } */
74 /* We don't offer suggestions where a single C++-style cast can't be
77 void test_7 (const void *ptr)
79 foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
80 /* { dg-begin-multiline-output "" }
83 { dg-end-multiline-output "" } */
86 /* Likewise, no single C++-style cast is usable here. */
88 void test_8 (const bar &b_inst)
90 foo *f = (foo *)&b_inst; // { dg-warning "old-style cast" }
91 /* { dg-begin-multiline-output "" }
92 foo *f = (foo *)&b_inst;
94 { dg-end-multiline-output "" } */