Merge branch 'master' of github.com:danmar/cppcheck

This commit is contained in:
Edoardo Prezioso 2011-11-19 13:36:05 +01:00
commit c3b54066bd
2 changed files with 8 additions and 4 deletions

View File

@ -117,7 +117,11 @@ void CheckAssignIf::comparisonError(const Token *tok, int value1, const std::str
std::ostringstream expression;
expression << std::hex << "(X & 0x" << value1 << ") " << op << " 0x" << value2;
const std::string errmsg("Expression '" + expression.str() + "' is always " + (result?"true":"false") + ". Look again at the constants.");
const std::string errmsg("Expression '" + expression.str() + "' is always " + (result?"true":"false") + "\n"
"The expression '" + expression.str() + "' is always " + (result?"true":"false") +
". Check carefully constants and operators used, these errors might be hard to "
"spot sometimes. In case of complex expression it might help to split it to "
"separate expressions.");
reportError(tok, Severity::style, "comparisonError", errmsg);
}

View File

@ -94,19 +94,19 @@ private:
"{\n"
" if (x & 4 == 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false. Look again at the constants.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false\n", errout.str());
check("void foo(int x)\n"
"{\n"
" if ((x & 4) == 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false. Look again at the constants.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false\n", errout.str());
check("void foo(int x)\n"
"{\n"
" if (x & 4 != 3);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) != 0x3' is always true. Look again at the constants.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) != 0x3' is always true\n", errout.str());
}
void multicompare() {