diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-12-08 22:56:02 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-12-08 22:56:02 +0100 |
commit | bb24492c767eda30a14c83ac27b74b977b177dbb (patch) | |
tree | 0bd75004941a3b111e3c8c911bd2c22b6b259b0d /compilerplugins/clang/passstuffbyref.cxx | |
parent | 8d2c9a60b2dca069dedb08cac38c26afea0a562d (diff) |
More loplugin::TypeCheck use
Change-Id: I2f4a26a918134568f541cd45bdcf5a12b1f1d2ee
Diffstat (limited to 'compilerplugins/clang/passstuffbyref.cxx')
-rw-r--r-- | compilerplugins/clang/passstuffbyref.cxx | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx index f2e66f710986..9da28b3c5938 100644 --- a/compilerplugins/clang/passstuffbyref.cxx +++ b/compilerplugins/clang/passstuffbyref.cxx @@ -11,6 +11,7 @@ #include <set> #include "plugin.hxx" +#include "typecheck.hxx" // Find places where various things are passed by value. // It's not very efficient, because we generally end up copying it twice - once into the parameter and @@ -38,7 +39,7 @@ public: bool VisitLambdaExpr(const LambdaExpr * expr); private: - bool isFat(QualType type, std::string * name); + bool isFat(QualType type); }; bool PassStuffByRef::VisitFunctionDecl(const FunctionDecl * functionDecl) { @@ -63,14 +64,13 @@ bool PassStuffByRef::VisitFunctionDecl(const FunctionDecl * functionDecl) { unsigned n = functionDecl->getNumParams(); for (unsigned i = 0; i != n; ++i) { const ParmVarDecl * pvDecl = functionDecl->getParamDecl(i); - std::string name; - if (isFat(pvDecl->getType(), &name)) { + auto const t = pvDecl->getType(); + if (isFat(t)) { report( DiagnosticsEngine::Warning, - ("passing '%0' by value, rather pass by reference, e.g., '%0" - " const &'"), + ("passing %0 by value, rather pass by const lvalue reference"), pvDecl->getLocation()) - << name << pvDecl->getSourceRange(); + << t << pvDecl->getSourceRange(); } } return true; @@ -82,14 +82,14 @@ bool PassStuffByRef::VisitLambdaExpr(const LambdaExpr * expr) { } for (auto i(expr->capture_begin()); i != expr->capture_end(); ++i) { if (i->getCaptureKind() == LambdaCaptureKind::LCK_ByCopy) { - std::string name; - if (isFat(i->getCapturedVar()->getType(), &name)) { + auto const t = i->getCapturedVar()->getType(); + if (isFat(t)) { report( DiagnosticsEngine::Warning, - ("%0 capture of '%1' variable by copy, rather use capture" + ("%0 capture of %1 variable by copy, rather use capture" " by reference---UNLESS THE LAMBDA OUTLIVES THE VARIABLE"), i->getLocation()) - << (i->isImplicit() ? "implicit" : "explicit") << name + << (i->isImplicit() ? "implicit" : "explicit") << t << expr->getSourceRange(); } } @@ -97,13 +97,17 @@ bool PassStuffByRef::VisitLambdaExpr(const LambdaExpr * expr) { return true; } -bool PassStuffByRef::isFat(QualType type, std::string * name) { +bool PassStuffByRef::isFat(QualType type) { if (!type->isRecordType()) { return false; } - *name = type.getUnqualifiedType().getCanonicalType().getAsString(); - if (*name == "class rtl::OUString" || *name == "class rtl::OString" - || name->compare(0, 35, "class com::sun::star::uno::Sequence") == 0) + if ((loplugin::TypeCheck(type).Class("OUString").Namespace("rtl") + .GlobalNamespace()) + || (loplugin::TypeCheck(type).Class("OString").Namespace("rtl") + .GlobalNamespace()) + || (loplugin::TypeCheck(type).Class("Sequence").Namespace("uno") + .Namespace("star").Namespace("sun").Namespace("com") + .GlobalNamespace())) { return true; } |