diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 029369c11..422c6d7a0 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1124,7 +1124,8 @@ void CheckStl::string_c_str() const Variable* var = symbolDatabase->getVariableFromVarId(tok->next()->varId()); 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(), "::|.")) { // calling function. TODO: Add support for member functions + } 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 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 02614b350..c5aad4839 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1582,6 +1582,14 @@ private: "[test.cpp:10]: (performance) Passing the result of c_str() to a function that takes std::string as argument 1 is slow and redundant.\n", "", errout.str()); + check("void svgFile(const std::string &content, const std::string &fileName, const double end = 1000., const double start = 0.);\n" + "void Bar(std::string filename) {\n" + " std::string str = \"bar\";\n" + " std::ofstream svgFile(filename.c_str(), std::ios::trunc);\n" + " svgFile << \"test\";\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void Foo(const char* p) {}\n" "void Foo(const std::string& str) {Foo(str.c_str());}\n" // Overloaded "void Bar() {\n"