From e8eeb90adbc051ae2d746cadc3108bf0965f9fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 20 Nov 2013 16:18:09 +0100 Subject: [PATCH] AST: Fixed 'same expression' false positives (git merge --squash s, <<, >>) --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2a2d4c515..2b4a4828a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3378,12 +3378,12 @@ void CheckOther::checkDuplicateExpression() // Experimental implementation 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())) continue; if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions)) duplicateExpressionError(tok, tok, tok->str()); - else if (tok->astOperand1() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), constStandardFunctions)) + else if (tok->astOperand1() && tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), constStandardFunctions)) duplicateExpressionError(tok->astOperand2(), tok->astOperand2(), tok->str()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 23b3edf9d..03a13b542 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4812,6 +4812,14 @@ private: " if (a / 1000 / 1000) {}\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " if (a << 1 << 1) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("int f() { return !!y; }"); // No FP + ASSERT_EQUALS("", errout.str()); } void duplicateIf1() { // ticket 3689 ( avoid false positive )