Fixed #3729: Don't suggest recursive call to optimize away c_str()

This commit is contained in:
PKEuS 2012-08-26 10:56:46 +02:00
parent 839f7a32a4
commit 4b1075b34b
2 changed files with 6 additions and 1 deletions

View File

@ -1121,7 +1121,7 @@ void CheckStl::string_c_str()
if (var && var->isPointer())
string_c_strError(tok);
} else if (Token::Match(tok, "%var% ( !!)") && c_strFuncParam.find(tok->str()) != c_strFuncParam.end() &&
_settings->isEnabled("performance") && !Token::Match(tok->previous(), "::|.") && tok->varId() == 0) { // calling function. TODO: Add support for member functions
_settings->isEnabled("performance") && !Token::Match(tok->previous(), "::|.") && tok->varId() == 0 && tok->str() != scope->className) { // calling function. TODO: Add support for member functions
std::pair<std::multimap<std::string, unsigned int>::const_iterator, std::multimap<std::string, unsigned int>::const_iterator> range = c_strFuncParam.equal_range(tok->str());
for (std::multimap<std::string, unsigned int>::const_iterator i = range.first; i != range.second; ++i) {
if (i->second == 0)

View File

@ -1724,6 +1724,11 @@ private:
" Foo(str.c_str());\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int atoi(const std::string& str) {\n" // #3729: Don't suggest recursive call
" return atoi(str.c_str());\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void autoPointer() {