Skip to content

Fix issue 9103: False positive duplicateConditionAssign - #1808

Merged
danmar merged 3 commits into
cppcheck-opensource:masterfrom
pfultz2:fp-duplicate-cond-assign
Apr 26, 2019
Merged

danmar merged 3 commits into
cppcheck-opensource:masterfrom
pfultz2:fp-duplicate-cond-assign

Conversation

@pfultz2

@pfultz2 pfultz2 commented Apr 25, 2019

Copy link
Copy Markdown
Collaborator

No description provided.

@danmar

danmar commented Apr 25, 2019 •

Copy link
Copy Markdown
Collaborator

I would like to see some kind of clarification of the error message also.

Just a suggestion; the current message does not really say what the problem is. Say something about the fundamental reason why we added this warning. In my humble opinion the message Duplicate expression for the condition and assignment focus on how we detect this stylistic issue not what the stylistic issue really is.

But well.. feel free to figure out some clarification and then we can ask orbitcowboy if he thinks that is good.

@pfultz2

pfultz2 commented Apr 25, 2019

Copy link
Copy Markdown
Collaborator Author

I would like to see some kind of clarification of the error message also.

We can say something like: if (x != y) x = y is logically the same as x = y. Would that be enough?

@danmar

danmar commented Apr 26, 2019

Copy link
Copy Markdown
Collaborator

We can say something like: if (x != y) x = y is logically the same as x = y. Would that be enough?

That sounds good to me. @orbitcowboy what do you think about this suggestion?

@orbitcowboy

Copy link
Copy Markdown
Collaborator

We can say something like: if (x != y) x = y is logically the same as x = y. Would that be enough?

That sounds good to me. @orbitcowboy what do you think about this suggestion?

Lgtm. Thanks!

@amai2012

amai2012 commented Apr 26, 2019 •

Copy link
Copy Markdown
Collaborator

Well, that is not exactly true for complex types, is it?

@amai2012

Copy link
Copy Markdown
Collaborator
void foo(A& x, A&y)
{
  if (x!=y)
     x=y;

Here the assignment might be much more expensive than the comparison.

@danmar

danmar commented Apr 26, 2019

Copy link
Copy Markdown
Collaborator

Well, that is not exactly true for complex types, is it?

If there is some code that is better to not rewrite.. then please report it as FP.

@danmar
danmar merged commit c4325bb into cppcheck-opensource:master Apr 26, 2019
@pfultz2
pfultz2 deleted the fp-duplicate-cond-assign branch May 19, 2019 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants