More loplugin::TypeCheck use

Change-Id: I2f4a26a918134568f541cd45bdcf5a12b1f1d2ee
This commit is contained in:
Stephan Bergmann
2015-12-08 22:56:02 +01:00
parent 8d2c9a60b2
commit bb24492c76
5 changed files with 80 additions and 116 deletions

View File

@@ -16,6 +16,7 @@
#include "compat.hxx"
#include "plugin.hxx"
#include "typecheck.hxx"
// Define a "string constant" to be a constant expression either of type "array
// of N char" where each array element is a non-NUL ASCII character---except
@@ -37,11 +38,6 @@
namespace {
bool isPlainChar(QualType type) {
return type->isSpecificBuiltinType(BuiltinType::Char_S)
|| type->isSpecificBuiltinType(BuiltinType::Char_U);
}
SourceLocation getMemberLocation(Expr const * expr) {
CallExpr const * e1 = dyn_cast<CallExpr>(expr);
MemberExpr const * e2 = e1 == nullptr
@@ -227,30 +223,14 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) {
std::string qname(fdecl->getQualifiedNameAsString());
for (unsigned i = 0; i != fdecl->getNumParams(); ++i) {
auto t = fdecl->getParamDecl(i)->getType();
if (t->isLValueReferenceType()
&& t->getAs<SubstTemplateTypeParmType>() == nullptr)
if (loplugin::TypeCheck(t).NotSubstTemplateTypeParmType()
.LvalueReference().Const().NotSubstTemplateTypeParmType()
.Class("OUString").Namespace("rtl").GlobalNamespace())
{
t = t->getAs<LValueReferenceType>()->getPointeeType();
if (t.isConstQualified() && !t.isVolatileQualified()
&& t->isClassType()
&& t->getAs<SubstTemplateTypeParmType>() == nullptr)
if (!(isLhsOfAssignment(fdecl, i)
|| hasOverloads(fdecl, expr->getNumArgs())))
{
auto td = compat::getAsTagDecl(*t);
auto id = td->getIdentifier();
if (id != nullptr && id->isStr("OUString")) {
auto nd = dyn_cast<NamespaceDecl>(td->getParent());
if (nd != nullptr) {
id = nd->getIdentifier();
if (id != nullptr && id->isStr("rtl")) {
//TODO: check rtl is outermost namespace
if (!(isLhsOfAssignment(fdecl, i)
|| hasOverloads(fdecl, expr->getNumArgs())))
{
handleOUStringCtor(expr, i, qname, true);
}
}
}
}
handleOUStringCtor(expr, i, qname, true);
}
}
}
@@ -839,7 +819,8 @@ bool StringConstant::isStringConstant(
assert(terminatingNul != nullptr);
QualType t = expr->getType();
if (!(t->isConstantArrayType() && t.isConstQualified()
&& isPlainChar(t->getAsArrayTypeUnsafe()->getElementType())))
&& (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
.Char())))
{
return false;
}