This commit is contained in:
PKEuS 2012-04-02 11:02:41 +02:00
parent 8e9c09659f
commit 8492685531
2 changed files with 10 additions and 1 deletions

View File

@ -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<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

@ -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"