[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann sbergman at redhat.com
Fri Oct 7 08:40:31 UTC 2016


 compilerplugins/clang/nullptr.cxx |   23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

New commits:
commit b8711a13834d4b141bb41de915702131dcc494e7
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Oct 7 09:23:51 2016 +0200

    loplugin:nullptr: remove duplicate warnings
    
    Change-Id: I859d9ac8f7e4134bdac59b39e95eb563d1291e8b

diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx
index 0ebbcde..3ab3203 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);


More information about the Libreoffice-commits mailing list