Any recommendations of a tool or method to refactor/replace casts such as:
(type*) data
into:
convert_to_type(data)
Things become trickier when data has higher priority operators, parenthesis or line breaks in it:
(type*) a(b)->
c
should become convert_to_type(a(b)->c) not convert_to_type(a)(b)->c etc.
I'm not aware of a tool that's able to properly parse and replace these automatically.
The best option I'm aware of is to use g++ with -Wold-style-cast which will then helpfully warn you for all such C-style casts, allowing you to disposition them properly by analyzing the code in question. This will obviously take more time than a tool but it also give you the opportunity to review and prevent a tool from doing an incorrect conversion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With