parent
c6d43506b6
commit
08f301a0de
|
@ -133,7 +133,6 @@ const Token * astIsVariableComparison(const Token *tok, const std::string &comp,
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
static const Token * getVariableInitExpression(const Variable * var)
|
||||
{
|
||||
if (!var || !var->declEndToken())
|
||||
|
@ -166,7 +165,7 @@ static const Token * followVariableExpression(const Token * tok, bool cpp)
|
|||
if (Token::Match(tok->astTop(), "%assign%") || Token::Match(tok->next(), "%assign%"))
|
||||
return tok;
|
||||
// Skip references
|
||||
if (Token::Match(tok->astTop(), "& %var%;") && Token::Match(tok->astTop()->astOperand1(), "%type%"))
|
||||
if (Token::Match(tok->astTop(), "& %var% ;") && Token::Match(tok->astTop()->astOperand1(), "%type%"))
|
||||
return tok;
|
||||
const Variable * var = tok->variable();
|
||||
const Token * varTok = getVariableInitExpression(var);
|
||||
|
@ -231,7 +230,6 @@ 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)
|
||||
{
|
||||
|
@ -252,10 +250,6 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
if (Token::simpleMatch(tok2, "!") && Token::simpleMatch(tok2->astOperand1(), "!") && !Token::simpleMatch(tok2->astParent(), "=")) {
|
||||
return isSameExpression(cpp, macro, tok1, tok2->astOperand1()->astOperand1(), library, pure, errors);
|
||||
}
|
||||
// Follow variables if possible
|
||||
// DM: followVariableExpression is disabled for now because it cause problems.
|
||||
// See #8709, #8713, #8717 and #8722
|
||||
/*
|
||||
if (tok1->str() != tok2->str() && (Token::Match(tok1, "%var%") || Token::Match(tok2, "%var%"))) {
|
||||
const Token * varTok1 = followVariableExpression(tok1, cpp);
|
||||
if (varTok1->str() == tok2->str()) {
|
||||
|
@ -273,7 +267,6 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
|||
return isSameExpression(cpp, macro, varTok1, varTok2, library, pure, errors);
|
||||
}
|
||||
}
|
||||
*/
|
||||
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,"<=|>="))) {
|
||||
|
|
|
@ -1245,7 +1245,7 @@ private:
|
|||
" if (a > x && a < y)\n"
|
||||
" return;\n"
|
||||
"}\n");
|
||||
TODO_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"
|
||||
|
@ -1275,7 +1275,7 @@ private:
|
|||
" if (a > x && a < y)\n"
|
||||
" return;\n"
|
||||
"}\n");
|
||||
TODO_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() {
|
||||
|
@ -1600,7 +1600,7 @@ private:
|
|||
" if(!b) {}\n"
|
||||
" }\n"
|
||||
"}");
|
||||
TODO_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"
|
||||
|
|
|
@ -3916,13 +3916,13 @@ private:
|
|||
" const int i = sizeof(int);\n"
|
||||
" if ( i != sizeof (int)){}\n"
|
||||
"}\n");
|
||||
TODO_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");
|
||||
TODO_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());
|
||||
|
@ -3931,21 +3931,21 @@ private:
|
|||
" int a = 1;\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
TODO_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");
|
||||
TODO_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");
|
||||
TODO_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"
|
||||
|
@ -3954,7 +3954,7 @@ private:
|
|||
" use(b);\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
TODO_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"
|
||||
|
@ -3978,7 +3978,7 @@ private:
|
|||
" void f() {\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
TODO_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"
|
||||
|
@ -3990,7 +3990,7 @@ private:
|
|||
" static const int a = 1;\n"
|
||||
" if ( a != 1){} \n"
|
||||
"}\n");
|
||||
TODO_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"
|
||||
|
@ -4003,7 +4003,7 @@ private:
|
|||
" if ( a != 1){\n"
|
||||
" a++;\n"
|
||||
" }}\n");
|
||||
TODO_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"
|
||||
|
@ -4086,7 +4086,7 @@ private:
|
|||
" int a = 1;\n"
|
||||
" while ( a != 1){}\n"
|
||||
"}\n");
|
||||
TODO_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());
|
||||
|
@ -4102,7 +4102,7 @@ private:
|
|||
" if( i != 0 ) {}\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
TODO_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"
|
||||
|
@ -4143,7 +4143,7 @@ private:
|
|||
" b++;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
TODO_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
|
||||
|
|
Loading…
Reference in New Issue