File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 () {
You can’t perform that action at this time.
0 commit comments