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/stringconstant.cxx | |
parent | 8d2c9a60b2dca069dedb08cac38c26afea0a562d (diff) |
More loplugin::TypeCheck use
Change-Id: I2f4a26a918134568f541cd45bdcf5a12b1f1d2ee
Diffstat (limited to 'compilerplugins/clang/stringconstant.cxx')
-rw-r--r-- | compilerplugins/clang/stringconstant.cxx | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 56ae27c90bc5..0749abb3ddd0 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -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; } |