Fixed #8710 (Update message duplicateExpression when operand is integer literal)

This commit is contained in:
Daniel Marjamäki 2018-08-30 18:28:34 +02:00
parent 27aae8d032
commit 7591616f43
2 changed files with 10 additions and 10 deletions

View File

@ -2065,10 +2065,10 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
msg = exprMsg + "true";
else if (Token::Match(opTok, "!=|>|<"))
msg = exprMsg + "false";
msg += " because '" + expr1 + "' and '" + expr2 + "' represent the same value";
if (!Token::Match(tok1, "%num%|NULL|nullptr") && !Token::Match(tok2, "%num%|NULL|nullptr"))
msg += " because '" + expr1 + "' and '" + expr2 + "' represent the same value";
}
reportError(errors, Severity::style, "duplicateExpression", msg + ".\n"
"Finding the same expression on both sides of an operator is suspicious and might "
"indicate a cut and paste or logic error. Please examine this code carefully to "

View File

@ -3931,7 +3931,7 @@ 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 because 'a' and '1' represent the same value.\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"
@ -3954,7 +3954,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 because 'a' and '1' represent the same value.\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");
ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The expression 'a != 1' is always false because 'a' and '1' represent the same value.\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");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false because 'a' and '1' represent the same value.\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");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'a != 1' is always false because 'a' and '1' represent the same value.\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"
@ -4082,7 +4082,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 because 'a' and '1' represent the same value.\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());
@ -4098,7 +4098,7 @@ private:
" if( i != 0 ) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The expression 'i != 0' is always false because 'i' and '0' represent the same value.\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"
@ -4139,7 +4139,7 @@ private:
" b++;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The expression 'a != 1' is always false because 'a' and '1' represent the same value.\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