File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3326,7 +3326,10 @@ static const Variable* getSingleReturnVar(const Scope* scope) {
33263326 return nullptr ;
33273327 if (!start->astOperand1 () || start->str () != " return" )
33283328 return nullptr ;
3329- return start->astOperand1 ()->variable ();
3329+ const Token* tok = start->astOperand1 ();
3330+ if (tok->str () == " ." )
3331+ tok = tok->astOperand2 ();
3332+ return tok->variable ();
33303333}
33313334
33323335void CheckClass::checkReturnByReference ()
Original file line number Diff line number Diff line change @@ -795,7 +795,7 @@ class CPPCHECKLIB Token {
795795 setFlag (fIsTemplateArg , value);
796796 }
797797
798- std::string getMacroName () const {
798+ const std::string& getMacroName () const {
799799 return mImpl ->mMacroName ;
800800 }
801801 void setMacroName (std::string name) {
Original file line number Diff line number Diff line change @@ -9066,6 +9066,23 @@ class TestClass : public TestFixture {
90669066 " std::string foo() && { return s; }\n " // <- used for temporary objects
90679067 " };\n " );
90689068 ASSERT_EQUALS (" " , errout_str ());
9069+
9070+ checkReturnByReference (" struct S1 {\n " // #13056
9071+ " std::string str;\n "
9072+ " struct T { std::string strT; } mT;\n "
9073+ " };\n "
9074+ " struct S2 {\n "
9075+ " std::string get1() const {\n "
9076+ " return mS1->str;\n "
9077+ " }\n "
9078+ " std::string get2() const {\n "
9079+ " return mS1->mT.strT;\n "
9080+ " }\n "
9081+ " S1* mS1;\n "
9082+ " };\n " );
9083+ ASSERT_EQUALS (" [test.cpp:6]: (performance) Function 'get1()' should return member 'str' by const reference.\n "
9084+ " [test.cpp:9]: (performance) Function 'get2()' should return member 'strT' by const reference.\n " ,
9085+ errout_str ());
90699086 }
90709087};
90719088
You can’t perform that action at this time.
0 commit comments