File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3327,8 +3327,14 @@ static const Variable* getSingleReturnVar(const Scope* scope) {
33273327 if (!start->astOperand1 () || start->str () != " return" )
33283328 return nullptr ;
33293329 const Token* tok = start->astOperand1 ();
3330- if (tok->str () == " ." )
3330+ if (tok->str () == " ." ) {
3331+ const Token* top = tok->astOperand1 ();
3332+ while (Token::Match (top, " [[.]" ))
3333+ top = top->astOperand1 ();
3334+ if (!Token::Match (top, " %var%" ))
3335+ return nullptr ;
33313336 tok = tok->astOperand2 ();
3337+ }
33323338 return tok->variable ();
33333339}
33343340
Original file line number Diff line number Diff line change @@ -9083,6 +9083,23 @@ class TestClass : public TestFixture {
90839083 ASSERT_EQUALS (" [test.cpp:6]: (performance) Function 'get1()' should return member 'str' by const reference.\n "
90849084 " [test.cpp:9]: (performance) Function 'get2()' should return member 'strT' by const reference.\n " ,
90859085 errout_str ());
9086+
9087+ checkReturnByReference (" struct S { std::string str; };\n " // #13059
9088+ " struct T {\n "
9089+ " S temp() const;\n "
9090+ " S s[1];\n "
9091+ " };\n "
9092+ " struct U {\n "
9093+ " std::string get1() const {\n "
9094+ " return t.temp().str;\n "
9095+ " }\n "
9096+ " std::string get2() const {\n "
9097+ " return t.s[0].str;\n "
9098+ " }\n "
9099+ " T t;\n "
9100+ " };\n " );
9101+ ASSERT_EQUALS (" [test.cpp:10]: (performance) Function 'get2()' should return member 'str' by const reference.\n " ,
9102+ errout_str ());
90869103 }
90879104};
90889105
You can’t perform that action at this time.
0 commit comments