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

Stephan Bergmann sbergman at redhat.com
Wed Aug 30 13:06:32 UTC 2017


 compilerplugins/clang/constparams.cxx |    6 ++++++
 1 file changed, 6 insertions(+)

New commits:
commit 0660a30d54eb6762302cf1afd43de01e137f6393
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Aug 30 14:57:46 2017 +0200

    Avoid loplugin:constparam when param is subject of cast to non-const pointer
    
    ...as in WriteCallback (desktop/source/minidump/minidump.cxx), where
    
      void *ptr
    
    is use in
    
      static_cast<char *>(ptr)
    
    Change-Id: I0bd44329029cd793390d0744de3c839612e0b494

diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx
index 3203fc59cd12..31c1bc29affa 100644
--- a/compilerplugins/clang/constparams.cxx
+++ b/compilerplugins/clang/constparams.cxx
@@ -418,6 +418,12 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar
     } else if (isa<CXXConstCastExpr>(parent)) {
         return false;
     } else if (isa<CastExpr>(parent)) { // all other cast expression subtypes
+        if (auto e = dyn_cast<ExplicitCastExpr>(parent)) {
+            if (loplugin::TypeCheck(e->getTypeAsWritten()).Pointer().NonConst())
+            {
+                return false;
+            }
+        }
         return checkIfCanBeConst(parent, parmVarDecl);
     } else if (isa<MemberExpr>(parent)) {
         return checkIfCanBeConst(parent, parmVarDecl);


More information about the Libreoffice-commits mailing list