File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3345,6 +3345,9 @@ void CheckClass::checkReturnByReference()
33453345 if (const Library::Container* container = mSettings ->library .detectContainer (func.retDef ))
33463346 if (container->view )
33473347 continue ;
3348+ if (!func.isConst () && func.hasRvalRefQualifier ())
3349+ // this method could be used by temporary objects, return by value can be dangerous
3350+ continue ;
33483351 if (const Variable* var = getSingleReturnVar (func.functionScope )) {
33493352 if (!var->valueType ())
33503353 continue ;
Original file line number Diff line number Diff line change @@ -9045,6 +9045,13 @@ class TestClass : public TestFixture {
90459045 " };\n "
90469046 " U<std::string> u;\n " );
90479047 ASSERT_EQUALS (" " , errout_str ());
9048+
9049+ checkReturnByReference (" struct S {\n " // #13011
9050+ " std::string s;\n "
9051+ " const std::string& foo() const & { return s; }\n "
9052+ " std::string foo() && { return s; }\n " // <- used for temporary objects
9053+ " };\n " );
9054+ ASSERT_EQUALS (" " , errout_str ());
90489055 }
90499056};
90509057
You can’t perform that action at this time.
0 commit comments