loplugin:nullptr: Check for more pointer types
(but did not turn up further matches) Change-Id: I7e4843d00a2e3b46edec46c5b56b6ba1b2e098fd
This commit is contained in:
@@ -34,6 +34,11 @@ char const * kindName(Expr::NullPointerConstantKind kind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isAnyKindOfPointerType(QualType type) {
|
||||||
|
return type->isAnyPointerType() || type->isFunctionPointerType()
|
||||||
|
|| type->isMemberPointerType();
|
||||||
|
}
|
||||||
|
|
||||||
class Nullptr:
|
class Nullptr:
|
||||||
public RecursiveASTVisitor<Nullptr>, public loplugin::RewritePlugin
|
public RecursiveASTVisitor<Nullptr>, public loplugin::RewritePlugin
|
||||||
{
|
{
|
||||||
@@ -136,13 +141,13 @@ bool Nullptr::VisitBinaryOperator(BinaryOperator const * expr) {
|
|||||||
switch (expr->getOpcode()) {
|
switch (expr->getOpcode()) {
|
||||||
case BO_EQ:
|
case BO_EQ:
|
||||||
case BO_NE:
|
case BO_NE:
|
||||||
if (expr->getRHS()->getType()->isPointerType()) {
|
if (isAnyKindOfPointerType(expr->getRHS()->getType())) {
|
||||||
e = expr->getLHS();
|
e = expr->getLHS();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
case BO_Assign:
|
case BO_Assign:
|
||||||
if (expr->getLHS()->getType()->isPointerType()) {
|
if (isAnyKindOfPointerType(expr->getLHS()->getType())) {
|
||||||
e = expr->getRHS();
|
e = expr->getRHS();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -162,13 +167,13 @@ bool Nullptr::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) {
|
|||||||
switch (expr->getOperator()) {
|
switch (expr->getOperator()) {
|
||||||
case OO_EqualEqual:
|
case OO_EqualEqual:
|
||||||
case OO_ExclaimEqual:
|
case OO_ExclaimEqual:
|
||||||
if (expr->getArg(1)->getType()->isPointerType()) {
|
if (isAnyKindOfPointerType(expr->getArg(1)->getType())) {
|
||||||
e = expr->getArg(0);
|
e = expr->getArg(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
case OO_Equal:
|
case OO_Equal:
|
||||||
if (expr->getArg(0)->getType()->isPointerType()) {
|
if (isAnyKindOfPointerType(expr->getArg(0)->getType())) {
|
||||||
e = expr->getArg(1);
|
e = expr->getArg(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -184,7 +189,7 @@ bool Nullptr::VisitParmVarDecl(ParmVarDecl const * decl) {
|
|||||||
if (ignoreLocation(decl)) {
|
if (ignoreLocation(decl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!decl->getType()->isPointerType()) {
|
if (!isAnyKindOfPointerType(decl->getType())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto e = decl->getDefaultArg();
|
auto e = decl->getDefaultArg();
|
||||||
@@ -231,7 +236,7 @@ void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto d = init->getAnyMember();
|
auto d = init->getAnyMember();
|
||||||
if (d == nullptr || !d->getType()->isPointerType()) {
|
if (d == nullptr || !isAnyKindOfPointerType(d->getType())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto e2 = dyn_cast<ParenListExpr>(e)) {
|
if (auto e2 = dyn_cast<ParenListExpr>(e)) {
|
||||||
|
Reference in New Issue
Block a user