Teach loplugin:stringconstant about RTL_CONSTASCII_STRINGPARAM
Change-Id: I8ff0e104aad045f3835dc8facc760a8339b1d088
This commit is contained in:
@@ -821,6 +821,20 @@ bool StringConstant::isStringConstant(
|
||||
assert(embeddedNuls != nullptr);
|
||||
assert(terminatingNul != nullptr);
|
||||
QualType t = expr->getType();
|
||||
// Look inside RTL_CONSTASCII_STRINGPARAM:
|
||||
if (loplugin::TypeCheck(t).Pointer().Const().Char()) {
|
||||
auto e2 = dyn_cast<UnaryOperator>(expr);
|
||||
if (e2 == nullptr || e2->getOpcode() != UO_AddrOf) {
|
||||
return false;
|
||||
}
|
||||
auto e3 = dyn_cast<ArraySubscriptExpr>(
|
||||
e2->getSubExpr()->IgnoreParenImpCasts());
|
||||
if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
|
||||
return false;
|
||||
}
|
||||
expr = e3->getBase()->IgnoreParenImpCasts();
|
||||
t = expr->getType();
|
||||
}
|
||||
if (!(t->isConstantArrayType() && t.isConstQualified()
|
||||
&& (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
|
||||
.Char())))
|
||||
|
@@ -39,6 +39,16 @@ TypeCheck TypeCheck::LvalueReference() const {
|
||||
return TypeCheck();
|
||||
}
|
||||
|
||||
TypeCheck TypeCheck::Pointer() const {
|
||||
if (!type_.isNull()) {
|
||||
auto const t = type_->getAs<clang::PointerType>();
|
||||
if (t != nullptr) {
|
||||
return TypeCheck(t->getPointeeType());
|
||||
}
|
||||
}
|
||||
return TypeCheck();
|
||||
}
|
||||
|
||||
TypeCheck TypeCheck::NotSubstTemplateTypeParmType() const {
|
||||
return
|
||||
(!type_.isNull()
|
||||
|
@@ -31,6 +31,8 @@ public:
|
||||
|
||||
TerminalCheck Char() const;
|
||||
|
||||
TypeCheck Pointer() const;
|
||||
|
||||
TypeCheck LvalueReference() const;
|
||||
|
||||
template<std::size_t N> inline NamespaceCheck Class(char const (& id)[N])
|
||||
|
Reference in New Issue
Block a user