From f853ec317f6af1b8c65cc5bd758371689c75118d Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 19 Nov 2019 16:32:49 +0100 Subject: Extend loplugin:external to warn about classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." () The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- vbahelper/source/vbahelper/vbaapplicationbase.cxx | 8 ++++++++ vbahelper/source/vbahelper/vbacommandbarcontrols.cxx | 6 ++++++ vbahelper/source/vbahelper/vbacommandbarhelper.cxx | 4 ++++ vbahelper/source/vbahelper/vbacommandbars.cxx | 3 +++ vbahelper/source/vbahelper/vbadocumentsbase.cxx | 8 ++++++++ vbahelper/source/vbahelper/vbashaperange.cxx | 4 ++++ vbahelper/source/vbahelper/vbashapes.cxx | 4 ++++ 7 files changed, 37 insertions(+) (limited to 'vbahelper/source/vbahelper') diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index 94c3419f6e2a..bf7ac741563c 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -60,6 +60,8 @@ using namespace ::ooo::vba; typedef ::std::pair< OUString, ::std::pair< double, double > > VbaTimerInfo; +namespace { + class VbaTimer { Timer m_aTimer; @@ -115,6 +117,8 @@ public: DECL_LINK( MacroCallHdl, Timer*, void ); }; +} + IMPL_LINK_NOARG(VbaTimer, MacroCallHdl, Timer *, void) { if ( m_aTimerInfo.second.second == 0 || GetNow() < m_aTimerInfo.second.second ) @@ -136,6 +140,8 @@ IMPL_LINK_NOARG(VbaTimer, MacroCallHdl, Timer *, void) {} } +namespace { + struct VbaTimerInfoHash { size_t operator()( const VbaTimerInfo& rTimerInfo ) const @@ -148,6 +154,8 @@ struct VbaTimerInfoHash } }; +} + typedef std::unordered_map< VbaTimerInfo, std::unique_ptr, VbaTimerInfoHash > VbaTimerHashMap; struct VbaApplicationBase_Impl final diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx index f789a487f6b2..cb83e51c8204 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx @@ -23,6 +23,8 @@ using namespace com::sun::star; using namespace ooo::vba; +namespace { + class CommandBarControlEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration > { //uno::Reference< uno::XComponentContext > m_xContext; @@ -45,6 +47,8 @@ public: } }; +} + ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef const & pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const OUString& sResourceUrl ) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ) { m_bIsMenu = sResourceUrl == ITEM_MENUBAR_URL; @@ -243,6 +247,7 @@ ScVbaCommandBarControls::getServiceNames() return aServiceNames; } +namespace { class VbaDummyIndexAccess : public ::cppu::WeakImplHelper< container::XIndexAccess > { @@ -260,6 +265,7 @@ public: { return false; } }; +} VbaDummyCommandBarControls::VbaDummyCommandBarControls( const uno::Reference< XHelperInterface >& xParent, diff --git a/vbahelper/source/vbahelper/vbacommandbarhelper.cxx b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx index aa18d1b0dc49..f2926139aea9 100644 --- a/vbahelper/source/vbahelper/vbacommandbarhelper.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx @@ -41,6 +41,8 @@ using namespace ooo::vba; typedef std::map< OUString, OUString > MSO2OOCommandbarMap; +namespace { + class MSO2OOCommandbarHelper final { private: @@ -83,6 +85,8 @@ public: } }; +} + MSO2OOCommandbarHelper* MSO2OOCommandbarHelper::pMSO2OOCommandbarHelper = nullptr; diff --git a/vbahelper/source/vbahelper/vbacommandbars.cxx b/vbahelper/source/vbahelper/vbacommandbars.cxx index be173f49b2a7..332249049b84 100644 --- a/vbahelper/source/vbahelper/vbacommandbars.cxx +++ b/vbahelper/source/vbahelper/vbacommandbars.cxx @@ -31,6 +31,7 @@ using namespace com::sun::star; using namespace ooo::vba; +namespace { class CommandBarEnumeration : public ::cppu::WeakImplHelper< container::XEnumeration > { @@ -71,6 +72,8 @@ public: } }; +} + ScVbaCommandBars::ScVbaCommandBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< frame::XModel >& xModel ) : CommandBars_BASE( xParent, xContext, xIndexAccess ) { m_pCBarHelper.reset( new VbaCommandBarHelper( mxContext, xModel ) ); diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx index 1ba2bb1a0b0f..d0951b0c13e7 100644 --- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx @@ -56,6 +56,8 @@ typedef std::vector < uno::Reference< frame::XModel > > Documents; // #FIXME clearly this is a candidate for some sort of helper base class as // this is a copy of SelectedSheetsEnum ( vbawindow.cxx ) +namespace { + class DocumentsEnumImpl : public ::cppu::WeakImplHelper< container::XEnumeration > { uno::Reference< uno::XComponentContext > m_xContext; @@ -97,6 +99,8 @@ public: } }; +} + // #FIXME clearly this is also a candidate for some sort of helper base class as // a very similar one is used in vbawindow ( SelectedSheetsEnumAccess ) // Maybe a template base class that does all of the operations on the hashmap @@ -108,6 +112,8 @@ typedef ::cppu::WeakImplHelper< container::XEnumerationAccess , css::container::XNameAccess > DocumentsAccessImpl_BASE; +namespace { + class DocumentsAccessImpl : public DocumentsAccessImpl_BASE { uno::Reference< uno::XComponentContext > m_xContext; @@ -187,6 +193,8 @@ public: }; +} + VbaDocumentsBase::VbaDocumentsBase( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, DOCUMENT_TYPE eDocType ) : VbaDocumentsBase_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new DocumentsAccessImpl( xContext, eDocType ) ) ), meDocType( eDocType ) { } diff --git a/vbahelper/source/vbahelper/vbashaperange.cxx b/vbahelper/source/vbahelper/vbashaperange.cxx index b21c24165cf7..6f353e5e14d1 100644 --- a/vbahelper/source/vbahelper/vbashaperange.cxx +++ b/vbahelper/source/vbahelper/vbashaperange.cxx @@ -29,6 +29,8 @@ using namespace ::ooo::vba; using namespace ::com::sun::star; +namespace { + class VbShapeRangeEnumHelper : public EnumerationHelper_BASE { uno::Reference< XCollection > m_xParent; @@ -50,6 +52,8 @@ public: }; +} + ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xShapes, const uno::Reference< drawing::XDrawPage >& xDrawPage, const uno::Reference< frame::XModel >& xModel ) : ScVbaShapeRange_BASE( xParent, xContext, xShapes ), m_xDrawPage( xDrawPage ), m_xModel( xModel ) { } diff --git a/vbahelper/source/vbahelper/vbashapes.cxx b/vbahelper/source/vbahelper/vbashapes.cxx index 7c9ca3f22cd9..f9356efedd9d 100644 --- a/vbahelper/source/vbahelper/vbashapes.cxx +++ b/vbahelper/source/vbahelper/vbashapes.cxx @@ -51,6 +51,8 @@ using namespace ::ooo::vba; using namespace ::com::sun::star; +namespace { + class VbShapeEnumHelper : public EnumerationHelper_BASE { uno::Reference m_xParent; @@ -72,6 +74,8 @@ public: }; +} + void ScVbaShapes::initBaseCollection() { if ( m_xNameAccess.is() ) // already has NameAccess -- cgit