basic/source/sbx/sbxvar.cxx | 56 --------------- compilerplugins/clang/deadclass.cxx | 74 ++++++++++++++++++++ compilerplugins/clang/test/deadclass.cxx | 14 +++ cui/source/dialogs/SpellAttrib.cxx | 36 --------- cui/source/dialogs/SpellAttrib.hxx | 11 --- include/basic/sbx.hxx | 12 --- include/vcl/txtattr.hxx | 16 ---- sc/source/filter/inc/biffcodec.hxx | 37 ---------- sc/source/filter/oox/biffcodec.cxx | 99 --------------------------- solenv/CompilerTest_compilerplugins_clang.mk | 1 vcl/source/edit/textdoc.cxx | 16 +--- vcl/source/edit/txtattr.cxx | 27 ------- 12 files changed, 98 insertions(+), 301 deletions(-)
New commits: commit 7634b279a53e7212925566e0de25d721fa7598ac Author: Jochen Nitschke <j.nitschke+loger...@ok.de> Date: Fri Aug 11 11:39:20 2017 +0200 vcl: use default copy-ctor for TextAttrib Type of TextAttrib (mnWhich) never changes, const it up. Derived classes can use implicit default copy-ctor. No need to explicitly delete default-ctor if there is a user provided ctor. And no need to define a default override dtor here either. Change-Id: I7a0d1896f659801319dc5fa74844df94c5888a7b Reviewed-on: https://gerrit.libreoffice.org/41022 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/cui/source/dialogs/SpellAttrib.cxx b/cui/source/dialogs/SpellAttrib.cxx index b71449d98295..cc1b86c6a66a 100644 --- a/cui/source/dialogs/SpellAttrib.cxx +++ b/cui/source/dialogs/SpellAttrib.cxx @@ -32,18 +32,6 @@ SpellErrorAttrib::SpellErrorAttrib( const SpellErrorDescription& rDesc ) : } -SpellErrorAttrib::SpellErrorAttrib( const SpellErrorAttrib& rAttr ) : - TextAttrib(TEXTATTR_SPELL_ERROR), - m_aSpellErrorDescription( rAttr.m_aSpellErrorDescription ) -{ -} - - -SpellErrorAttrib::~SpellErrorAttrib() -{ -} - - void SpellErrorAttrib::SetFont( vcl::Font& ) const { //this attribute doesn't have a visual effect @@ -70,18 +58,6 @@ SpellLanguageAttrib::SpellLanguageAttrib(LanguageType eLang) : } -SpellLanguageAttrib::SpellLanguageAttrib( const SpellLanguageAttrib& rAttr ) : - TextAttrib(TEXTATTR_SPELL_LANGUAGE), - m_eLanguage(rAttr.m_eLanguage) -{ -} - - -SpellLanguageAttrib::~SpellLanguageAttrib() -{ -} - - void SpellLanguageAttrib::SetFont( vcl::Font& ) const { //no visual effect @@ -108,18 +84,6 @@ SpellBackgroundAttrib::SpellBackgroundAttrib(const Color& rCol) : } -SpellBackgroundAttrib::SpellBackgroundAttrib( const SpellBackgroundAttrib& rAttr ) : - TextAttrib(TEXTATTR_SPELL_BACKGROUND), - m_aBackgroundColor(rAttr.m_aBackgroundColor) -{ -} - - -SpellBackgroundAttrib::~SpellBackgroundAttrib() -{ -} - - void SpellBackgroundAttrib::SetFont( vcl::Font& rFont ) const { rFont.SetFillColor(m_aBackgroundColor); diff --git a/cui/source/dialogs/SpellAttrib.hxx b/cui/source/dialogs/SpellAttrib.hxx index 3ce4048d4021..aabf466235c3 100644 --- a/cui/source/dialogs/SpellAttrib.hxx +++ b/cui/source/dialogs/SpellAttrib.hxx @@ -96,11 +96,8 @@ public: private: SpellErrorDescription m_aSpellErrorDescription; - SpellErrorAttrib() = delete; public: SpellErrorAttrib( const SpellErrorDescription& ); - SpellErrorAttrib( const SpellErrorAttrib& rAttr ); - virtual ~SpellErrorAttrib() override; const SpellErrorDescription& GetErrorDescription() const { return m_aSpellErrorDescription; } @@ -115,12 +112,8 @@ class SpellLanguageAttrib : public TextAttrib { LanguageType m_eLanguage; - SpellLanguageAttrib() = delete; - public: SpellLanguageAttrib(LanguageType eLanguage); - SpellLanguageAttrib( const SpellLanguageAttrib& rAttr ); - virtual ~SpellLanguageAttrib() override; LanguageType GetLanguage() const {return m_eLanguage;} @@ -134,12 +127,8 @@ class SpellBackgroundAttrib : public TextAttrib { Color m_aBackgroundColor; - SpellBackgroundAttrib() = delete; - public: SpellBackgroundAttrib(const Color& rCol); - SpellBackgroundAttrib( const SpellBackgroundAttrib& rAttr ); - virtual ~SpellBackgroundAttrib() override; virtual void SetFont( vcl::Font& rFont ) const override; virtual TextAttrib* Clone() const override; diff --git a/include/vcl/txtattr.hxx b/include/vcl/txtattr.hxx index e446ee203563..8fadf98cc46f 100644 --- a/include/vcl/txtattr.hxx +++ b/include/vcl/txtattr.hxx @@ -39,11 +39,11 @@ namespace vcl { class Font; } class VCL_DLLPUBLIC TextAttrib { private: - sal_uInt16 mnWhich; + sal_uInt16 const mnWhich; protected: - TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; } - TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; } + TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {} + TextAttrib( const TextAttrib& ) = default; public: @@ -66,8 +66,6 @@ private: public: TextAttribFontColor( const Color& rColor ); - TextAttribFontColor( const TextAttribFontColor& rAttr ); - virtual ~TextAttribFontColor() override; const Color& GetColor() const { return maColor; } @@ -84,8 +82,6 @@ private: public: TextAttribFontWeight( FontWeight eWeight ); - TextAttribFontWeight( const TextAttribFontWeight& rAttr ); - virtual ~TextAttribFontWeight() override; virtual void SetFont( vcl::Font& rFont ) const override; virtual TextAttrib* Clone() const override; @@ -98,8 +94,6 @@ class VCL_DLLPUBLIC TextAttribProtect : public TextAttrib { public: TextAttribProtect(); - TextAttribProtect( const TextAttribProtect& rAttr ); - virtual ~TextAttribProtect() override; virtual void SetFont( vcl::Font& rFont ) const override; virtual TextAttrib* Clone() const override; @@ -116,13 +110,9 @@ private: sal_Int32 mnStart; sal_Int32 mnEnd; -protected: - public: - TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd ); TextCharAttrib( const TextCharAttrib& rTextCharAttrib ); - ~TextCharAttrib(); const TextAttrib& GetAttr() const { return *mpAttr; } diff --git a/vcl/source/edit/textdoc.cxx b/vcl/source/edit/textdoc.cxx index dce76e1cc0b6..25b19fb521c4 100644 --- a/vcl/source/edit/textdoc.cxx +++ b/vcl/source/edit/textdoc.cxx @@ -29,20 +29,16 @@ static bool CompareStart( const std::unique_ptr<TextCharAttrib>& pFirst, const s } TextCharAttrib::TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd ) + : mpAttr(rAttr.Clone()) + , mnStart(nStart) + , mnEnd(nEnd) { - mpAttr.reset( rAttr.Clone() ); - mnStart = nStart; - mnEnd = nEnd; } TextCharAttrib::TextCharAttrib( const TextCharAttrib& rTextCharAttrib ) -{ - mpAttr.reset( rTextCharAttrib.GetAttr().Clone() ); - mnStart = rTextCharAttrib.mnStart; - mnEnd = rTextCharAttrib.mnEnd; -} - -TextCharAttrib::~TextCharAttrib() + : mpAttr(rTextCharAttrib.mpAttr->Clone()) + , mnStart(rTextCharAttrib.mnStart) + , mnEnd(rTextCharAttrib.mnEnd) { } diff --git a/vcl/source/edit/txtattr.cxx b/vcl/source/edit/txtattr.cxx index 4065995314ec..f1a6e1ea6b0c 100644 --- a/vcl/source/edit/txtattr.cxx +++ b/vcl/source/edit/txtattr.cxx @@ -34,15 +34,6 @@ TextAttribFontColor::TextAttribFontColor( const Color& rColor ) { } -TextAttribFontColor::TextAttribFontColor( const TextAttribFontColor& rAttr ) - : TextAttrib( rAttr ), maColor( rAttr.maColor ) -{ -} - -TextAttribFontColor::~TextAttribFontColor() -{ -} - void TextAttribFontColor::SetFont( vcl::Font& rFont ) const { rFont.SetColor( maColor ); @@ -64,15 +55,6 @@ TextAttribFontWeight::TextAttribFontWeight( FontWeight eWeight ) { } -TextAttribFontWeight::TextAttribFontWeight( const TextAttribFontWeight& rAttr ) - : TextAttrib( rAttr ), meWeight( rAttr.meWeight ) -{ -} - -TextAttribFontWeight::~TextAttribFontWeight() -{ -} - void TextAttribFontWeight::SetFont( vcl::Font& rFont ) const { rFont.SetWeight( meWeight ); @@ -94,15 +76,6 @@ TextAttribProtect::TextAttribProtect() : { } -TextAttribProtect::TextAttribProtect( const TextAttribProtect&) : - TextAttrib( TEXTATTR_PROTECTED ) -{ -} - -TextAttribProtect::~TextAttribProtect() -{ -} - void TextAttribProtect::SetFont( vcl::Font& ) const { } commit 4d89865ef2026f40a9a4d66f3e047b77454e6fee Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Fri Aug 11 14:55:50 2017 +0200 new loplugin:deadclass look for classes which only have copy/move constructors, and so are effectively dead Change-Id: I0b844f301e2200c2b40031856bfdb0b0e2c8f77d Reviewed-on: https://gerrit.libreoffice.org/41039 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> 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 \ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits