cppcheck
cppcheck copied to clipboard
Fix false positive struct member is never used
Oh ok. I'll try to do that then ;-)
I ended up with https://github.com/danmar/cppcheck/commit/6ce4b2bd6caf52210e81f70b1d4cd233ee11e8e7, but I feel like it would be easier to remove the parentheses in the simplification. Maybe simplifyRedundantConsecutiveBraces is enough, or maybe doing it in the handling of "->" in Tokenizer::combineOperators. I'm afraid that not simplifying it would make checks more difficult.
Edit: besides, the code to handle parentheses is fragile (the commit above broke (foo[1]).x = 123), and there literally can be parentheses everywhere... It really feels better to simply remove the redundant parentheses.
Edit bis: that being said, it looks like there are some other issues in createSymbolDatabaseSetVariablePointers, I'll see if I can find the time to debug it. Maybe rewriting it to use the ast instead of parsing the code directly will do the trick.
Typically, with master and the following, the member a is reported as unused:
struct A {
int a;
};
#define dAa(ptr) (((ptr))->a)
void f(A p[]) {
int i=0;
if (32 == dAa(&p[i])) {
}
if (dAa(&p[i])) {
}
if ((&p[i])->a) {
}
}
Maybe rewriting it to use the ast instead of parsing the code directly will do the trick.
imho that sounds like a better approach but I understand it's not a quick fix.
sooner or later the simplification can bite us. for instance if we would like to write a check for misplaced/redundant parentheses.
Indeed. This looks better, but I have at least one FP on the codebase where I work.
We also have astParentSkipParens to skip parenthesis when traversing the ast.
On the topic of parentheses, not sure if this is related:
The token list currently does not contain the double parentheses in foo((x = 1, x = x + 1)); from https://trac.cppcheck.net/ticket/8215