diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 637f5e1e8b8..45c6ab59bf8 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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; diff --git a/test/teststl.cpp b/test/teststl.cpp index 197cc3fafa7..dad71b5aec9 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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() {