diff --git a/.travis.yml b/.travis.yml index a2b6281ee..28a0fa43e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ compiler: script: - make test - $CXX -o cppcheck -O2 cli/*.cpp lib/*.cpp -Ilib - - ./cppcheck --error-exitcode=1 -Ilib --enable=style --suppress=duplicateBranch --suppress=stlIfStrFind -q cli gui lib -igui/test + - ./cppcheck --error-exitcode=1 -Ilib --enable=style --suppress=duplicateBranch -q cli gui lib -igui/test diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index b49d71c46..b60a430aa 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -720,14 +720,18 @@ static bool if_findCompare(const Token * const tokBack) const Token *tok = tokBack; while (tok && tok->str() == ")") { tok = tok->next(); - if (Token::Match(tok,",|==|!=")) - return true; + if (Token::Match(tok, ") !!{") && tok->link()->previous() && (Token::Match(tok->link()->previous(),",|==|!=") || tok->link()->previous()->isName())) return true; } + + if (Token::Match(tok,",|==|!=")) + return true; + if (tok->isArithmeticalOp()) // result is used in some calculation + return true; // TODO: check if there is a comparison of the result somewhere return false; } diff --git a/test/teststl.cpp b/test/teststl.cpp index d5a181185..8e5ab87e3 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1372,6 +1372,12 @@ private: " if ((!s1.empty()) && (0 == s1.find(s2))) { }\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (performance) Inefficient usage of string::find in condition; string::compare would be faster.\n", errout.str()); + + // #4102 + check("void f(const std::string &define) {\n" + " if (define.find(\"=\") + 1U == define.size());\n" + "}"); + ASSERT_EQUALS("", errout.str()); }