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 --- starmath/source/dialog.cxx | 12 ++++++-- starmath/source/mathmlimport.cxx | 65 ++++++++++++++++++++++++++++++++++++++-- starmath/source/unofilter.cxx | 4 +++ 3 files changed, 77 insertions(+), 4 deletions(-) (limited to 'starmath') diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx index 1c2d5f3405fc..de1fd7eb4bc8 100644 --- a/starmath/source/dialog.cxx +++ b/starmath/source/dialog.cxx @@ -67,8 +67,6 @@ void lclGetSettingColors(Color& rBackgroundColor, Color& rTextColor) } } -} // end anonymous namespace - // Since it's better to set/query the FontStyle via its attributes rather // than via the StyleName we create a way to translate // Attribute <-> StyleName @@ -88,6 +86,8 @@ public: const OUString& GetStyleName(sal_uInt16 nIdx) const; }; +} // end anonymous namespace + SmFontStyles::SmFontStyles() : aNormal(SmResId(RID_FONTREGULAR)) , aBold(SmResId(RID_FONTBOLD)) @@ -340,6 +340,8 @@ SmFontDialog::~SmFontDialog() { } +namespace { + class SaveDefaultsQuery : public weld::MessageDialogController { public: @@ -350,6 +352,8 @@ public: } }; +} + IMPL_LINK_NOARG( SmFontSizeDialog, DefaultButtonClickHdl, weld::Button&, void ) { SaveDefaultsQuery aQuery(m_xDialog.get()); @@ -530,11 +534,15 @@ void SmFontTypeDialog::WriteTo(SmFormat &rFormat) const /**************************************************************************/ +namespace { + struct FieldMinMax { sal_uInt16 nMin, nMax; }; +} + // Data for min and max values of the 4 metric fields // for each of the 10 categories static const FieldMinMax pMinMaxData[10][4] = diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx index 808a235b96b8..18cf0e3b7ca6 100644 --- a/starmath/source/mathmlimport.cxx +++ b/starmath/source/mathmlimport.cxx @@ -502,6 +502,7 @@ void SmXMLImport::endDocument() SvXMLImport::endDocument(); } +namespace { class SmXMLImportContext: public SvXMLImportContext { @@ -534,6 +535,8 @@ public: } }; +} + void SmXMLImportContext::TCharacters(const OUString & /*rChars*/) { } @@ -559,6 +562,7 @@ SvXMLImportContextRef SmXMLImportContext::CreateChildContext(sal_uInt16 /*nPrefi return nullptr; } +namespace { struct SmXMLContext_Helper { @@ -582,6 +586,8 @@ struct SmXMLContext_Helper void ApplyAttrs(); }; +} + bool SmXMLContext_Helper::IsFontNodeNeeded() const { return nIsBold != -1 || @@ -742,6 +748,7 @@ void SmXMLContext_Helper::ApplyAttrs() } } +namespace { class SmXMLTokenAttrHelper { @@ -760,6 +767,8 @@ public: void ApplyAttrs(MathMLMathvariantValue eDefaultMv); }; +} + void SmXMLTokenAttrHelper::RetrieveAttrs(const uno::Reference& xAttrList) { if (!xAttrList.is()) @@ -867,6 +876,7 @@ void SmXMLTokenAttrHelper::ApplyAttrs(MathMLMathvariantValue eDefaultMv) } } +namespace { class SmXMLDocContext_Impl : public SmXMLImportContext { @@ -915,6 +925,8 @@ public: void EndElement() override; }; +} + void SmXMLEncloseContext_Impl::EndElement() { /* @@ -926,6 +938,7 @@ void SmXMLEncloseContext_Impl::EndElement() SmXMLRowContext_Impl::EndElement(); } +namespace { class SmXMLFracContext_Impl : public SmXMLRowContext_Impl { @@ -976,6 +989,8 @@ public: void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList ) override; }; +} + void SmXMLStyleContext_Impl::StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) { @@ -996,6 +1011,7 @@ void SmXMLStyleContext_Impl::EndElement() aStyleHelper.ApplyAttrs(); } +namespace { class SmXMLPaddedContext_Impl : public SmXMLRowContext_Impl { @@ -1008,6 +1024,8 @@ public: void EndElement() override; }; +} + void SmXMLPaddedContext_Impl::EndElement() { /* @@ -1019,6 +1037,7 @@ void SmXMLPaddedContext_Impl::EndElement() SmXMLRowContext_Impl::EndElement(); } +namespace { class SmXMLPhantomContext_Impl : public SmXMLRowContext_Impl { @@ -1031,6 +1050,8 @@ public: void EndElement() override; }; +} + void SmXMLPhantomContext_Impl::EndElement() { /* @@ -1052,6 +1073,7 @@ void SmXMLPhantomContext_Impl::EndElement() rNodeStack.push_front(std::move(pPhantom)); } +namespace { class SmXMLFencedContext_Impl : public SmXMLRowContext_Impl { @@ -1069,6 +1091,7 @@ public: void EndElement() override; }; +} void SmXMLFencedContext_Impl::StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) @@ -1145,6 +1168,7 @@ void SmXMLFencedContext_Impl::EndElement() GetSmImport().GetNodeStack().push_front(std::move(pSNode)); } +namespace { class SmXMLErrorContext_Impl : public SmXMLRowContext_Impl { @@ -1156,6 +1180,8 @@ public: void EndElement() override; }; +} + void SmXMLErrorContext_Impl::EndElement() { /*Right now the error tag is completely ignored, what @@ -1172,6 +1198,7 @@ void SmXMLErrorContext_Impl::EndElement() } } +namespace { class SmXMLNumberContext_Impl : public SmXMLImportContext { @@ -1193,6 +1220,8 @@ public: void EndElement() override; }; +} + void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars) { aToken.aText = rChars; @@ -1203,6 +1232,7 @@ void SmXMLNumberContext_Impl::EndElement() GetSmImport().GetNodeStack().push_front(std::make_unique(aToken,FNT_NUMBER)); } +namespace { class SmXMLAnnotationContext_Impl : public SmXMLImportContext { @@ -1218,6 +1248,8 @@ public: void StartElement(const uno::Reference & xAttrList ) override; }; +} + void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) { @@ -1249,6 +1281,7 @@ void SmXMLAnnotationContext_Impl::Characters(const OUString &rChars) GetSmImport().SetText( GetSmImport().GetText() + rChars ); } +namespace { class SmXMLTextContext_Impl : public SmXMLImportContext { @@ -1270,6 +1303,8 @@ public: void EndElement() override; }; +} + void SmXMLTextContext_Impl::TCharacters(const OUString &rChars) { aToken.aText = rChars; @@ -1280,6 +1315,7 @@ void SmXMLTextContext_Impl::EndElement() GetSmImport().GetNodeStack().push_front(std::make_unique(aToken,FNT_TEXT)); } +namespace { class SmXMLStringContext_Impl : public SmXMLImportContext { @@ -1301,6 +1337,8 @@ public: void EndElement() override; }; +} + void SmXMLStringContext_Impl::TCharacters(const OUString &rChars) { /* @@ -1321,6 +1359,7 @@ void SmXMLStringContext_Impl::EndElement() GetSmImport().GetNodeStack().push_front(std::make_unique(aToken,FNT_FIXED)); } +namespace { class SmXMLIdentifierContext_Impl : public SmXMLImportContext { @@ -1349,6 +1388,8 @@ public: void EndElement() override; }; +} + void SmXMLIdentifierContext_Impl::EndElement() { std::unique_ptr pNode; @@ -1384,6 +1425,7 @@ void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars) aToken.aText = rChars; } +namespace { class SmXMLOperatorContext_Impl : public SmXMLImportContext { @@ -1407,6 +1449,8 @@ public: void EndElement() override; }; +} + void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars) { aToken.cMathChar = rChars[0]; @@ -1455,6 +1499,7 @@ void SmXMLOperatorContext_Impl::StartElement(const uno::Reference< } } +namespace { class SmXMLSpaceContext_Impl : public SmXMLImportContext { @@ -1466,8 +1511,6 @@ public: void StartElement(const uno::Reference< xml::sax::XAttributeList >& xAttrList ) override; }; -namespace { - bool lcl_CountBlanks(const MathMLAttributeLengthValue &rLV, sal_Int32 *pWide, sal_Int32 *pNarrow) { @@ -1542,6 +1585,7 @@ void SmXMLSpaceContext_Impl::StartElement( GetSmImport().GetNodeStack().push_front(std::move(pBlank)); } +namespace { class SmXMLSubContext_Impl : public SmXMLRowContext_Impl { @@ -1559,6 +1603,7 @@ public: } }; +} void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup) { @@ -1586,6 +1631,7 @@ void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup rNodeStack.push_front(std::move(pNode)); } +namespace { class SmXMLSupContext_Impl : public SmXMLSubContext_Impl { @@ -1617,6 +1663,8 @@ public: } }; +} + void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup aSub,SmSubSup aSup) { @@ -1645,6 +1693,7 @@ void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, rNodeStack.push_front(std::move(pNode)); } +namespace { class SmXMLUnderContext_Impl : public SmXMLSubContext_Impl { @@ -1663,6 +1712,8 @@ public: void HandleAccent(); }; +} + void SmXMLUnderContext_Impl::StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) { @@ -1707,6 +1758,7 @@ void SmXMLUnderContext_Impl::EndElement() HandleAccent(); } +namespace { class SmXMLOverContext_Impl : public SmXMLSubContext_Impl { @@ -1723,6 +1775,7 @@ public: void HandleAccent(); }; +} void SmXMLOverContext_Impl::StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) @@ -1762,6 +1815,7 @@ void SmXMLOverContext_Impl::HandleAccent() } +namespace { class SmXMLUnderOverContext_Impl : public SmXMLSubSupContext_Impl { @@ -1806,6 +1860,7 @@ public: void EndElement() override; }; +} void SmXMLNoneContext_Impl::EndElement() { @@ -1818,6 +1873,7 @@ void SmXMLNoneContext_Impl::EndElement() std::make_unique(aToken,FNT_VARIABLE)); } +namespace { class SmXMLPrescriptsContext_Impl : public SmXMLImportContext { @@ -1919,6 +1975,8 @@ public: sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; }; +} + SvXMLImportContextRef SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList) @@ -1948,6 +2006,7 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SmXMLOfficeContext_Impl return new SvXMLImportContext( GetImport() ); } +namespace { // context for flat file xml format class SmXMLFlatDocContext_Impl @@ -1968,6 +2027,8 @@ public: sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; }; +} + SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport, const uno::Reference& i_xDocProps) : SvXMLImportContext(i_rImport), diff --git a/starmath/source/unofilter.cxx b/starmath/source/unofilter.cxx index 7add12f9e3fb..5886e9e6e0b9 100644 --- a/starmath/source/unofilter.cxx +++ b/starmath/source/unofilter.cxx @@ -21,6 +21,8 @@ using namespace ::com::sun::star; +namespace { + /// Invokes the MathType importer via UNO. class MathTypeFilter : public cppu::WeakImplHelper < @@ -47,6 +49,8 @@ public: uno::Sequence SAL_CALL getSupportedServiceNames() override; }; +} + MathTypeFilter::MathTypeFilter() = default; sal_Bool MathTypeFilter::filter(const uno::Sequence& rDescriptor) -- cgit