In einspline there are many warnings for such code. Because there are so many cases with such pattern I do believe that is intentional and therefore these warnings are false positives.
So what should we do to fix the false positives. One possible heuristic to avoid false positives is to match the variable names. Since there is no "doffset" variable in rhs do not show the warning.
As far as I know this check is meant to detect such mistake:
intx=something.x;inty=something.x;
Any other ideas?
Last edit: Daniel Marjamäki 2020-09-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes there would be such false negatives. However off the top of my head I can't see any other heuristic that could avoid the false positive in this case. With an "AI" we could see there is a common pattern and avoid the warnings. The motivation for the warnings are that there could be a mistake and if there is similar code in >10 places then it's more likely by intention.
Your fix is reasonable but I assume the compiler could do that optimisation.
Since this is 1 project I think it's ok if the conclusion is that they must suppress. However if we could have seen some possible heuristic that would be better. :-(
Last edit: Daniel Marjamäki 2020-09-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can see in daca@home that there are many duplicateAssignExpression false positives in einspline.
Here is an example code. Cppcheck warns about the doffset and coffset that is marked with comments below:
In einspline there are many warnings for such code. Because there are so many cases with such pattern I do believe that is intentional and therefore these warnings are false positives.
So what should we do to fix the false positives. One possible heuristic to avoid false positives is to match the variable names. Since there is no "doffset" variable in rhs do not show the warning.
As far as I know this check is meant to detect such mistake:
Any other ideas?
Last edit: Daniel Marjamäki 2020-09-24
Well there is a performance issue as it will calculate the value twice, instead of once. I think writing it like this:
Makes it more intentional and clearer that
coffset
should reuse the value ofdoffset
.I dont think thats great. It would miss mistakes like this:
It could also find mistakes like this:
Yes there would be such false negatives. However off the top of my head I can't see any other heuristic that could avoid the false positive in this case. With an "AI" we could see there is a common pattern and avoid the warnings. The motivation for the warnings are that there could be a mistake and if there is similar code in >10 places then it's more likely by intention.
Your fix is reasonable but I assume the compiler could do that optimisation.
Since this is 1 project I think it's ok if the conclusion is that they must suppress. However if we could have seen some possible heuristic that would be better. :-(
Last edit: Daniel Marjamäki 2020-09-25
When I looked at the daca@home results for duplicateAssignExpressions yesterday I did not feel that the noise ratio was very good.