diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index fa7cf86ec..74354bcc4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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::const_iterator, std::multimap::const_iterator> range = c_strFuncParam.equal_range(tok->str()); for (std::multimap::const_iterator i = range.first; i != range.second; ++i) { if (i->second == 0) diff --git a/test/teststl.cpp b/test/teststl.cpp index b251a782c..ca69de985 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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() {