Fix CheckClass::operatorEqToSelf#3088
Conversation
|
Fix CheckClass::operatorEqToSelf false negative cases. |
| return res; | ||
| } | ||
|
|
||
| const Token * CheckClass::getScopeStartToken(const Token *tok) |
There was a problem hiding this comment.
hmm .. this is a strange name. With this name I would have thought it worked like tok->scope()->bodyStart.
I guess I'd prefer that you use tok->astTop() instead of a for loop. I assume that we only are interested in the top.
Then instead of such condition: itr->link()->next() && itr->link()->next()->str() == "{" I'd prefer Token::simpleMatch(itr->link(), ") {"). That is more explicit and also avoid extra calls for link() and next().
There was a problem hiding this comment.
I think the name is strange but do not have a suggestion right now.. feel free to suggest a name that is more specific.
| if (itr->str() == "!=" && (itr->astOperand1()->str() == "true" || itr->astOperand2()->str() == "true")) { | ||
| res = !res; | ||
| } | ||
| else if (itr->str() == "!=" && (itr->astOperand1()->str() != "false" && itr->astOperand2()->str() != "false")) { |
There was a problem hiding this comment.
In general I prefer that we use valueflow instead of hardcoded constants. A false token has the known integer value 0..
(... astOperand1()->hasKnownIntValue() && .. astOperand1()->getKnownIntValue() != 0 )
.. and a true token has the value 1 ..
| } | ||
|
|
||
| bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) | ||
| bool CheckClass::isInverseAssignmentTest(const Token *tok) |
There was a problem hiding this comment.
hmm.. spontaneously I have the feeling this has some overlap for what we want to achieve with astIsVariableComparison. maybe I am wrong.
There was a problem hiding this comment.
isInverseAssignmentTest checks if a self-assignment test is inverse.
For example, for if (this == &rhs) and if (!(this != &rhs)) the function will return true, and for
if (this != &rhs) it will return false.
Can I achieve this with astIsVariableComparison?
There was a problem hiding this comment.
hmm.. you can implement this for now.
And then I can try to see if some refactoring / improvements can be made later.
There was a problem hiding this comment.
I think a name that explains what the function do is better than a name that explains when it is used. The "Assignment" has nothing to do with the functionality of the function.
Something like isInverted or something like that will work for me..
Maybe we should also consider that in practice the result is not false/true but false/maybe/true.
if (foo && this == &rhs)
The address of rhs may or may not be this when this condition is true/false.
If the result is "maybe" it's better to bailout and don't write warnings if that can avoid false positives.
|
sorry I forgot this PR. If you don't get a review in 1-2 days.. feel free to ping me. you can write @danmar in a comment. |
danmar
left a comment
There was a problem hiding this comment.
Thanks for working on this! I think it looks promising, but I have more nits.
| return false; | ||
| } | ||
|
|
||
| bool CheckClass::isTrueKeyword(const Token* tok) |
There was a problem hiding this comment.
I'd prefer that this was a local function. Not part of CheckClass. No need to declare it in the header.
| } | ||
|
|
||
| const Token * CheckClass::getScopeStartToken(const Token *tok) | ||
| const Token * CheckClass::getIfStmtScopeStart(const Token *tok) |
There was a problem hiding this comment.
this name is better. but I'd suggest getIfStmtBodyStart.
| } | ||
|
|
||
| bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) | ||
| bool CheckClass::isInverseAssignmentTest(const Token *tok) |
There was a problem hiding this comment.
hmm.. you can implement this for now.
And then I can try to see if some refactoring / improvements can be made later.
| } | ||
|
|
||
| bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs) | ||
| bool CheckClass::isInverseAssignmentTest(const Token *tok) |
There was a problem hiding this comment.
I think a name that explains what the function do is better than a name that explains when it is used. The "Assignment" has nothing to do with the functionality of the function.
Something like isInverted or something like that will work for me..
Maybe we should also consider that in practice the result is not false/true but false/maybe/true.
if (foo && this == &rhs)
The address of rhs may or may not be this when this condition is true/false.
If the result is "maybe" it's better to bailout and don't write warnings if that can avoid false positives.
|
@danmar ping |
|
I would like to add your name in our AUTHORS. What name would you like that I add? |
|
Alon Liberman
Thanks :)
…On Tue, Feb 2, 2021 at 4:02 PM Daniel Marjamäki ***@***.***> wrote:
I would like to add your name in our AUTHORS. What name would you like
that I add?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3088 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKE5AEIS6DFQEZ7X5A5BVF3S5AAYVANCNFSM4WUB6HQA>
.
|
…r union member is never used" for structs with __attribute__((packed)) or #pragma pack(push))
No description provided.