loplugin:passstuffbyref improved return in canvas and svtools

and for now, ignore methods with params so we don't fall into the trap
of thinking that calls to methods like:
   Bar& foo(Bar &p) { return p; }
can be converted from
   Bar f() { return foo(Bar()); }
to
Bar const & f() { return foo(Bar()); }

Change-Id: Ia3795eb2baf353cb6bec4ebf40451f2789d66ad7
Reviewed-on: https://gerrit.libreoffice.org/47034
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2017-12-25 19:21:12 +02:00
parent 09895ae496
commit c54d34f708
25 changed files with 39 additions and 30 deletions

View File

@@ -402,6 +402,12 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr)
FunctionDecl const * calleeFunctionDecl = callExpr->getDirectCallee();
if (!calleeFunctionDecl)
return true;
// TODO anything takes a param is suspect because it might return the param by ref.
// we could tighten this to only reject functions that have a param of the same type
// as the return type. Or we could check for such functions and disallow them.
// Or we could force such functions to be annotated somehow.
if (calleeFunctionDecl->getNumParams() > 0)
return true;
auto tc = loplugin::TypeCheck(calleeFunctionDecl->getReturnType());
if (!tc.LvalueReference() && !tc.Pointer())
return true;