STL: don't warn about the suspicious string::find condition because it's not always a bug
This commit is contained in:
parent
75c0ed7e6e
commit
e207da18a2
|
@ -556,12 +556,8 @@ void CheckStl::if_find()
|
|||
|
||||
decl = decl->next();
|
||||
|
||||
// string..
|
||||
if (_settings->_showAll && Token::Match(decl, "const| std :: string &|*| %varid%", varid))
|
||||
if_findError(tok, true);
|
||||
|
||||
// stl container
|
||||
else if (Token::Match(decl, "const| std :: %var% < %type% > &|*| %varid%", varid))
|
||||
if (Token::Match(decl, "const| std :: %var% < %type% > &|*| %varid%", varid))
|
||||
if_findError(tok, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -646,25 +646,6 @@ private:
|
|||
|
||||
void if_find()
|
||||
{
|
||||
// ---------------------------
|
||||
// string::find
|
||||
// ---------------------------
|
||||
|
||||
// error
|
||||
check("void f(std::string s)\n"
|
||||
"{\n"
|
||||
" if (s.find(\"ab\")) { }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (possible style) Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string.\n", errout.str());
|
||||
|
||||
// ok
|
||||
check("void f(std::string s)\n"
|
||||
"{\n"
|
||||
" if (s.find(\"ab\") != std::string::npos) { }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
|
||||
// ---------------------------
|
||||
// set::find
|
||||
// ---------------------------
|
||||
|
|
Loading…
Reference in New Issue