File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2003,7 +2003,20 @@ static bool isc_strConstructor(const Token* tok)
20032003{
20042004 if (!tok->valueType () || !Token::Match (tok, " %var% (|{" ))
20052005 return false ;
2006- return isc_strCall (tok->tokAt (1 )->astOperand2 (), tok->valueType ()->container );
2006+
2007+ const Token* callTok = tok->tokAt (1 )->astOperand2 ();
2008+ while (Token::simpleMatch (callTok, " +" ) && callTok->isBinaryOp ()) {
2009+ if (callTok->astOperand1 ()->str () == " +" ) {
2010+ callTok = callTok->astOperand1 ();
2011+ continue ;
2012+ }
2013+ if (callTok->astOperand1 ()->str () == " (" )
2014+ callTok = callTok->astOperand1 ();
2015+ else if (tok->astOperand2 ()->str () == " (" )
2016+ callTok = callTok->astOperand2 ();
2017+ break ;
2018+ }
2019+ return isc_strCall (callTok, tok->valueType ()->container );
20072020}
20082021
20092022namespace {
Original file line number Diff line number Diff line change @@ -4719,6 +4719,13 @@ class TestStl : public TestFixture {
47194719 " auto a = + s.c_str();\n "
47204720 " }\n " );
47214721 ASSERT_EQUALS (" " , errout_str ());
4722+
4723+ check (" std::string f(const std::string& a) {\n " // #14600
4724+ " std::string b(a.c_str() + 1 + 2);\n "
4725+ " return b;\n "
4726+ " }\n " );
4727+ ASSERT_EQUALS (" [test.cpp:2:17]: (performance) Constructing a std::string from the result of c_str() is slow and redundant. [stlcstrConstructor]\n " ,
4728+ errout_str ());
47224729 }
47234730
47244731 void uselessCalls () {
You can’t perform that action at this time.
0 commit comments