From 015da40e49262ea950980c01c980d377a3c1ec6b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:34:44 +0200 Subject: [PATCH 1/3] Update checkstl.cpp --- lib/checkstl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 637f5e1e8b8..97ca1c853d1 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; From f2a4eb84c57aa8d1f10ac1e1a353e0b1def9fb66 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:35:56 +0200 Subject: [PATCH 2/3] Update teststl.cpp --- test/teststl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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() { From 5e51acf1a2cd13e7835f54945a4d291414e794ec Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:37:46 +0200 Subject: [PATCH 3/3] Update checkstl.cpp --- lib/checkstl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 97ca1c853d1..45c6ab59bf8 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1986,7 +1986,7 @@ static bool isc_strCall(const Token* tok, const Library::Container* container) static bool isc_strConcat(const Token* tok) { - if (!tok->isBinaryOp() || !Token::Match(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))