From 6028b64e27dc45f20aa4a4e0adbef1c03e91a79b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 23 Dec 2017 18:35:30 +0200 Subject: loplugin:passstuffbyref even more return improvements Change-Id: I2a752025cd429e4d271626402dce5d8a8b0c76d2 Reviewed-on: https://gerrit.libreoffice.org/47021 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/passstuffbyref.cxx | 11 ++++++++++- compilerplugins/clang/test/passstuffbyref.cxx | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx index 98b75abac960..0630beb80b59 100644 --- a/compilerplugins/clang/passstuffbyref.cxx +++ b/compilerplugins/clang/passstuffbyref.cxx @@ -229,6 +229,10 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C return; } + // not sure if it's possible to modify these + if (isa(functionDecl)) + return; + // ignore stuff that forms part of the stable URE interface if (isInUnoIncludeFile(functionDecl)) { return; @@ -267,6 +271,9 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C if (startswith(type.getAsString(), "struct o3tl::strong_int")) { return; } + + //functionDecl->dump(); + mbInsideFunctionDecl = true; mbFoundReturnValueDisqualifier = false; TraverseStmt(functionDecl->getBody()); @@ -395,7 +402,9 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr) FunctionDecl const * calleeFunctionDecl = callExpr->getDirectCallee(); if (!calleeFunctionDecl) return true; - return !loplugin::TypeCheck(calleeFunctionDecl->getReturnType()).LvalueReference(); + auto tc = loplugin::TypeCheck(calleeFunctionDecl->getReturnType()); + if (!tc.LvalueReference() && !tc.Pointer()) + return true; } return false; } diff --git a/compilerplugins/clang/test/passstuffbyref.cxx b/compilerplugins/clang/test/passstuffbyref.cxx index 3178bf7329f2..99e4a5a189b6 100644 --- a/compilerplugins/clang/test/passstuffbyref.cxx +++ b/compilerplugins/clang/test/passstuffbyref.cxx @@ -9,6 +9,7 @@ #include #include +#include #include struct S1 { @@ -21,6 +22,7 @@ struct S2 { OUString mv3[2]; S1 child; static OUString gs1; + o3tl::cow_wrapper mxCow; // make sure we ignore cases where the passed in parameter is std::move'd S2(OUString v1, OUString v2) @@ -35,6 +37,9 @@ struct S2 { OUString get7() { return get6(); } // expected-error {{rather return class rtl::OUString by const& than by value, to avoid unnecessary copying [loplugin:passstuffbyref]}} OUString & get8() { return gs1; } OUString get9() { return get8(); } // expected-error {{rather return class rtl::OUString by const& than by value, to avoid unnecessary copying [loplugin:passstuffbyref]}} + // TODO + OUString get10() { return OUString(*&get6()); } // todoexpected-error {{rather return class rtl::OUString by const& than by value, to avoid unnecessary copying [loplugin:passstuffbyref]}} + OUString get11() const { return mxCow->get(); } // expected-error {{rather return class rtl::OUString by const& than by value, to avoid unnecessary copying [loplugin:passstuffbyref]}} // no warning expected OUString set1() { return OUString("xxx"); } -- cgit