From e5ff920ea9817db4c4feb61cd1f7d8a263badfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 19 Aug 2011 00:56:15 +0200 Subject: [PATCH] Suspicious condition: Better handling when rhs is non-numeric --- lib/checkother.cpp | 2 +- test/testother.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bf25276f7..89a67dc75 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -152,7 +152,7 @@ void CheckOther::clarifyCondition() tok2 = tok2->link(); else if (Token::Match(tok2, "&&|%oror%|?|)")) break; - else if (Token::Match(tok2, "<|<=|==|!=|>|>= %num% )")) + else if (Token::Match(tok2, "<|<=|==|!=|>|>=")) { clarifyConditionError(tok, tok->strAt(2) == "="); break; diff --git a/test/testother.cpp b/test/testother.cpp index a9de95018..3f02f717f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2639,6 +2639,11 @@ private: " if (x & 2 == 2) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str()); + + check("void f() {\n" + " if (a & fred1.x == fred2.y) {}\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison), it can be clarified with parentheses\n", errout.str()); } void incorrectStringCompare()