[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann
sbergman at redhat.com
Thu Aug 31 09:23:29 UTC 2017
compilerplugins/clang/constparams.cxx | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
New commits:
commit 72cfd4d024aa9deb68010824a804f252e37b8388
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Aug 31 11:13:38 2017 +0200
loplugin:constparams: Also handle ObjCObjectPointerType
...in 0660a30d54eb6762302cf1afd43de01e137f6393 "Avoid loplugin:constparam when
param is subject of cast to non-const pointer"
But turns out this whole avoidance is ill-advised and should eventually be
reverted:
Aug 31 09:09:26 <sberg> noelgrandin, the way you originally handled CastExpr in
constparam's checkIfCanBeConst, your intent was if there's code like
static_cast<T*>(p) and param p is found it can be made const, one would also
need to change that cast to static_cast<T const *>(p) when fixing the loplugin
warning, right?
Aug 31 09:09:43 <noelgrandin> sberg, correct
Aug 31 09:10:10 <sberg> noelgrandin, I messed the up with
0660a30d54eb6762302cf1afd43de01e137f6393
Aug 31 09:10:12 <IZBot> core - Avoid loplugin:constparam when param is subject
of cast to non-const pointer -
http://cgit.freedesktop.org/libreoffice/core/commit/?id=0660a30d54eb6762302cf1afd43de01e137f6393
Aug 31 09:10:24 <noelgrandin> sberg, I probably should have had a test for that
Aug 31 09:10:41 <noelgrandin> tests are better at expressing intent
Aug 31 09:10:56 <sberg> I ran across it in a function that needed to have the
param non-const for API reasons (callback fn), and it looked like the "obvious"
fix there, not needing to add the fn to the blacklist
Aug 31 09:11:26 <sberg> I'll eventually get that fixed again (but want to first
get the Mac and Windows builds to succeed)
Aug 31 09:11:44 <noelgrandin> fair enough
Change-Id: Idef0cfc417ec0597a26a29c8720e3e4051a68e00
diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx
index 0a52ba1c7726..0aec1e3d82c2 100644
--- a/compilerplugins/clang/constparams.cxx
+++ b/compilerplugins/clang/constparams.cxx
@@ -418,8 +418,13 @@ bool ConstParams::checkIfCanBeConst(const Stmt* stmt, const ParmVarDecl* parmVar
return false;
} else if (isa<CastExpr>(parent)) { // all other cast expression subtypes
if (auto e = dyn_cast<ExplicitCastExpr>(parent)) {
- loplugin::TypeCheck tc(e->getTypeAsWritten());
- if (tc.Pointer().NonConst() || tc.Void()) {
+ auto t = e->getTypeAsWritten();
+ if (t->isAnyPointerType()
+ && !t->getPointeeType().isConstQualified())
+ {
+ return false;
+ }
+ if (loplugin::TypeCheck(t).Void()) {
return false;
}
}
More information about the Libreoffice-commits
mailing list