Fixed #3261 (Function 'find' useless call. The variable 'str' is using function 'find' against itself)
This commit is contained in:
parent
5d868766c7
commit
950460c0a7
|
@ -1162,13 +1162,7 @@ void CheckStl::uselessCalls()
|
|||
if (Token::Match(tok, "%var% . compare (") &&
|
||||
tok->varId() == tok->tokAt(3)->link()->tokAt(-1)->varId()) {
|
||||
uselessCallsReturnValueError(tok, tok->tokAt(2));
|
||||
} else if ((Token::Match(tok, "%var% . compare ( %var%") ||
|
||||
Token::Match(tok, "%var% . find ( %var%") ||
|
||||
Token::Match(tok, "%var% . rfind ( %var%") ||
|
||||
Token::Match(tok, "%var% . find_first_not_of ( %var%") ||
|
||||
Token::Match(tok, "%var% . find_first_of ( %var%") ||
|
||||
Token::Match(tok, "%var% . find_last_not_of ( %var%") ||
|
||||
Token::Match(tok, "%var% . find_last_of ( %var%")) &&
|
||||
} else if (Token::Match(tok, "%var% . compare|find|rfind|find_first_not_of|find_first_of|find_last_not_of|find_last_of ( %var% ,") &&
|
||||
tok->varId() == tok->tokAt(4)->varId()) {
|
||||
uselessCallsReturnValueError(tok->tokAt(4), tok->tokAt(2));
|
||||
} else if (Token::Match(tok, "%var% . swap ( %var% )") &&
|
||||
|
|
|
@ -1509,6 +1509,14 @@ private:
|
|||
"[test.cpp:8]: (performance) Function \'substr\' useless call. Function create copy "
|
||||
"of the \'s2\' object.\n",errout.str());
|
||||
|
||||
check("#include <string>\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" std::string str = \"a1b1\";\n"
|
||||
" return str.find(str[1], 2);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue