summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-03-31 15:49:28 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-03-31 15:49:28 +0200
commit2d74cbe769e4562d6edcd0d35868fa80e6d9dd15 (patch)
treebf5e18abebaa0b839d66114e4772b629a79a9401 /compilerplugins
parent4c363dd65a18e9b8d4dcd1b0aaf545a40c3dbec5 (diff)
loplugin:nullptr: Check for more pointer types
(but did not turn up further matches) Change-Id: I7e4843d00a2e3b46edec46c5b56b6ba1b2e098fd
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/nullptr.cxx17
1 files changed, 11 insertions, 6 deletions
diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx
index 1e6311b1862b..34e27e663dc1 100644
--- a/compilerplugins/clang/nullptr.cxx
+++ b/compilerplugins/clang/nullptr.cxx
@@ -34,6 +34,11 @@ char const * kindName(Expr::NullPointerConstantKind kind) {
}
}
+bool isAnyKindOfPointerType(QualType type) {
+ return type->isAnyPointerType() || type->isFunctionPointerType()
+ || type->isMemberPointerType();
+}
+
class Nullptr:
public RecursiveASTVisitor<Nullptr>, public loplugin::RewritePlugin
{
@@ -136,13 +141,13 @@ bool Nullptr::VisitBinaryOperator(BinaryOperator const * expr) {
switch (expr->getOpcode()) {
case BO_EQ:
case BO_NE:
- if (expr->getRHS()->getType()->isPointerType()) {
+ if (isAnyKindOfPointerType(expr->getRHS()->getType())) {
e = expr->getLHS();
break;
}
// fall through
case BO_Assign:
- if (expr->getLHS()->getType()->isPointerType()) {
+ if (isAnyKindOfPointerType(expr->getLHS()->getType())) {
e = expr->getRHS();
break;
}
@@ -162,13 +167,13 @@ bool Nullptr::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) {
switch (expr->getOperator()) {
case OO_EqualEqual:
case OO_ExclaimEqual:
- if (expr->getArg(1)->getType()->isPointerType()) {
+ if (isAnyKindOfPointerType(expr->getArg(1)->getType())) {
e = expr->getArg(0);
break;
}
// fall through
case OO_Equal:
- if (expr->getArg(0)->getType()->isPointerType()) {
+ if (isAnyKindOfPointerType(expr->getArg(0)->getType())) {
e = expr->getArg(1);
break;
}
@@ -184,7 +189,7 @@ bool Nullptr::VisitParmVarDecl(ParmVarDecl const * decl) {
if (ignoreLocation(decl)) {
return true;
}
- if (!decl->getType()->isPointerType()) {
+ if (!isAnyKindOfPointerType(decl->getType())) {
return true;
}
auto e = decl->getDefaultArg();
@@ -231,7 +236,7 @@ void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) {
return;
}
auto d = init->getAnyMember();
- if (d == nullptr || !d->getType()->isPointerType()) {
+ if (d == nullptr || !isAnyKindOfPointerType(d->getType())) {
return;
}
if (auto e2 = dyn_cast<ParenListExpr>(e)) {