Skip to content

Commit 0ec9223

Browse files
Update teststl.cpp
1 parent 5f7d92b commit 0ec9223

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

test/teststl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,6 +4680,22 @@ class TestStl : public TestFixture {
46804680
" return s->x.c_str();\n"
46814681
"}\n");
46824682
ASSERT_EQUALS("", errout_str());
4683+
4684+
check("std::string f(const std::string& s) {\n" // #14533
4685+
" auto x = std::string(\"abc\") + s.c_str();\n"
4686+
" auto y = s.c_str() + std::string(\"def\");\n"
4687+
" return x + y;\n"
4688+
"}\n");
4689+
ASSERT_EQUALS("[test.cpp:2:33]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n"
4690+
"[test.cpp:3:24]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n",
4691+
errout_str());
4692+
4693+
check("std::string get();\n"
4694+
"std::string f(const std::string& s) {\n"
4695+
" return get() + s.c_str();\n"
4696+
"}\n");
4697+
ASSERT_EQUALS("[test.cpp:3:18]: (performance) Concatenating the result of c_str() and a std::string is slow and redundant. [stlcstrConcat]\n",
4698+
errout_str());
46834699
}
46844700

46854701
void uselessCalls() {

0 commit comments

Comments
 (0)