Fix issue 7904: Handle double nots in isSameExpression (#1305)
* Fix issue 7904: Handle double nots in isSameExpression * Skip checking double nots in assignments * Use ast to check for double not
This commit is contained in:
parent
60485df762
commit
5d1fdf7958
|
@ -145,6 +145,12 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
if (tok2->str() == "." && tok2->astOperand1() && tok2->astOperand1()->str() == "this")
|
||||
tok2 = tok2->astOperand2();
|
||||
}
|
||||
if(Token::simpleMatch(tok1, "!") && Token::simpleMatch(tok1->astOperand1(), "!") && !Token::simpleMatch(tok1->astParent(), "=")) {
|
||||
return isSameExpression(cpp, macro, tok1->astOperand1()->astOperand1(), tok2, library, pure);
|
||||
}
|
||||
if(Token::simpleMatch(tok2, "!") && Token::simpleMatch(tok2->astOperand1(), "!") && !Token::simpleMatch(tok2->astParent(), "=")) {
|
||||
return isSameExpression(cpp, macro, tok1, tok2->astOperand1()->astOperand1(), library, pure);
|
||||
}
|
||||
if (tok1->varId() != tok2->varId() || tok1->str() != tok2->str() || tok1->originalName() != tok2->originalName()) {
|
||||
if ((Token::Match(tok1,"<|>") && Token::Match(tok2,"<|>")) ||
|
||||
(Token::Match(tok1,"<=|>=") && Token::Match(tok2,"<=|>="))) {
|
||||
|
|
|
@ -630,6 +630,42 @@ private:
|
|||
" else if (x & 0x08) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( !!b && !!a){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( !!b && a){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( b && !!a){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( b && !(!a)){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( !!b && !(!a)){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||
|
||||
check("void f(bool a, bool b) {\n"
|
||||
" if(a && b){}\n"
|
||||
" else if( !!(b) && !!(a+b)){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkBadBitmaskCheck() {
|
||||
|
|
|
@ -3009,6 +3009,9 @@ private:
|
|||
"[test.cpp:10]: (warning) Redundant assignment of 'y' to itself.\n"
|
||||
"[test.cpp:10]: (warning) Redundant assignment of 'z' to itself.\n", errout.str());
|
||||
|
||||
check("void f(int i) { i = !!i; }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void trac1132() {
|
||||
|
|
Loading…
Reference in New Issue