2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / other / old-style-cast-fixits.C
bloba10b623f9818d531be9e6145aa009f207fc95a51
1 // { dg-options "-Wold-style-cast -fdiagnostics-show-caret" }
3 struct foo {};
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 "" }
10    foo *f = (foo *)ptr;
11                    ^~~
12             ----------
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 "" }
21    foo *f = (foo *)ptr;
22                    ^~~
23             ----------
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 "" }
32    foo *f = (foo *)ptr;
33                    ^~~
34             ----------
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;
44                         ^~~~~
45             -----------------
46             const_cast<foo *> (ptr->field)
47      { dg-end-multiline-output "" } */
50 void test_5 ()
52   bar b_inst;
53   foo *f = (foo *)&b_inst; // { dg-warning "old-style cast" }
54   /* { dg-begin-multiline-output "" }
55    foo *f = (foo *)&b_inst;
56                     ^~~~~~
57             --------------
58             reinterpret_cast<foo *> (&b_inst)
59      { dg-end-multiline-output "" } */
62 /* We don't offer suggestions for templates.  */
64 template <typename T>
65 void test_6 (void *ptr)
67   foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
68   /* { dg-begin-multiline-output "" }
69    foo *f = (foo *)ptr;
70                    ^~~
71      { dg-end-multiline-output "" } */
74 /* We don't offer suggestions where a single C++-style cast can't be
75    used.  */
77 void test_7 (const void *ptr)
79   foo *f = (foo *)ptr; // { dg-warning "old-style cast" }
80   /* { dg-begin-multiline-output "" }
81    foo *f = (foo *)ptr;
82                    ^~~
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;
93                     ^~~~~~
94      { dg-end-multiline-output "" } */