Temporarily comment out the followVariable() handling
This commit is contained in:
parent
29d7872440
commit
afe09f4d7a
|
@ -133,6 +133,7 @@ const Token * astIsVariableComparison(const Token *tok, const std::string &comp,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
static const Token * getVariableInitExpression(const Variable * var)
|
||||
{
|
||||
if (!var || !var->declEndToken())
|
||||
|
@ -245,7 +246,7 @@ static void followVariableExpressionError(const Token *tok1, const Token *tok2,
|
|||
return;
|
||||
errors->push_back(item);
|
||||
}
|
||||
|
||||
*/
|
||||
bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, ErrorPath* errors)
|
||||
{
|
||||
if (tok1 == nullptr && tok2 == nullptr)
|
||||
|
@ -266,6 +267,8 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
return isSameExpression(cpp, macro, tok1, tok2->astOperand1()->astOperand1(), library, pure, errors);
|
||||
}
|
||||
if (tok1->str() != tok2->str() && (Token::Match(tok1, "%var%") || Token::Match(tok2, "%var%"))) {
|
||||
// TODO this code is temporarily commented out because there are false positives. See #8717, #8744, #8775.
|
||||
/*
|
||||
const Token * varTok1 = followVariableExpression(tok1, cpp, tok2);
|
||||
if (varTok1->str() == tok2->str()) {
|
||||
followVariableExpressionError(tok1, varTok1, errors);
|
||||
|
@ -281,6 +284,7 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
followVariableExpressionError(tok2, varTok2, errors);
|
||||
return isSameExpression(cpp, macro, varTok1, varTok2, library, true, errors);
|
||||
}
|
||||
*/
|
||||
}
|
||||
if (tok1->varId() != tok2->varId() || tok1->str() != tok2->str() || tok1->originalName() != tok2->originalName()) {
|
||||
if ((Token::Match(tok1,"<|>") && Token::Match(tok2,"<|>")) ||
|
||||
|
|
|
@ -1246,7 +1246,7 @@ private:
|
|||
" if (a > x && a < y)\n"
|
||||
" return;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:8]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str());
|
||||
|
||||
check("struct A {\n"
|
||||
" void f();\n"
|
||||
|
@ -1276,7 +1276,7 @@ private:
|
|||
" if (a > x && a < y)\n"
|
||||
" return;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:5]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str());
|
||||
}
|
||||
|
||||
void secondAlwaysTrueFalseWhenFirstTrueError() {
|
||||
|
@ -1601,7 +1601,7 @@ private:
|
|||
" if(!b) {}\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str());
|
||||
|
||||
check("void foo(unsigned u) {\n"
|
||||
" if (u != 0) {\n"
|
||||
|
@ -2538,7 +2538,8 @@ private:
|
|||
" if (val < 0) continue;\n"
|
||||
" if (val > 0) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'val<0' is always false\n"
|
||||
"[test.cpp:4]: (style) Condition 'val>0' is always false\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int val = 0;\n"
|
||||
|
@ -2546,7 +2547,7 @@ private:
|
|||
" if (val > 0) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'val<0' is always false\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int val = 0;\n"
|
||||
|
@ -2554,7 +2555,7 @@ private:
|
|||
" if (val < 0) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'val<0' is always false\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int activate = 0;\n"
|
||||
|
|
|
@ -3917,13 +3917,13 @@ private:
|
|||
" const int i = sizeof(int);\n"
|
||||
" if ( i != sizeof (int)){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" const int i = sizeof(int);\n"
|
||||
" if ( sizeof (int) != i){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value.\n", errout.str());
|
||||
|
||||
check("void f(int a = 1) { if ( a != 1){}}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -3932,21 +3932,21 @@ private:
|
|||
" int a = 1;\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int a = 1;\n"
|
||||
" int b = 1;\n"
|
||||
" if ( a != b){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int a = 1;\n"
|
||||
" int b = a;\n"
|
||||
" if ( a != b){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str());
|
||||
|
||||
check("void use(int);\n"
|
||||
"void f() {\n"
|
||||
|
@ -3955,7 +3955,7 @@ private:
|
|||
" use(b);\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("void use(int);\n"
|
||||
"void f() {\n"
|
||||
|
@ -3979,7 +3979,7 @@ private:
|
|||
" void f() {\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("int a = 1;\n"
|
||||
" void f() {\n"
|
||||
|
@ -3991,7 +3991,7 @@ private:
|
|||
" static const int a = 1;\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" static int a = 1;\n"
|
||||
|
@ -4004,7 +4004,7 @@ private:
|
|||
" if ( a != 1){\n"
|
||||
" a++;\n"
|
||||
" }}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("void f(int b) {\n"
|
||||
" int a = 1;\n"
|
||||
|
@ -4087,7 +4087,7 @@ private:
|
|||
" int a = 1;\n"
|
||||
" while ( a != 1){}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
|
||||
check("void f() { int a = 1; while ( a != 1){ a++; }}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -4103,7 +4103,7 @@ private:
|
|||
" if( i != 0 ) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'i != 0' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'i != 0' is always false.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" for(int i = 0; i < 10;) {\n"
|
||||
|
@ -4144,7 +4144,7 @@ private:
|
|||
" b++;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != 1' is always false.\n", errout.str());
|
||||
}
|
||||
|
||||
void duplicateExpressionTernary() { // #6391
|
||||
|
@ -4623,8 +4623,8 @@ private:
|
|||
" if (val < 0) continue;\n"
|
||||
" if ((val > 0)) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
"[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val > 0' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
// "[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val > 0' is always false.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int val = 0;\n"
|
||||
|
@ -4632,8 +4632,8 @@ private:
|
|||
" if ((val > 0)) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
"[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val > 0' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
// "[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val > 0' is always false.\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" int val = 0;\n"
|
||||
|
@ -4641,8 +4641,9 @@ private:
|
|||
" if ((val < 0)) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
"[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val < 0' is always false.\n", errout.str());
|
||||
//ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'val < 0' is always false.\n"
|
||||
// "[test.cpp:2] -> [test.cpp:4]: (style) The expression 'val < 0' is always false.\n", errout.str());
|
||||
|
||||
|
||||
check("void f() {\n"
|
||||
" int activate = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue