Answer the question
In order to leave comments, you need to log in
C++, search for explicit type conversions: a = (int)b;?
A question about diagnostics.
One person suggested to implement in the PVS-Studio analyzer a search for all explicit type conversions in the C style. Those. detect constructions of the form:
int *x = (int *)y;
float a = float(b);
float c = (float)(d);
The goal is to replace all of these casts with safer options - reinterpret_cast / static_cast / const_cast. In the process of such refactoring, some defects may well be revealed.
Of course, this is not the detection of real errors. And if this diagnostic is implemented, it will be located in the [Customer's Specific Requests] section and disabled by default.
However, even in the benefits of this option, I'm not sure. Decided to ask a question. Does anyone else need to look up all the explicit C-style casts? Would anyone like to do similar refactoring of their code?
Answer the question
In order to leave comments, you need to log in
Definitely necessary. C-style type casting is an evil that needs to be fought.
A very useful feature. Repeatedly rewrote both my own code and the inherited one, in order to translate everything into the C++ version.
You wrote that you don't want to duplicate compiler checks. g++ has a -Wold-style-cast switch that turns on warnings about such type casts. From this we can conclude that support for this option should not be implemented. I think you should look for more hard-to-find bugs instead.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question