diff options
-rw-r--r-- | basic/source/sbx/sbxvar.cxx | 56 | ||||
-rw-r--r-- | compilerplugins/clang/deadclass.cxx | 74 | ||||
-rw-r--r-- | compilerplugins/clang/test/deadclass.cxx | 14 | ||||
-rw-r--r-- | include/basic/sbx.hxx | 12 | ||||
-rw-r--r-- | sc/source/filter/inc/biffcodec.hxx | 37 | ||||
-rw-r--r-- | sc/source/filter/oox/biffcodec.cxx | 99 | ||||
-rw-r--r-- | solenv/CompilerTest_compilerplugins_clang.mk | 1 |
7 files changed, 89 insertions, 204 deletions
diff --git a/basic/source/sbx/sbxvar.cxx b/basic/source/sbx/sbxvar.cxx index 2e0d49c927a2..df30aad6ebe8 100644 --- a/basic/source/sbx/sbxvar.cxx +++ b/basic/source/sbx/sbxvar.cxx @@ -624,62 +624,6 @@ SbxInfo::SbxInfo( const OUString& r, sal_uInt32 n ) : aHelpFile( r ), nHelpId( n ) {} -// SbxAlias - -SbxAlias::SbxAlias( const SbxAlias& r ) - : SvRefBase( r ), SbxVariable( r ), - SfxListener( r ), xAlias( r.xAlias ) -{} - -SbxAlias& SbxAlias::operator=( const SbxAlias& r ) -{ - xAlias = r.xAlias; - return *this; -} - -SbxAlias::~SbxAlias() -{ - if( xAlias.is() ) - { - EndListening( xAlias->GetBroadcaster() ); - } -} - -void SbxAlias::Broadcast( SfxHintId nHt ) -{ - if( xAlias.is() ) - { - xAlias->SetParameters( GetParameters() ); - if( nHt == SfxHintId::BasicDataWanted ) - { - SbxVariable::operator=( *xAlias ); - } - else if( nHt == SfxHintId::BasicDataChanged || nHt == SfxHintId::BasicConverted ) - { - *xAlias = *this; - } - else if( nHt == SfxHintId::BasicInfoWanted ) - { - xAlias->Broadcast( nHt ); - pInfo = xAlias->GetInfo(); - } - } -} - -void SbxAlias::Notify( SfxBroadcaster&, const SfxHint& rHint ) -{ - const SbxHint* p = dynamic_cast<const SbxHint*>(&rHint); - if( p && p->GetId() == SfxHintId::BasicDying ) - { - xAlias.clear(); - // delete the alias? - if( pParent ) - { - pParent->Remove( this ); - } - } -} - void SbxVariable::Dump( SvStream& rStrm, bool bFill ) { OString aBNameStr(OUStringToOString(GetName( SbxNameType::ShortTypes ), RTL_TEXTENCODING_ASCII_US)); diff --git a/compilerplugins/clang/deadclass.cxx b/compilerplugins/clang/deadclass.cxx new file mode 100644 index 000000000000..1c14dd52d136 --- /dev/null +++ b/compilerplugins/clang/deadclass.cxx @@ -0,0 +1,74 @@ +/* -*- 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 "plugin.hxx" + +namespace { + +class DeadClass: + public RecursiveASTVisitor<DeadClass>, public loplugin::Plugin +{ +public: + explicit DeadClass(InstantiationData const & data): Plugin(data) {} + + void run() override; + + bool VisitCXXRecordDecl(CXXRecordDecl const *); +}; + +void DeadClass::run() { + if (compiler.getLangOpts().CPlusPlus) { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } +} + +bool DeadClass::VisitCXXRecordDecl(CXXRecordDecl const * decl) { + if (ignoreLocation(decl) || !decl->isThisDeclarationADefinition()) + return true; + if (decl->needsImplicitDefaultConstructor()) + return true; + if (decl->getDescribedClassTemplate()) + return true; + if (isa<ClassTemplateSpecializationDecl>(decl)) + return true; + int otherCnt = 0; + int copyMoveCnt = 0; + for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) { + if (!i->isUserProvided()) + continue; +// if (i->getTemplatedKind() != clang::FunctionDecl::TK_NonTemplate) +// return true; +// if (i->getTemplateInstantiationPattern()) +// return true; + if (i->isCopyOrMoveConstructor()) + copyMoveCnt++; + else + otherCnt++; + } + if (otherCnt == 0 && copyMoveCnt > 0) + { + report( + DiagnosticsEngine::Warning, + "class has only copy/move constructors, must be dead", + decl->getLocStart()) + << decl->getSourceRange(); + for (auto i = decl->ctor_begin(); i != decl->ctor_end(); ++i) { + if (i->isDeleted()) + continue; + i->dump(); + } + } + return true; +} + +loplugin::Plugin::Registration<DeadClass> X("deadclass"); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/test/deadclass.cxx b/compilerplugins/clang/test/deadclass.cxx new file mode 100644 index 000000000000..d8b9cdb60889 --- /dev/null +++ b/compilerplugins/clang/test/deadclass.cxx @@ -0,0 +1,14 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +struct Foo { // expected-error {{class has only copy/move constructors, must be dead [loplugin:deadclass]}} + Foo(Foo&); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/basic/sbx.hxx b/include/basic/sbx.hxx index 0e905fd333b1..45d00555ec3d 100644 --- a/include/basic/sbx.hxx +++ b/include/basic/sbx.hxx @@ -97,18 +97,6 @@ public: SbxVariable* GetVar() const { return pVar; } }; -// SbxAlias is an alias for a var or object -class BASIC_DLLPUBLIC SbxAlias : public SbxVariable, public SfxListener -{ - SbxVariableRef xAlias; - virtual ~SbxAlias() override; - virtual void Broadcast( SfxHintId ) override; - virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; -public: - SbxAlias( const SbxAlias& ); - SbxAlias& operator=( const SbxAlias& ); -}; - // SbxArray is an unidimensional, dynamic Array // The variables convert from SbxVariablen. Put()/Insert() into the // declared datatype, if they are not SbxVARIANT. diff --git a/sc/source/filter/inc/biffcodec.hxx b/sc/source/filter/inc/biffcodec.hxx index 4548ff6a9b4a..6375b52e1e3a 100644 --- a/sc/source/filter/inc/biffcodec.hxx +++ b/sc/source/filter/inc/biffcodec.hxx @@ -54,43 +54,6 @@ private: bool mbValid; /// True = decoder is correctly initialized. }; -/** Decodes BIFF stream contents that are encoded using the old XOR algorithm. */ -class BiffDecoder_XOR : public BiffDecoderBase -{ -private: - /** Copy constructor for cloning. */ - BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder ); - - /** Implements password verification and initialization of the decoder. */ - virtual css::uno::Sequence< css::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) override; - virtual bool implVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override; - -private: - ::oox::core::BinaryCodec_XOR maCodec; /// Cipher algorithm implementation. - css::uno::Sequence< css::beans::NamedValue > maEncryptionData; - sal_uInt16 mnKey; - sal_uInt16 mnHash; -}; - -/** Decodes BIFF stream contents that are encoded using the RC4 algorithm. */ -class BiffDecoder_RCF : public BiffDecoderBase -{ -private: - /** Copy constructor for cloning. */ - BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder ); - - /** Implements password verification and initialization of the decoder. */ - virtual css::uno::Sequence< css::beans::NamedValue > implVerifyPassword( const OUString& rPassword ) override; - virtual bool implVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override; - -private: - ::oox::core::BinaryCodec_RCF maCodec; /// Cipher algorithm implementation. - css::uno::Sequence< css::beans::NamedValue > maEncryptionData; - ::std::vector< sal_uInt8 > maSalt; - ::std::vector< sal_uInt8 > maVerifier; - ::std::vector< sal_uInt8 > maVerifierHash; -}; - } // namespace xls } // namespace oox diff --git a/sc/source/filter/oox/biffcodec.cxx b/sc/source/filter/oox/biffcodec.cxx index 4f924a3a3b5f..5c8e421301a3 100644 --- a/sc/source/filter/oox/biffcodec.cxx +++ b/sc/source/filter/oox/biffcodec.cxx @@ -52,105 +52,6 @@ BiffDecoderBase::~BiffDecoderBase() return mbValid ? ::comphelper::DocPasswordVerifierResult::OK : ::comphelper::DocPasswordVerifierResult::WrongPassword; } -BiffDecoder_XOR::BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder ) : - BiffDecoderBase(), // must be called to prevent compiler warning - maCodec(), - maEncryptionData( rDecoder.maEncryptionData ), - mnKey( rDecoder.mnKey ), - mnHash( rDecoder.mnHash ) -{ - if( isValid() ) - maCodec.initCodec( maEncryptionData ); -} - -Sequence< NamedValue > BiffDecoder_XOR::implVerifyPassword( const OUString& rPassword ) -{ - maEncryptionData.realloc( 0 ); - - /* Convert password to a byte string. TODO: this needs some finetuning - according to the spec... */ - OString aBytePassword = OUStringToOString( rPassword, osl_getThreadTextEncoding() ); - sal_Int32 nLen = aBytePassword.getLength(); - if( (0 < nLen) && (nLen < 16) ) - { - // init codec - maCodec.initKey( reinterpret_cast< const sal_uInt8* >( aBytePassword.getStr() ) ); - - if( maCodec.verifyKey( mnKey, mnHash ) ) - maEncryptionData = maCodec.getEncryptionData(); - } - - return maEncryptionData; -} - -bool BiffDecoder_XOR::implVerifyEncryptionData( const Sequence< NamedValue >& rEncryptionData ) -{ - maEncryptionData.realloc( 0 ); - - if( rEncryptionData.hasElements() ) - { - // init codec - maCodec.initCodec( rEncryptionData ); - - if( maCodec.verifyKey( mnKey, mnHash ) ) - maEncryptionData = rEncryptionData; - } - - return maEncryptionData.hasElements(); -} - - -BiffDecoder_RCF::BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder ) : - BiffDecoderBase(), // must be called to prevent compiler warning - maEncryptionData( rDecoder.maEncryptionData ), - maSalt( rDecoder.maSalt ), - maVerifier( rDecoder.maVerifier ), - maVerifierHash( rDecoder.maVerifierHash ) -{ - if( isValid() ) - maCodec.initCodec( maEncryptionData ); -} - -Sequence< NamedValue > BiffDecoder_RCF::implVerifyPassword( const OUString& rPassword ) -{ - maEncryptionData.realloc( 0 ); - - sal_Int32 nLen = rPassword.getLength(); - if( (0 < nLen) && (nLen < 16) ) - { - // copy string to sal_uInt16 array - ::std::vector< sal_uInt16 > aPassVect( 16 ); - const sal_Unicode* pcChar = rPassword.getStr(); - const sal_Unicode* pcCharEnd = pcChar + nLen; - ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin(); - for( ; pcChar < pcCharEnd; ++pcChar, ++aIt ) - *aIt = static_cast< sal_uInt16 >( *pcChar ); - - // init codec - maCodec.initKey(aPassVect.data(), maSalt.data()); - if (maCodec.verifyKey(maVerifier.data(), maVerifierHash.data())) - maEncryptionData = maCodec.getEncryptionData(); - } - - return maEncryptionData; -} - -bool BiffDecoder_RCF::implVerifyEncryptionData( const Sequence< NamedValue >& rEncryptionData ) -{ - maEncryptionData.realloc( 0 ); - - if( rEncryptionData.hasElements() ) - { - // init codec - maCodec.initCodec( rEncryptionData ); - - if (maCodec.verifyKey(maVerifier.data(), maVerifierHash.data())) - maEncryptionData = rEncryptionData; - } - - return maEncryptionData.hasElements(); -} - } // namespace xls } // namespace oox diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk index 22bbb1fcc9a1..c19a9134dc72 100644 --- a/solenv/CompilerTest_compilerplugins_clang.mk +++ b/solenv/CompilerTest_compilerplugins_clang.mk @@ -13,6 +13,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \ compilerplugins/clang/test/casttovoid \ compilerplugins/clang/test/constparams \ compilerplugins/clang/test/cppunitassertequals \ + compilerplugins/clang/test/deadclass \ compilerplugins/clang/test/datamembershadow \ compilerplugins/clang/test/externvar \ compilerplugins/clang/test/finalprotected \ |