cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

valueflow.cpp: limit `const_cast` to the necessary calls

Open firewave opened this issue 3 years ago • 2 comments

This shows that there's only two calls which actually require the const_cast so there's no need to do it arbitrary all over the code (there was even at least one redundant one). The valueFlowGeneric*() probably also just require this just for setTokenValue() so it might be possible to get rid of those as well.

firewave avatar Aug 07 '22 17:08 firewave

I dont really understand why we are just reducing const_cast instead of fixing them in the first place, as this seems to make it harder to fix in the future.

pfultz2 avatar Aug 07 '22 19:08 pfultz2

I dont really understand why we are just reducing const_cast instead of fixing them in the first place, as this seems to make it harder to fix in the future.

It's an incremental approach. I mentioned the intentions in my initial comment.

firewave avatar Aug 07 '22 20:08 firewave

Closing as though the idea to pinpoint the exact location where something is actually modifying is enticing the usage of const_cast should be avoided in general. So actually getting rid of those calls makes way more sense. Also we have the constParameter* and constVariable checks which would help to properly propagate const where possible.

Also this can no longer be properly rebased.

firewave avatar Dec 02 '23 12:12 firewave