I'm trying to get cppcheck 1.68 to warn on case statements without a dedicated break or fall through comment.
When I add the --experimental argument I get: cppcheck: error: unrecognized command line option: "--experimental". Has it been deprecated? Is there a replacement?
Thanks,
Aleks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I could have sworn it was in an earlier version... maybe I confused it with something else.
I know the functionality is there, and it's even in the test cases, take a look at https://github.com/danmar/cppcheck/blob/master/test/testother.cpp and see switchFallThroughCase
I would love to have this in cppcheck, 95% of the bugs in my code seem to stem from missing breaks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't want to have any FP here in this general case:
switch (x) {
case 1:
foo();
case 2:
bar();
};
With the checker switchFallThroughCase a comment must be added to suppress the warning. I don't like that. I think it's a bad idea that comments or annotations must be used to silence all FP.
I would love to detect more unintentional switch case fallthrough. If you have some good ideas how we can do it feel free to write a suggestion.
As an inspiration, we warn if a fall through results in useless code. For example the assignment "y = 1;" is useless here:
switch (x) {
case 1:
y = 1;
case 2:
y = 7;
break;
}
I'm trying to get cppcheck 1.68 to warn on case statements without a dedicated break or fall through comment.
When I add the --experimental argument I get: cppcheck: error: unrecognized command line option: "--experimental". Has it been deprecated? Is there a replacement?
Thanks,
Aleks
ehm.. as far as I know we haven't had a "--experimental" flag. But maybe I'm wrong.
I don't want to have that warning in cppcheck. I guess we should remove it.
I really like to warn about unintentional missing breaks. But Cppcheck does it without looking at comments/annotations.
I don't know if it helps you.. but clang has this warning.
Last edit: Daniel Marjamäki 2015-01-16
I could have sworn it was in an earlier version... maybe I confused it with something else.
I know the functionality is there, and it's even in the test cases, take a look at https://github.com/danmar/cppcheck/blob/master/test/testother.cpp and see switchFallThroughCase
I would love to have this in cppcheck, 95% of the bugs in my code seem to stem from missing breaks.
I don't want to have any FP here in this general case:
With the checker switchFallThroughCase a comment must be added to suppress the warning. I don't like that. I think it's a bad idea that comments or annotations must be used to silence all FP.
I would love to detect more unintentional switch case fallthrough. If you have some good ideas how we can do it feel free to write a suggestion.
As an inspiration, we warn if a fall through results in useless code. For example the assignment "y = 1;" is useless here:
If you check that code you'll get this warning:
Last edit: Daniel Marjamäki 2015-01-19