diff options
author | Noel Grandin <noel@peralex.com> | 2014-08-28 08:58:48 +0200 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2014-09-07 02:42:30 -0500 |
commit | ed75aa271956824c89b7c9df2c06e4ad09a74734 (patch) | |
tree | 432c17088789736364b2932b9085e5b17a8cc71a | |
parent | 5ca2d1e26513095670b3fd2dce6a464a415cab89 (diff) |
create clang plugin to warn about C-style casts
We don't like C-style casts in our nice C++ code
Change-Id: I94e7ec90de9275cd6e20c4146d4f3a74bed93c9d
Reviewed-on: https://gerrit.libreoffice.org/10367
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
Tested-by: Norbert Thiebaud <nthiebaud@gmail.com>
-rw-r--r-- | compilerplugins/clang/cstylecast.cxx | 88 | ||||
-rw-r--r-- | extensions/source/nsplugin/source/npshell.cxx | 16 | ||||
-rw-r--r-- | idlc/inc/idlc/astdeclaration.hxx | 2 | ||||
-rw-r--r-- | idlc/inc/idlc/errorhandler.hxx | 2 | ||||
-rw-r--r-- | idlc/source/astdump.cxx | 16 | ||||
-rw-r--r-- | idlc/source/astenum.cxx | 4 | ||||
-rw-r--r-- | idlc/source/astinterface.cxx | 7 | ||||
-rw-r--r-- | idlc/source/astoperation.cxx | 2 | ||||
-rw-r--r-- | idlc/source/astscope.cxx | 6 | ||||
-rw-r--r-- | idlc/source/aststruct.cxx | 2 | ||||
-rw-r--r-- | idlc/source/errorhandler.cxx | 4 | ||||
-rw-r--r-- | idlc/source/fehelper.cxx | 4 | ||||
-rw-r--r-- | idlc/source/idlc.cxx | 40 | ||||
-rw-r--r-- | include/salhelper/dynload.hxx | 4 | ||||
-rw-r--r-- | include/tools/multisel.hxx | 4 | ||||
-rw-r--r-- | include/vcl/alpha.hxx | 2 | ||||
-rw-r--r-- | l10ntools/source/xmlparse.cxx | 12 |
17 files changed, 151 insertions, 64 deletions
diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx new file mode 100644 index 000000000000..5183e26ff27e --- /dev/null +++ b/compilerplugins/clang/cstylecast.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <string> +#include "plugin.hxx" +#include "compat.hxx" + +// +// We don't like using C-style casts in C++ code +// + +namespace { + +class CStyleCast: + public RecursiveASTVisitor<CStyleCast>, public loplugin::Plugin +{ +public: + explicit CStyleCast(InstantiationData const & data): Plugin(data) {} + + virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + + bool VisitCStyleCastExpr(const CStyleCastExpr * expr); +}; + +static const char * recommendedFix(clang::CastKind ck) { + switch(ck) { + case CK_IntegralToPointer: return "reinterpret_cast"; + case CK_PointerToIntegral: return "reinterpret_cast"; + case CK_BaseToDerived: return "static_cast"; + default: return "???"; + } +} + +bool CStyleCast::VisitCStyleCastExpr(const CStyleCastExpr * expr) { + if (ignoreLocation(expr)) { + return true; + } + // casting to void is typically used when a parameter or field is only used in + // debug mode, and we want to eliminate an "unused" warning + if( expr->getCastKind() == CK_ToVoid ) { + return true; + } + // ignore integral-type conversions for now, there is unsufficient agreement about + // the merits of C++ style casting in this case + if( expr->getCastKind() == CK_IntegralCast ) { + return true; + } + if( expr->getCastKind() == CK_NoOp ) { + return true; + } + // ignore pointer-type conversions for now + if( expr->getCastKind() == CK_BitCast ) { + return true; + } + SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( + expr->getLocStart()); + StringRef filename = compiler.getSourceManager().getFilename(spellingLocation); + // ignore C code + if ( filename.endswith(".h") || filename.endswith(".c") ) { + return true; + } + if ( compat::isInMainFile(compiler.getSourceManager(), spellingLocation) + ? (filename.startswith(SRCDIR "/sal")) // sal has tons of weird stuff going on that I don't understand enough to fix + : (filename.startswith(SRCDIR "/include/tools/solar.h")) ) { + return true; + } + report( + DiagnosticsEngine::Warning, + "c-style cast, type=%0, from=%1, recommendedFix=%2", + expr->getSourceRange().getBegin()) + << expr->getCastKind() + << expr->getSubExprAsWritten()->getType() + << recommendedFix(expr->getCastKind()) + << expr->getSourceRange(); + return true; +} + +loplugin::Plugin::Registration< CStyleCast > X("cstylecast"); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/nsplugin/source/npshell.cxx b/extensions/source/nsplugin/source/npshell.cxx index b73c3e8841d3..84aff99c9d5d 100644 --- a/extensions/source/nsplugin/source/npshell.cxx +++ b/extensions/source/nsplugin/source/npshell.cxx @@ -507,7 +507,7 @@ NPP_New(NPMIMEType pluginType, PLUGIN_MSG msg; memset((char*)&msg, 0, sizeof(PLUGIN_MSG)); msg.msg_id = SO_NEW_INSTANCE; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); if (!sendMsg(&msg, sizeof(PLUGIN_MSG), 1)) return NPERR_GENERIC_ERROR; @@ -528,7 +528,7 @@ NPP_Destroy(NPP instance, NPSavedData** /*save*/) PLUGIN_MSG msg; memset((char*)&msg, 0, sizeof(PLUGIN_MSG)); msg.msg_id = SO_DESTROY; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); #ifdef UNIX msg.wnd_id =(plugin_Int32)((PluginInstance*) instance->pdata)->window; #endif //end of UNIX @@ -580,14 +580,14 @@ NPP_SetWindow(NPP instance, NPWindow* window) PLUGIN_MSG msg; memset((char*)&msg, 0, sizeof(msg)); msg.msg_id = SO_SET_WINDOW; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); if ( window ) { // Set window info for instance #ifdef UNIX ws_info = (NPSetWindowCallbackStruct *)window->ws_info; - This->window = (Window) window->window; + This->window = reinterpret_cast<Window>( window->window); This->x = window->x; This->y = window->y; This->width = window->width; @@ -608,7 +608,7 @@ NPP_SetWindow(NPP instance, NPWindow* window) debug_fprintf(NSP_LOG_APPEND, "W=(%d) H=(%d)\n", window->width, window->height); // fill the window dependent part of the message - msg.wnd_id = (plugin_Int32) window->window; + msg.wnd_id = reinterpret_cast<plugin_Int32>(window->window); msg.wnd_x = window->x; msg.wnd_y = window->y; msg.wnd_w = window->width; @@ -815,7 +815,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) PLUGIN_MSG msg; memset((char*)&msg, 0, sizeof(PLUGIN_MSG)); msg.msg_id = SO_SET_URL; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); #ifdef UNIX msg.wnd_id =(plugin_Int32)(This->window); sprintf(msg.url, "file://%s", localPathNew); @@ -831,7 +831,7 @@ NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) // send SO_SET_WINDOW message // memset((char*)&msg, 0, sizeof(PLUGIN_MSG)); msg.msg_id = SO_SET_WINDOW; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); // msg.wnd_id =(plugin_Int32)((PluginInstance*) instance->pdata)->window; #ifdef UNIX msg.wnd_x = This->x; @@ -869,7 +869,7 @@ NPP_Print(NPP instance, NPPrint* printInfo) PLUGIN_MSG msg; memset((char*)&msg, 0, sizeof(PLUGIN_MSG)); msg.msg_id = SO_PRINT; - msg.instance_id = (plugin_Int32)instance; + msg.instance_id = reinterpret_cast<plugin_Int32>(instance); if(!sendMsg(&msg, sizeof(PLUGIN_MSG), 1)) debug_fprintf(NSP_LOG_APPEND, "NPP_StreamAsFile send SO_SET_WINDOW return failure \n"); /**************************************/ diff --git a/idlc/inc/idlc/astdeclaration.hxx b/idlc/inc/idlc/astdeclaration.hxx index caa35d6a1598..d7d7aec22274 100644 --- a/idlc/inc/idlc/astdeclaration.hxx +++ b/idlc/inc/idlc/astdeclaration.hxx @@ -75,6 +75,8 @@ public: { return m_fullName.getStr()+1; } AstScope* getScope() { return m_pScope; } + const AstScope* getScope() const + { return m_pScope; } void setScope(AstScope* pSc) { m_pScope = pSc; } NodeType getNodeType() const diff --git a/idlc/inc/idlc/errorhandler.hxx b/idlc/inc/idlc/errorhandler.hxx index 9877f081221f..1e7e7285d0d8 100644 --- a/idlc/inc/idlc/errorhandler.hxx +++ b/idlc/inc/idlc/errorhandler.hxx @@ -118,7 +118,7 @@ public: void flagError(ErrorCode e, sal_uInt32 flag); - void forwardLookupError(AstDeclaration* pForward, const OString& name); + void forwardLookupError(const AstDeclaration* pForward, const OString& name); void constantExpected(AstDeclaration* pDecl, const OString& name); diff --git a/idlc/source/astdump.cxx b/idlc/source/astdump.cxx index 6e052fbb6046..d4bbc196b3d2 100644 --- a/idlc/source/astdump.cxx +++ b/idlc/source/astdump.cxx @@ -77,7 +77,7 @@ bool AstModule::dump(RegistryKey& rKey) if ( pDecl->getNodeType() == NT_const && pDecl->isInMainfile() ) { - ((AstConstant*)pDecl)->dumpBlob( + static_cast<AstConstant*>(pDecl)->dumpBlob( aBlob, index++, getNodeType() == NT_module && pDecl->isPublished()); } @@ -197,7 +197,7 @@ bool AstService::dump(RegistryKey& rKey) case NT_service_member: if (getNodeType() == NT_singleton) { OSL_ASSERT(superName.isEmpty()); - superName = ((AstServiceMember *)(*i))-> + superName = (static_cast<AstServiceMember *>(*i))-> getRealService()->getRelativName(); break; } @@ -247,16 +247,16 @@ bool AstService::dump(RegistryKey& rKey) { switch ((*i)->getNodeType()) { case NT_operation: - ((AstOperation *)(*i))->dumpBlob(writer, constructorIndex++); + static_cast<AstOperation *>(*i)->dumpBlob(writer, constructorIndex++); break; case NT_property: - ((AstAttribute *)(*i))->dumpBlob(writer, propertyIndex++, 0); + static_cast<AstAttribute *>(*i)->dumpBlob(writer, propertyIndex++, 0); break; case NT_interface_member: { - AstInterfaceMember * decl = (AstInterfaceMember *)(*i); + AstInterfaceMember * decl = static_cast<AstInterfaceMember *>(*i); writer.setReferenceData( referenceIndex++, decl->getDocumentation(), RT_REF_SUPPORTS, (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID), @@ -268,7 +268,7 @@ bool AstService::dump(RegistryKey& rKey) case NT_service_member: if (getNodeType() == NT_service) { - AstServiceMember * decl = (AstServiceMember *)(*i); + AstServiceMember * decl = static_cast<AstServiceMember *>(*i); writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_EXPORTS, (decl->isOptional() ? RT_ACCESS_OPTIONAL : RT_ACCESS_INVALID), OStringToOUString(decl->getRealService()->getRelativName(), @@ -278,7 +278,7 @@ bool AstService::dump(RegistryKey& rKey) case NT_observes: { - AstObserves * decl = (AstObserves *)(*i); + AstObserves * decl = static_cast<AstObserves *>(*i); writer.setReferenceData(referenceIndex++, decl->getDocumentation(), RT_REF_OBSERVES, RT_ACCESS_INVALID, OStringToOUString( decl->getRealInterface()->getRelativName(), @@ -288,7 +288,7 @@ bool AstService::dump(RegistryKey& rKey) case NT_needs: { - AstNeeds * decl = (AstNeeds *)(*i); + AstNeeds * decl = static_cast<AstNeeds *>(*i); writer.setReferenceData( referenceIndex++, decl->getDocumentation(), RT_REF_NEEDS, RT_ACCESS_INVALID, OStringToOUString( decl->getRealService()->getRelativName(), diff --git a/idlc/source/astenum.cxx b/idlc/source/astenum.cxx index 13bd8774f651..a0df33199ec5 100644 --- a/idlc/source/astenum.cxx +++ b/idlc/source/astenum.cxx @@ -45,7 +45,7 @@ AstConstant* AstEnum::checkValue(AstExpression* pExpr) while ( iter != end) { pDecl = *iter; - pConst = (AstConstant*)pDecl; + pConst = static_cast<AstConstant*>(pDecl); if (pConst->getConstValue()->compare(pExpr)) return pConst; @@ -88,7 +88,7 @@ bool AstEnum::dump(RegistryKey& rKey) { pDecl = *iter; if ( pDecl->getNodeType() == NT_enum_val ) - ((AstConstant*)pDecl)->dumpBlob(aBlob, index++, false); + static_cast<AstConstant*>(pDecl)->dumpBlob(aBlob, index++, false); ++iter; } diff --git a/idlc/source/astinterface.cxx b/idlc/source/astinterface.cxx index 3fd0a7e1845a..7f097fd23555 100644 --- a/idlc/source/astinterface.cxx +++ b/idlc/source/astinterface.cxx @@ -140,7 +140,7 @@ bool AstInterface::dump(RegistryKey& rKey) if (!increment(&nAttributes, "attributes")) { return false; } - AstAttribute * attr = (AstAttribute *)(*i); + AstAttribute * attr = static_cast<AstAttribute *>(*i); if (attr->isBound()) { version = TYPEREG_VERSION_1; } @@ -227,13 +227,12 @@ bool AstInterface::dump(RegistryKey& rKey) { switch ((*i)->getNodeType()) { case NT_attribute: - - ((AstAttribute *)(*i))->dumpBlob( + static_cast<AstAttribute *>(*i)->dumpBlob( aBlob, attributeIndex++, &methodIndex); break; case NT_operation: - ((AstOperation *)(*i))->dumpBlob(aBlob, methodIndex++); + static_cast<AstOperation *>(*i)->dumpBlob(aBlob, methodIndex++); break; default: diff --git a/idlc/source/astoperation.cxx b/idlc/source/astoperation.cxx index 55e52931dfbb..cae75fe0027e 100644 --- a/idlc/source/astoperation.cxx +++ b/idlc/source/astoperation.cxx @@ -70,7 +70,7 @@ bool AstOperation::dumpBlob(typereg::Writer & rBlob, sal_uInt16 index) pDecl = *iter; if ( pDecl->getNodeType() == NT_parameter ) { - AstParameter* pParam = (AstParameter*)pDecl; + AstParameter* pParam = static_cast<AstParameter*>(pDecl); switch (pParam->getDirection()) { case DIR_IN : diff --git a/idlc/source/astscope.cxx b/idlc/source/astscope.cxx index cc0812664181..caa2dc3cb20d 100644 --- a/idlc/source/astscope.cxx +++ b/idlc/source/astscope.cxx @@ -60,7 +60,7 @@ AstDeclaration* AstScope::addDeclaration(AstDeclaration* pDecl) } if ( (pDeclaration->getNodeType() == NT_interface) && (pDecl->getNodeType() == NT_interface) - && !((AstInterface*)pDeclaration)->isDefined() ) + && !(static_cast<AstInterface*>(pDeclaration)->isDefined()) ) { m_declarations.push_back(pDecl); return pDecl; @@ -214,7 +214,7 @@ AstDeclaration* AstScope::lookupByNameLocal(const OString& name) const AstDeclaration* AstScope::lookupInInherited(const OString& scopedName) const { - AstInterface* pInterface = (AstInterface*)this; + const AstInterface* pInterface = dynamic_cast<const AstInterface*>(this); if ( !pInterface ) return NULL; @@ -313,7 +313,7 @@ AstDeclaration* AstScope::lookupPrimitiveType(ExprType type) if ( pDecl && (pDecl->getNodeType() == NT_predefined) ) { - AstBaseType* pBaseType = (AstBaseType*)pDecl; + AstBaseType* pBaseType = static_cast<AstBaseType*>(pDecl); if ( pBaseType->getExprType() == type ) return pDecl; diff --git a/idlc/source/aststruct.cxx b/idlc/source/aststruct.cxx index abc4bfed843b..7c42d1692ad0 100644 --- a/idlc/source/aststruct.cxx +++ b/idlc/source/aststruct.cxx @@ -131,7 +131,7 @@ bool AstStruct::dump(RegistryKey& rKey) pDecl = *iter; if ( pDecl->getNodeType() == NT_member ) { - pMember = (AstMember*)pDecl; + pMember = static_cast<AstMember*>(pDecl); RTFieldAccess flags = RT_ACCESS_READWRITE; OString typeName; if (pMember->getType()->getNodeType() == NT_type_parameter) { diff --git a/idlc/source/errorhandler.cxx b/idlc/source/errorhandler.cxx index 6a99b669e72f..b7b6e799be3a 100644 --- a/idlc/source/errorhandler.cxx +++ b/idlc/source/errorhandler.cxx @@ -564,7 +564,7 @@ void ErrorHandler::inheritanceError(NodeType nodeType, const OString* name, AstD { if ( nodeType == NT_interface && (pDecl->getNodeType() == NT_interface) && - !((AstInterface*)pDecl)->isDefined() ) + !(static_cast<AstInterface*>(pDecl)->isDefined()) ) { errorHeader(EIDL_INHERIT_FWD_ERROR); fprintf(stderr, "interface '%s' cannot inherit from forward declared interface '%s'\n", @@ -579,7 +579,7 @@ void ErrorHandler::inheritanceError(NodeType nodeType, const OString* name, AstD idlc()->incErrorCount(); } -void ErrorHandler::forwardLookupError(AstDeclaration* pForward, +void ErrorHandler::forwardLookupError(const AstDeclaration* pForward, const OString& name) { errorHeader(EIDL_FWD_DECL_LOOKUP); diff --git a/idlc/source/fehelper.cxx b/idlc/source/fehelper.cxx index 12636e1ef6a6..a11f4b053992 100644 --- a/idlc/source/fehelper.cxx +++ b/idlc/source/fehelper.cxx @@ -49,7 +49,7 @@ bool FeDeclarator::checkType(AstDeclaration const * type) AstType const * FeDeclarator::compose(AstDeclaration const * pDecl) { - AstType* pType; + const AstType* pType; if ( pDecl == 0 ) { @@ -60,7 +60,7 @@ AstType const * FeDeclarator::compose(AstDeclaration const * pDecl) idlc()->error()->noTypeError(pDecl); return NULL; } - pType = (AstType*)pDecl; + pType = static_cast<const AstType*>(pDecl); if (m_declType == FD_simple || m_pComplexPart == NULL) return pType; diff --git a/idlc/source/idlc.cxx b/idlc/source/idlc.cxx index bf7594eee467..2617c22c237c 100644 --- a/idlc/source/idlc.cxx +++ b/idlc/source/idlc.cxx @@ -48,22 +48,22 @@ AstDeclaration* SAL_CALL scopeAsDecl(AstScope* pScope) { case NT_service: case NT_singleton: - return (AstService*)(pScope); + return static_cast<AstService*>(pScope); case NT_module: case NT_root: - return (AstModule*)(pScope); + return static_cast<AstModule*>(pScope); case NT_constants: - return (AstConstants*)(pScope); + return static_cast<AstConstants*>(pScope); case NT_interface: - return (AstInterface*)(pScope); + return static_cast<AstInterface*>(pScope); case NT_operation: - return (AstOperation*)(pScope); + return static_cast<AstOperation*>(pScope); case NT_exception: - return (AstException*)(pScope); + return static_cast<AstException*>(pScope); case NT_struct: - return (AstStruct*)(pScope); + return static_cast<AstStruct*>(pScope); case NT_enum: - return (AstEnum*)(pScope); + return static_cast<AstEnum*>(pScope); default: return NULL; } @@ -76,23 +76,23 @@ AstScope* SAL_CALL declAsScope(AstDeclaration* pDecl) switch(pDecl->getNodeType()) { case NT_interface: - return (AstInterface*)(pDecl); + return static_cast<AstInterface*>(pDecl); case NT_service: case NT_singleton: - return (AstService*)(pDecl); + return static_cast<AstService*>(pDecl); case NT_module: case NT_root: - return (AstModule*)(pDecl); + return static_cast<AstModule*>(pDecl); case NT_constants: - return (AstConstants*)(pDecl); + return static_cast<AstConstants*>(pDecl); case NT_exception: - return (AstException*)(pDecl); + return static_cast<AstException*>(pDecl); case NT_struct: - return (AstStruct*)(pDecl); + return static_cast<AstStruct*>(pDecl); case NT_enum: - return (AstEnum*)(pDecl); + return static_cast<AstEnum*>(pDecl); case NT_operation: - return (AstOperation*)(pDecl); + return static_cast<AstOperation*>(pDecl); default: return NULL; } @@ -127,21 +127,21 @@ static void SAL_CALL predefineXInterface(AstModule* pRoot) pParentScope->addDeclaration(pInterface); // define XInterface::queryInterface - AstOperation* pOp = new AstOperation((AstType*)(pRoot->lookupPrimitiveType(ET_any)), + AstOperation* pOp = new AstOperation(static_cast<AstType*>(pRoot->lookupPrimitiveType(ET_any)), OString("queryInterface"), pInterface); AstParameter* pParam = new AstParameter(DIR_IN, false, - (AstType*)(pRoot->lookupPrimitiveType(ET_type)), + static_cast<AstType*>(pRoot->lookupPrimitiveType(ET_type)), OString("aType"), pOp); pOp->addDeclaration(pParam); pInterface->addMember(pOp); // define XInterface::acquire - pOp = new AstOperation((AstType*)(pRoot->lookupPrimitiveType(ET_void)), + pOp = new AstOperation(static_cast<AstType*>(pRoot->lookupPrimitiveType(ET_void)), OString("acquire"), pInterface); pInterface->addMember(pOp); // define XInterface::release - pOp = new AstOperation((AstType*)(pRoot->lookupPrimitiveType(ET_void)), + pOp = new AstOperation(static_cast<AstType*>(pRoot->lookupPrimitiveType(ET_void)), OString("release"), pInterface); pInterface->addMember(pOp); } diff --git a/include/salhelper/dynload.hxx b/include/salhelper/dynload.hxx index d4942b8b6a53..91d70c12d2a6 100644 --- a/include/salhelper/dynload.hxx +++ b/include/salhelper/dynload.hxx @@ -172,13 +172,13 @@ public: /// returns a poiner to the initialized API function structure. API* SAL_CALL getApi() const { - return (API*)m_pLoader->getApi(); + return static_cast<API*>(m_pLoader->getApi()); } /// cast operator, which cast to a poiner with the initialized API function structure. API* SAL_CALL operator->() const { - return (API*)m_pLoader->getApi(); + return static_cast<API*>(m_pLoader->getApi()); } /// checks if the loader works on a loaded and initialized library. diff --git a/include/tools/multisel.hxx b/include/tools/multisel.hxx index 83841ce6a377..bac6fe8e8ff6 100644 --- a/include/tools/multisel.hxx +++ b/include/tools/multisel.hxx @@ -80,9 +80,7 @@ public: long NextSelected(); size_t GetRangeCount() const { return aSels.size(); } - const Range& GetRange( size_t nRange ) const { - return *(const Range*)aSels[nRange]; - } + const Range& GetRange( size_t nRange ) const { return *aSels[nRange]; } }; class TOOLS_DLLPUBLIC StringRangeEnumerator diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx index de3b4513e4f8..bd8ce8a10b9c 100644 --- a/include/vcl/alpha.hxx +++ b/include/vcl/alpha.hxx @@ -51,7 +51,7 @@ public: AlphaMask& operator=( const Bitmap& rBitmap ); AlphaMask& operator=( const AlphaMask& rAlphaMask ) { - return (AlphaMask&) Bitmap::operator=( rAlphaMask ); + return static_cast<AlphaMask&>( Bitmap::operator=( rAlphaMask ) ); } bool operator!() const diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 0e74383ecd39..2c376cf8c675 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -188,7 +188,7 @@ bool XMLFile::Write( ofstream &rStream , XMLNode *pCur ) break; case XML_NODE_TYPE_ELEMENT: { - XMLElement *pElement = ( XMLElement * ) pCur; + XMLElement *pElement = static_cast<XMLElement*>(pCur); rStream << "<"; rStream << pElement->GetName().getStr(); if ( pElement->GetAttributeList()) @@ -257,7 +257,7 @@ void XMLFile::Print( XMLNode *pCur, sal_uInt16 nLevel ) break; case XML_NODE_TYPE_ELEMENT: { - XMLElement *pElement = ( XMLElement * ) pCur; + XMLElement *pElement = static_cast<XMLElement*>(pCur); fprintf( stdout, "<%s", pElement->GetName().getStr()); if ( pElement->GetAttributeList()) @@ -467,7 +467,7 @@ void XMLFile::SearchL10NElements( XMLChildNode *pCur, int nPos ) break; case XML_NODE_TYPE_ELEMENT: { - XMLElement *pElement = ( XMLElement * ) pCur; + XMLElement *pElement = static_cast<XMLElement*>(pCur); const OString sName(pElement->GetName().toAsciiLowerCase()); OString sLanguage, sTmpStrVal, sOldref; if ( pElement->GetAttributeList()) @@ -534,7 +534,7 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur ) { for ( size_t i = 0; i < GetChildList()->size(); i++ ) { - pElement = (XMLParentNode*)(*GetChildList())[ i ]; + pElement = static_cast<XMLParentNode*>((*GetChildList())[ i ]); if( pElement->GetNodeType() == XML_NODE_TYPE_ELEMENT ) CheckExportStatus( pElement );//, i); } } @@ -542,7 +542,7 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur ) break; case XML_NODE_TYPE_ELEMENT: { - XMLElement *pElement = ( XMLElement * ) pCur; + XMLElement *pElement = static_cast<XMLElement*>(pCur); if (pElement->GetName().equalsIgnoreAsciiCase("TOPIC")) { if ( pElement->GetAttributeList()) @@ -566,7 +566,7 @@ bool XMLFile::CheckExportStatus( XMLParentNode *pCur ) else if ( pElement->GetChildList() ) { for (size_t k = 0; k < pElement->GetChildList()->size(); ++k) - CheckExportStatus( (XMLParentNode*)(*pElement->GetChildList())[k] ); + CheckExportStatus( static_cast<XMLParentNode*>((*pElement->GetChildList())[k]) ); } } break; |