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

Stephan Bergmann sbergman at redhat.com
Fri Jan 9 07:43:09 PST 2015


 binaryurp/source/unmarshal.cxx       |    2 +-
 compilerplugins/clang/cstylecast.cxx |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit 31498259bb801dee7bb2d7cb2b40162876116aa4
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jan 9 16:42:09 2015 +0100

    loplugin:cstylecast: warn about certain redundant reinterpret_casts
    
    Change-Id: Iaa46849742c215798722d03d9ee59bb39d8033f7

diff --git a/binaryurp/source/unmarshal.cxx b/binaryurp/source/unmarshal.cxx
index d04c889..f34bfd3 100644
--- a/binaryurp/source/unmarshal.cxx
+++ b/binaryurp/source/unmarshal.cxx
@@ -465,7 +465,7 @@ BinaryAny Unmarshal::readSequence(css::uno::TypeDescription const & type) {
             static_cast< sal_Sequence * >(buf)->elements + i * ctd.get()->nSize,
             const_cast< void * >(as[i].getValue(ctd)), ctd.get(), 0);
     }
-    return BinaryAny(type, reinterpret_cast< sal_Sequence ** >(&buf));
+    return BinaryAny(type, &buf);
 }
 
 void Unmarshal::readMemberValues(
diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx
index 53b7d88..4f8bd4b 100644
--- a/compilerplugins/clang/cstylecast.cxx
+++ b/compilerplugins/clang/cstylecast.cxx
@@ -47,6 +47,8 @@ public:
 
     bool VisitCStyleCastExpr(const CStyleCastExpr * expr);
 
+    bool VisitImplicitCastExpr(ImplicitCastExpr const * expr);
+
 private:
     bool externCFunction;
 };
@@ -136,6 +138,32 @@ bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) {
     return true;
 }
 
+bool CStyleCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
+    if (ignoreLocation(expr) || expr->getCastKind() != CK_BitCast) {
+        return true;
+    }
+    QualType t = expr->getType();
+    if (!(t->isPointerType()
+          && t->getAs<PointerType>()->getPointeeType()->isVoidType()
+          && expr->getSubExpr()->getType()->isPointerType()))
+    {
+        return true;
+    }
+    Expr const * e = expr->getSubExpr()->IgnoreParenImpCasts();
+    while (isa<CXXConstCastExpr>(e)) {
+        e = dyn_cast<CXXConstCastExpr>(e)->getSubExpr()->IgnoreParenImpCasts();
+    }
+    if (isa<CXXReinterpretCastExpr>(e)) {
+        report(
+            DiagnosticsEngine::Warning,
+            ("redundant reinterpret_cast, result is implicitly cast to void"
+             " pointer"),
+            e->getExprLoc())
+            << e->getSourceRange();
+    }
+    return true;
+}
+
 loplugin::Plugin::Registration< CStyleCast > X("cstylecast");
 
 }


More information about the Libreoffice-commits mailing list