From b2ea78543b3e27bad0cab3d7d9c18d014501a110 Mon Sep 17 00:00:00 2001 From: Richard Quirk Date: Thu, 1 Dec 2011 19:49:04 +0100 Subject: [PATCH] Fix false positive with non-const function calls --- lib/checkother.cpp | 11 +++++++++-- test/testother.cpp | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 222a97be2..6a3a15caf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2444,6 +2444,7 @@ namespace { Expressions(const SymbolDatabase *symbolDatabase, const std::list &constFunctions) : _start(0), + _lastTokens(0), _symbolDatabase(symbolDatabase), _constFunctions(constFunctions) { } @@ -2451,13 +2452,18 @@ namespace { const std::string &e = _expression.str(); if (!e.empty()) { std::map::iterator it = _expressions.find(e); + bool lastInconclusive = _lastTokens && _lastTokens->inconclusiveFunction; if (it == _expressions.end()) { ExpressionTokens exprTokens(_start, end); - exprTokens.inconclusiveFunction = inconclusiveFunctionCall( + exprTokens.inconclusiveFunction = lastInconclusive || inconclusiveFunctionCall( _symbolDatabase, _constFunctions, exprTokens); _expressions.insert(std::make_pair(e, exprTokens)); + _lastTokens = &_expressions.find(e)->second; } else { - it->second.count += 1; + ExpressionTokens &expr = it->second; + expr.count += 1; + expr.inconclusiveFunction = expr.inconclusiveFunction || lastInconclusive; + _lastTokens = &expr; } } _expression.str(""); @@ -2478,6 +2484,7 @@ namespace { std::map _expressions; std::ostringstream _expression; const Token *_start; + ExpressionTokens *_lastTokens; const SymbolDatabase *_symbolDatabase; const std::list &_constFunctions; }; diff --git a/test/testother.cpp b/test/testother.cpp index 624d85b5b..963f10aa7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3762,6 +3762,11 @@ private: " if (str == \"(\" || str == \"(\") {}\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str()); + + check("void foo() {\n" + " if (bar(a) && !strcmp(a, b) && bar(a) && !strcmp(a, b)) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void duplicateExpression4() {