Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,9 +1986,11 @@ static bool isc_strCall(const Token* tok, const Library::Container* container)

static bool isc_strConcat(const Token* tok)
{
if (!tok->isBinaryOp() || !Token::simpleMatch(tok, "+"))
if (!tok->isBinaryOp() || !Token::Match(tok, "+|+="))
return false;
for (const Token* op : { tok->astOperand1(), tok->astOperand2() }) { // NOLINT(readability-use-anyofallof)
if (tok->isAssignmentOp() && astIsLHS(op))
continue;
const Token* sibling = op->astSibling();
if (!sibling->valueType())
continue;
Expand Down
6 changes: 6 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5161,6 +5161,12 @@ class TestStl : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n",
errout_str());

check("void f(std::string& a, const std::string& b) {\n"
" a += b.c_str();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2:7]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n",
errout_str());
}

void uselessCalls() {
Expand Down
Loading