summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-12-23 18:35:30 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-12-24 07:01:47 +0100
commit6028b64e27dc45f20aa4a4e0adbef1c03e91a79b (patch)
treefcdba02b18bc9081371b91681fcb898697155af6 /compilerplugins
parent92bab0f11e0a93005bfd13db3a0552ecaf082ecb (diff)
loplugin:passstuffbyref even more return improvements
Change-Id: I2a752025cd429e4d271626402dce5d8a8b0c76d2 Reviewed-on: https://gerrit.libreoffice.org/47021 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/passstuffbyref.cxx11
-rw-r--r--compilerplugins/clang/test/passstuffbyref.cxx5
2 files changed, 15 insertions, 1 deletions
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<CXXConversionDecl>(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 <rtl/ustring.hxx>
#include <sys/time.h>
+#include <o3tl/cow_wrapper.hxx>
#include <vector>
struct S1 {
@@ -21,6 +22,7 @@ struct S2 {
OUString mv3[2];
S1 child;
static OUString gs1;
+ o3tl::cow_wrapper<S1> 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"); }