to avoid false positives, we do not warn about stylistic issues if it seems to be by intention. in your code it looks intentional that the condition is false.
Try something like if (x==0) when the value of x must be 0. for instance you may have assigned x to 0 before the condition. or the code is placed in a conditional scope that is only executed if x is 0.
Last edit: Daniel Marjamäki 2021-09-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But why not give the user the option if he/she wants to have a warning or not (suppress), even if the unreachable code was made intentionally.
For example, for testing purposes I did intentionally changed operational code from if (1) to if (0), BUT forgot to undo the change after the testing, and only found out months later!!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Can't cppcheck warn me about "unreachable code" in a if (0) statement, for instance:
to avoid false positives, we do not warn about stylistic issues if it seems to be by intention. in your code it looks intentional that the condition is false.
Try something like
if (x==0)
when the value of x must be 0. for instance you may have assigned x to 0 before the condition. or the code is placed in a conditional scope that is only executed if x is 0.Last edit: Daniel Marjamäki 2021-09-01
But why not give the user the option if he/she wants to have a warning or not (suppress), even if the unreachable code was made intentionally.
For example, for testing purposes I did intentionally changed operational code from if (1) to if (0), BUT forgot to undo the change after the testing, and only found out months later!!!!
I don't want to have such option in cppcheck I believe we skip the warning for good reasons to avoid noise.
But an addon can be created quite easily that would write this warning. I feel that it can be added in cppcheck repo and distributed with cppcheck.
Last edit: Daniel Marjamäki 2021-09-06