Fixed #3697.
This commit is contained in:
parent
8e9c09659f
commit
8492685531
|
@ -1124,7 +1124,8 @@ void CheckStl::string_c_str()
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
|
const Variable* var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
|
||||||
if (var && var->isPointer())
|
if (var && var->isPointer())
|
||||||
string_c_strError(tok);
|
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());
|
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) {
|
for (std::multimap<std::string, unsigned int>::const_iterator i = range.first; i != range.second; ++i) {
|
||||||
if (i->second == 0)
|
if (i->second == 0)
|
||||||
|
|
|
@ -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",
|
"[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());
|
"", 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"
|
check("void Foo(const char* p) {}\n"
|
||||||
"void Foo(const std::string& str) {Foo(str.c_str());}\n" // Overloaded
|
"void Foo(const std::string& str) {Foo(str.c_str());}\n" // Overloaded
|
||||||
"void Bar() {\n"
|
"void Bar() {\n"
|
||||||
|
|
Loading…
Reference in New Issue