compilerplugins/clang/redundantcast.cxx | 14 ++++++++++++++ compilerplugins/clang/test/redundantcast.cxx | 8 ++++++++ 2 files changed, 22 insertions(+)
New commits: commit d883e3556a77303919c84652fea0f603fa350311 Author: Stephan Bergmann <sberg...@redhat.com> Date: Tue Sep 26 08:35:32 2017 +0200 loplugin:redundantcast: cstyle_cast within reinterpret_cast Change-Id: Ie31c9dd6d8741aa856553b798bb5b7f695a3fe0f Reviewed-on: https://gerrit.libreoffice.org/42776 Reviewed-by: Stephan Bergmann <sberg...@redhat.com> Tested-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx index dba573387743..30914a460dc4 100644 --- a/compilerplugins/clang/redundantcast.cxx +++ b/compilerplugins/clang/redundantcast.cxx @@ -522,6 +522,20 @@ bool RedundantCast::VisitCXXReinterpretCastExpr( expr->getExprLoc()) << expr->getSubExprAsWritten()->getType() << expr->getType() << expr->getSourceRange(); + } else if (expr->getType()->isFundamentalType()) { + if (auto const sub = dyn_cast<CXXConstCastExpr>( + expr->getSubExpr()->IgnoreParens())) + { + report( + DiagnosticsEngine::Warning, + ("redundant const_cast from %0 to %1 within reinterpret_cast to" + " fundamental type %2"), + expr->getExprLoc()) + << sub->getSubExprAsWritten()->getType() + << sub->getTypeAsWritten() << expr->getTypeAsWritten() + << expr->getSourceRange(); + return true; + } } return true; } diff --git a/compilerplugins/clang/test/redundantcast.cxx b/compilerplugins/clang/test/redundantcast.cxx index 5a56ec42e32e..ff3e8392906a 100644 --- a/compilerplugins/clang/test/redundantcast.cxx +++ b/compilerplugins/clang/test/redundantcast.cxx @@ -7,6 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <cstddef> + #include "redundantcast.hxx" void f1(char *) {} @@ -318,12 +320,18 @@ void testArithmeticTypedefs() { (void) (T1) nt1r(); // expected-error {{redundant}} } +void testReinterpretConstCast() { + int n = 0; + (void) reinterpret_cast<std::size_t>((const_cast<int const *>(&n))); // expected-error-re {{redundant const_cast from 'int *' to 'const int *' within reinterpret_cast to fundamental type 'std::size_t' (aka 'unsigned {{.+}}') [loplugin:redundantcast]}} +} + int main() { testConstCast(); testStaticCast(); testFunctionalCast(); testCStyleCast(); testCStyleCastOfTemplateMethodResult(nullptr); + testReinterpretConstCast(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits