Fixed #4102 (False positive: 'find('=') + 1U' can't be replaced with compare)
This commit is contained in:
parent
b1a768e5ec
commit
0115bb8d24
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue