From c9e239afbf33ba2c593e954fc7a7db17091f2c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 7 Aug 2015 20:28:25 +0200 Subject: [PATCH] Fixed #6908 (False positive: Same expression on both sides of '+='.) --- lib/checkother.cpp | 2 +- test/testother.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 6024567a2..40213e1a8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2025,7 +2025,7 @@ void CheckOther::checkDuplicateExpression() continue; for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { - if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>")) { + if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>|+=|*=|<<=|>>=")) { if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1(), true)) continue; if (isSameExpression(_tokenizer->isCPP(), tok->astOperand1(), tok->astOperand2(), _settings->library.functionpure)) { diff --git a/test/testother.cpp b/test/testother.cpp index e08d67a79..9abcc067a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4137,6 +4137,9 @@ private: check("int f(int x) { return x+x; }"); ASSERT_EQUALS("", errout.str()); + check("void f(int x) { while (x+=x) ; }"); + ASSERT_EQUALS("", errout.str()); + check("void foo() {\n" " if (a && b && b) {}\n" "}");