From c025bf9d57ae94027889f7efeb87cc068446b0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 19 Nov 2011 08:38:54 +0100 Subject: [PATCH] Fixed #3332 (mismatching comparison: Hard to understand) --- lib/checkassignif.cpp | 6 +++++- test/testassignif.cpp | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/checkassignif.cpp b/lib/checkassignif.cpp index 7e2062d2c..fcf1f0273 100644 --- a/lib/checkassignif.cpp +++ b/lib/checkassignif.cpp @@ -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); } diff --git a/test/testassignif.cpp b/test/testassignif.cpp index a8ab3a419..aee94dafd 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -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() {