diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2016-10-07 09:23:51 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-10-07 10:38:06 +0200 |
commit | b8711a13834d4b141bb41de915702131dcc494e7 (patch) | |
tree | 352203ddeff7ec736313d3dd1416cc8a08edb5bf /compilerplugins | |
parent | 5d2210d5f3fecbd922fdccf0fa9d4b057880b409 (diff) |
loplugin:nullptr: remove duplicate warnings
Change-Id: I859d9ac8f7e4134bdac59b39e95eb563d1291e8b
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/nullptr.cxx | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx index 0ebbcde832f4..3ab32031e6f2 100644 --- a/compilerplugins/clang/nullptr.cxx +++ b/compilerplugins/clang/nullptr.cxx @@ -39,6 +39,16 @@ bool isAnyKindOfPointerType(QualType type) { || type->isMemberPointerType(); } +bool isNullPointerCast(CastExpr const * expr) { + switch (expr->getCastKind()) { + case CK_NullToPointer: + case CK_NullToMemberPointer: + return true; + default: + return false; + } +} + class Nullptr: public RecursiveASTVisitor<Nullptr>, public loplugin::RewritePlugin { @@ -92,11 +102,7 @@ bool Nullptr::VisitImplicitCastExpr(CastExpr const * expr) { if (ignoreLocation(expr)) { return true; } - switch (expr->getCastKind()) { - case CK_NullToPointer: - case CK_NullToMemberPointer: - break; - default: + if (!isNullPointerCast(expr)) { return true; } Expr::NullPointerConstantKind k = expr->isNullPointerConstant( @@ -268,6 +274,13 @@ void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) { void Nullptr::handleZero(Expr const * expr) { //TODO: detect NPCK_ZeroExpression where appropriate + // Filter out ImplicitCastExpr that will be handled by + // VisitImplicitCastExpr: + if (auto ice = dyn_cast<ImplicitCastExpr>(expr)) { + if (isNullPointerCast(ice)) { + return; + } + } auto const lit = dyn_cast<IntegerLiteral>(expr->IgnoreParenImpCasts()); if (lit != nullptr && !lit->getValue().getBoolValue()) { handleNull(expr, nullptr, Expr::NPCK_ZeroLiteral); |