summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-10-07 09:23:51 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-10-07 10:38:06 +0200
commitb8711a13834d4b141bb41de915702131dcc494e7 (patch)
tree352203ddeff7ec736313d3dd1416cc8a08edb5bf /compilerplugins
parentmight as well go back to a std::stack now (diff)
downloadcore-b8711a13834d4b141bb41de915702131dcc494e7.tar.gz
core-b8711a13834d4b141bb41de915702131dcc494e7.zip
loplugin:nullptr: remove duplicate warnings
Change-Id: I859d9ac8f7e4134bdac59b39e95eb563d1291e8b
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/nullptr.cxx23
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);