Fixed #3332 (mismatching comparison: Hard to understand)
This commit is contained in:
parent
fa34a14d57
commit
c025bf9d57
|
@ -117,7 +117,11 @@ void CheckAssignIf::comparisonError(const Token *tok, int value1, const std::str
|
||||||
std::ostringstream expression;
|
std::ostringstream expression;
|
||||||
expression << std::hex << "(X & 0x" << value1 << ") " << op << " 0x" << value2;
|
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);
|
reportError(tok, Severity::style, "comparisonError", errmsg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,19 +94,19 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 == 3);\n"
|
" if (x & 4 == 3);\n"
|
||||||
"}\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"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if ((x & 4) == 3);\n"
|
" if ((x & 4) == 3);\n"
|
||||||
"}\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"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 != 3);\n"
|
" if (x & 4 != 3);\n"
|
||||||
"}\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() {
|
void multicompare() {
|
||||||
|
|
Loading…
Reference in New Issue