Change-Id: I9a947beefd2dfe21da8239e841ea3fb416bd1548
This commit is contained in:
Noel Grandin
2015-11-04 08:29:36 +02:00
parent baa411b59c
commit 59b072e22b
126 changed files with 403 additions and 498 deletions

View File

@@ -11,6 +11,7 @@
#include <limits>
#include <stack>
#include <string>
#include <iostream>
#include "compat.hxx"
#include "plugin.hxx"
@@ -104,6 +105,8 @@ private:
void handleOUStringCtor(
CallExpr const * expr, unsigned arg, std::string const & qname);
void handleOUStringCtor2(
CallExpr const * expr, unsigned arg, std::string const & qname);
std::stack<Expr const *> calls_;
};
@@ -546,6 +549,12 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) {
TreatEmpty::Error);
return true;
}
// For places where we are calling a method with a 'const OUString&' param
for (unsigned i=0; i < fdecl->getNumParams(); ++i)
{
if (fdecl->getParamDecl(i)->getType().getAsString() == "const ::rtl::OUString &")
handleOUStringCtor2(expr, i, qname);
}
return true;
}
@@ -1283,6 +1292,40 @@ void StringConstant::handleOUStringCtor(
<< qname << expr->getSourceRange();
}
// For places where we are calling a method with an 'const OUString&' param
//
void StringConstant::handleOUStringCtor2(
CallExpr const * expr, unsigned arg, std::string const & qname)
{
auto e0 = expr->getArg(arg)->IgnoreParenImpCasts();
auto e1 = dyn_cast<CXXFunctionalCastExpr>(e0);
if (e1 == nullptr) {
return;
}
e0 = e1->getSubExpr()->IgnoreParenImpCasts();
auto e2 = dyn_cast<CXXBindTemporaryExpr>(e0);
if (e2 == nullptr) {
return;
}
auto e3 = dyn_cast<CXXConstructExpr>(
e2->getSubExpr()->IgnoreParenImpCasts());
if (e3 == nullptr) {
return;
}
if (e3->getNumArgs() == 1)
{
std::string s = e3->getArg(0)->getType().getAsString();
if (s == "sal_Unicode" || s == "char")
return;
}
report(
DiagnosticsEngine::Warning,
("in call of %0, replace OUString constructed from a string literal"
" directly with the string literal"),
e3->getExprLoc())
<< qname << expr->getSourceRange();
}
loplugin::Plugin::Registration< StringConstant > X("stringconstant", true);
}