Repository navigation
Fix #15023 FN redundantInitialization with braces or parentheses - #8846
chrchr-github wants to merge 8 commits into
Conversation
| if (tok->isCpp() && tok->astOperand1()->valueType()) { | ||
| // If there is a custom assignment operator => this is inconclusive | ||
| if (tok->astOperand1()->valueType()->typeScope) { | ||
| const std::string op = "operator" + tok->str(); |
There was a problem hiding this comment.
This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.
For the new ( / { initialization forms, tok->str() is ( or {, so this looks for operator( / operator{ and the custom-assignment-operator check never triggers. Result with this PR:
int g();
struct A { A(int); A& operator=(int); A& operator=(const A&); };
void f1() { A a(g()); a = 1; } // redundantInitialization (conclusive)
void f2() { A a = g(); a = 1; } // redundantInitialization (inconclusive)I'd expect both to be inconclusive. What matters is the later a = 1, so maybe:
| const std::string op = "operator" + tok->str(); | |
| const std::string op = isInitialization && Token::Match(tok, "[{(]") ? "operator=" : "operator" + tok->str(); |
With that, f1 becomes inconclusive like f2, P p{ g(), g() }; p = P{1, 2}; for a plain struct is still reported conclusively, and TestOther passes.
FYI, this PR and #8847 restructure the same block in checkRedundantAssignment(), so whichever is merged second will need a rebase.
There was a problem hiding this comment.
"operator" + tok->str();should always be"operator="- the inconclusive logic is flawed already, there is a conclusive warning for
S f() { S s = g(); s = 1; return s; }
|
Test results for commit 74b9be3 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8846/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
danmar
left a comment
There was a problem hiding this comment.
lgtm. I assume you have rejected the AI review? Then feel free to merge.
Best viewed with whitespace changes hidden.