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

Noel Grandin noel.grandin at collabora.co.uk
Tue Aug 15 13:47:02 UTC 2017


 compilerplugins/clang/redundantcast.cxx |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 3281628e1cf66f51f414436cd2002e0a63ec4750
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Aug 15 15:43:31 2017 +0200

    loplugin:redundantcast ignore functional casts involving typedefs
    
    <sberg> noelgrandin, 718cdd43c25783d9cd402e381123efe3981cc514 now also
    looks through typedef sugar, e.g. complaining about a gdouble -> double
    expl. conversion in configmgr/source/dconf.cxx;
    I think we want to remain silent about such conversions involving typedefs
    <noelgrandin> sberg, ah, good point.
    
    Change-Id: Icbb0d6be273f53e507c91556cf0ccb5a5c03e5a1
    Reviewed-on: https://gerrit.libreoffice.org/41175
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index 56afdf13f090..b9f97dce0c6b 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -633,9 +633,13 @@ bool RedundantCast::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr const * exp
     }
 
     auto const t1 = expr->getTypeAsWritten();
-    auto const t2 = sub->getType().getDesugaredType(compiler.getASTContext());
+    auto const t2 = sub->getType().getDesugaredType(compiler.getASTContext()); // look through templated wrapped types
     if (t1 != t2)
         return true;
+    // if we are casting from/to a typedef, ignore it, even if the underlying types are the same
+    if ((loplugin::TypeCheck(t1).Typedef() || loplugin::TypeCheck(sub->getType()).Typedef())
+        && t1 != sub->getType())
+        return true;
     if (!isOkToRemoveArithmeticCast(t1, t2, expr->getSubExpr()))
         return true;
     report(


More information about the Libreoffice-commits mailing list