AssignIf: Improved the error message for mismatching comparison
This commit is contained in:
parent
bc4db75aa9
commit
880e0e3b5f
|
@ -121,7 +121,14 @@ void CheckAssignIf::comparison()
|
||||||
|
|
||||||
void CheckAssignIf::comparisonError(const Token *tok, bool result)
|
void CheckAssignIf::comparisonError(const Token *tok, bool result)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::style,
|
std::string errmsg("Mismatching comparison, the result is always " + std::string(result ? "true" : "false") + "\n"
|
||||||
"comparisonError",
|
"Mismatching comparison. This error message is for example given for such a comparison: ");
|
||||||
"Comparison is always " + std::string(result ? "true" : "false"));
|
|
||||||
|
if (result)
|
||||||
|
errmsg += "'(x & 6 != 1)'. The result of 'x & 6' can't be 1 so the result of the comparison is always true";
|
||||||
|
else
|
||||||
|
errmsg += "'(x & 6 == 1)'. The result of 'x & 6' can't be 1 so the result of the comparison is always false";
|
||||||
|
|
||||||
|
|
||||||
|
reportError(tok, Severity::style, "comparisonError", errmsg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,19 +83,19 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (x & 4 == 3);\n"
|
" if (x & 4 == 3);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Comparison is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Mismatching comparison, the result 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) Comparison is always false\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Mismatching comparison, the result 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) Comparison is always true\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Mismatching comparison, the result is always true\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue