-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve fix for #9570: check if ternary operator is used in assignment to reference #3614
Conversation
It would be better to just check |
Thanks, I'll try that. This is all the comments I could find on
|
Using
|
Yea that part is little confusing. Originally, this only worked for variables but now you can pass arbitrary expressions to it. We should probably rename it to
You can use the
Yea that is to check over a range of tokens, but it wont be useful for this. |
The "variable" is determined to be conclusively changed at https://github.com/danmar/cppcheck/blob/main/lib/astutils.cpp#L2188 |
Ah thats right, this doesn't let you know if it was inconclusive or not. In ValueFlow, we call
Yes, or rather it could modify the result.
Yea when
Yea that doesn't seem related. |
I'm getting confused here. For the test case #6426,
Shouldn't this be "return false"? What exactly gets changed in this case? |
sounds like a good idea 👍 |
|
So
Yea, I just wonder how common such a case is, especially after fixing the ValueFlow issue with globals/static variables. It seems odd to compare the address of global variables that are never modified that is picked among global variables that have the same value. |
Yes, sorry was a typo. |
I am not against it in theory. But could that lead to lots of false positives? I don't know if we've set a noise target for inconclusive but if we make this change and 99% of the new warnings are false positives then we should let it be as it is. |
The FPs should be handled by the checks and ValueFlow analysis. |
it sounds ok to me. |
I have checked again, and
It's probably an edge case. Although global variables might be changed where cppcheck can't see it, or they might be |
Yes, and that is something that should be fixed in ValueFlow. We should only set the values to Known when we know conclusively the value can't be changed. |
The CI failure has to do with regexes in matchcompiler.py, which is unrelated to this PR. |
@pfultz2 if you approve this, I think it can be merged. |
Not strictly related to this PR, but anyway: |
So that was added here, but this was before we used this function for arbitrary expressions. It probably needs to be updated, as I think its assuming its just a variable passed by reference. Maybe we can open an issue to track this. |
I haven't been able to come up with an example that hinges on |
No description provided.