Question on the benefits of diagnosis. One person proposed to implement the search of all explicit type-C conversions in the PVS-Studio analyzer. Those. identify constructs of the form:

int *x = (int *)y; float a = float(b); float c = (float)(d);

The goal is to replace all these casts with safer options - reinterpret_cast / static_cast / const_cast. In the process of such refactoring, some defects may well be identified.

Of course, this is not revealing the real mistakes. And if this diagnostic is implemented, it will be in the [Customer's Specific Requests] section and disabled by default.

However, even in the benefits of this option, I'm not sure. I decided to ask a question. Need someone else to search for all the explicit type conversions in the style of C? Would someone like to do this refactoring of their code?

Closed due to the fact that it was off topic by participants aleksandr barakin , Vladimir Glinskikh , Visman , Aries , ermak0ff Sep 27 '15 at 8:00 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Questionnaires are forbidden on Stack Overflow in Russian . To get an answer, rephrase your question so that it can be given an unambiguously correct answer." - aleksandr barakin, Vladimir Glinskikh, Visman, Aries, ermak0ff
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • I think it makes sense. - gecube

1 answer 1

There are different options for such a reduction. 1) meaningless

 float d = 3; float c = (float)(d); 

for these it is worth proposing to just remove.

2) on request api. This is when a certain external function is declared with one type, and in the code we have a different type and do the coercion by force, although you could immediately declare correctly.

3) transformations that are not needed - this is when a given expression is guaranteed to fit into the result. (for example char to int).

But the main thing is that after any advice of PVS-Studio the code would be compiled at the maximum level of compiler pickiness.