From 314f15bff08b76bf96acf99141776ef64d2f1355 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Sat, 16 Nov 2019 21:00:53 +0100 Subject: Extend loplugin:external to warn about enums To mitigate the dangers of silently breaking ADL when moving enums into unnamed namespaces (see the commit message of 206b5b2661be37efdff3c6aedb6f248c4636be79 "New loplugin:external"), note all functions that are affected. (The plan is to extend loplugin:external further to also warn about classes and class templates, and the code to identify affected functions already takes that into account, so some parts of that code are not actually relevant for enums.) But it appears that none of the functions that are actually affected by the changes in this commit relied on being found through ADL, so no adaptions were necessary for them. (clang::DeclContext::collectAllContexts is non-const, which recursively means that External's Visit... functions must take non-const Decl*. Which required compilerplugins/clang/sharedvisitor/analyzer.cxx to be generalized to support such Visit... functions with non-const Decl* parameters.) Change-Id: Ia215291402bf850d43defdab3cff4db5b270d1bd Reviewed-on: https://gerrit.libreoffice.org/83001 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx | 4 ++++ xmloff/source/text/XMLFootnoteImportContext.cxx | 3 +++ xmloff/source/text/XMLIndexTemplateContext.cxx | 3 ++- xmloff/source/text/XMLSectionExport.cxx | 3 +++ xmloff/source/text/XMLSectionImportContext.cxx | 3 +++ xmloff/source/text/XMLSectionSourceDDEImportContext.cxx | 4 ++++ xmloff/source/text/XMLSectionSourceImportContext.cxx | 3 +++ xmloff/source/text/XMLTextColumnsContext.cxx | 4 ++++ xmloff/source/text/XMLTextMarkImportContext.cxx | 4 ++++ xmloff/source/text/txtdropi.cxx | 3 +++ xmloff/source/text/txtfldi.cxx | 3 +++ xmloff/source/text/txtparae.cxx | 8 ++++++++ xmloff/source/text/txtvfldi.cxx | 3 +++ 13 files changed, 47 insertions(+), 1 deletion(-) (limited to 'xmloff/source/text') diff --git a/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx b/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx index d9ce1134ca1ff..cf3beb02918fe 100644 --- a/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx +++ b/xmloff/source/text/XMLFootnoteConfigurationImportContext.cxx @@ -159,6 +159,8 @@ XMLFootnoteConfigurationImportContext::~XMLFootnoteConfigurationImportContext() { } +namespace { + enum XMLFtnConfigToken { XML_TOK_FTNCONFIG_CITATION_STYLENAME, @@ -174,6 +176,8 @@ enum XMLFtnConfigToken XML_TOK_FTNCONFIG_POSITION }; +} + static const SvXMLTokenMapEntry aTextFieldAttrTokenMap[] = { { XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME, XML_TOK_FTNCONFIG_CITATION_STYLENAME }, diff --git a/xmloff/source/text/XMLFootnoteImportContext.cxx b/xmloff/source/text/XMLFootnoteImportContext.cxx index 9569d4119a849..4361417f28f64 100644 --- a/xmloff/source/text/XMLFootnoteImportContext.cxx +++ b/xmloff/source/text/XMLFootnoteImportContext.cxx @@ -42,12 +42,15 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::xml::sax; using namespace ::xmloff::token; +namespace { enum XMLFootnoteChildToken { XML_TOK_FTN_NOTE_CITATION, XML_TOK_FTN_NOTE_BODY }; +} + static const SvXMLTokenMapEntry aFootnoteChildTokenMap[] = { { XML_NAMESPACE_TEXT, XML_NOTE_CITATION, diff --git a/xmloff/source/text/XMLIndexTemplateContext.cxx b/xmloff/source/text/XMLIndexTemplateContext.cxx index 02d545cdd8712..66be9d7a576e1 100644 --- a/xmloff/source/text/XMLIndexTemplateContext.cxx +++ b/xmloff/source/text/XMLIndexTemplateContext.cxx @@ -185,7 +185,7 @@ void XMLIndexTemplateContext::EndElement() } } - +namespace { /// template token types; used for aTokenTypeMap parameter enum TemplateTokenType { @@ -199,6 +199,7 @@ enum TemplateTokenType XML_TOK_INDEX_TYPE_BIBLIOGRAPHY }; +} SvXMLEnumMapEntry const aTemplateTokenTypeMap[] = { diff --git a/xmloff/source/text/XMLSectionExport.cxx b/xmloff/source/text/XMLSectionExport.cxx index 2ae5b7520bdec..db936652cea4a 100644 --- a/xmloff/source/text/XMLSectionExport.cxx +++ b/xmloff/source/text/XMLSectionExport.cxx @@ -1041,6 +1041,7 @@ bool XMLSectionExport::ExportIndexTemplate( return true; } +namespace { enum TemplateTypeEnum { @@ -1070,6 +1071,8 @@ enum TemplateParamEnum TOK_TPARAM_BIBLIOGRAPHY_DATA }; +} + SvXMLEnumStringMapEntry const aTemplateTypeMap[] = { ENUM_STRING_MAP_ENTRY( "TokenEntryNumber", TOK_TTYPE_ENTRY_NUMBER ), diff --git a/xmloff/source/text/XMLSectionImportContext.cxx b/xmloff/source/text/XMLSectionImportContext.cxx index e7754047aacdc..d5783a26fcc32 100644 --- a/xmloff/source/text/XMLSectionImportContext.cxx +++ b/xmloff/source/text/XMLSectionImportContext.cxx @@ -47,6 +47,7 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::text; using namespace ::xmloff::token; +namespace { enum XMLSectionToken { @@ -60,6 +61,8 @@ enum XMLSectionToken XML_TOK_SECTION_IS_HIDDEN }; +} + static const SvXMLTokenMapEntry aSectionTokenMap[] = { { XML_NAMESPACE_XML , XML_ID, XML_TOK_SECTION_XMLID }, diff --git a/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx b/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx index beecdbb5b396e..3969baba9cc01 100644 --- a/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx +++ b/xmloff/source/text/XMLSectionSourceDDEImportContext.cxx @@ -53,6 +53,8 @@ XMLSectionSourceDDEImportContext::~XMLSectionSourceDDEImportContext() { } +namespace { + enum XMLSectionSourceDDEToken { XML_TOK_SECTION_DDE_APPLICATION, @@ -61,6 +63,8 @@ enum XMLSectionSourceDDEToken XML_TOK_SECTION_IS_AUTOMATIC_UPDATE }; +} + static const SvXMLTokenMapEntry aSectionSourceDDETokenMap[] = { { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, diff --git a/xmloff/source/text/XMLSectionSourceImportContext.cxx b/xmloff/source/text/XMLSectionSourceImportContext.cxx index 006fbe5b076e4..ec6bd06dec27a 100644 --- a/xmloff/source/text/XMLSectionSourceImportContext.cxx +++ b/xmloff/source/text/XMLSectionSourceImportContext.cxx @@ -52,6 +52,7 @@ XMLSectionSourceImportContext::~XMLSectionSourceImportContext() { } +namespace { enum XMLSectionSourceToken { XML_TOK_SECTION_XLINK_HREF, @@ -59,6 +60,8 @@ enum XMLSectionSourceToken XML_TOK_SECTION_TEXT_SECTION_NAME }; +} + static const SvXMLTokenMapEntry aSectionSourceTokenMap[] = { { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF }, diff --git a/xmloff/source/text/XMLTextColumnsContext.cxx b/xmloff/source/text/XMLTextColumnsContext.cxx index b62b66fde1379..b8f3d55e48842 100644 --- a/xmloff/source/text/XMLTextColumnsContext.cxx +++ b/xmloff/source/text/XMLTextColumnsContext.cxx @@ -40,6 +40,8 @@ using namespace ::com::sun::star::style; using namespace ::com::sun::star::beans; using namespace ::xmloff::token; +namespace { + enum SvXMLTokenMapAttrs { XML_TOK_COLUMN_WIDTH, @@ -56,6 +58,8 @@ enum SvXMLSepTokenMapAttrs XML_TOK_COLUMN_SEP_STYLE }; +} + static const SvXMLTokenMapEntry aColAttrTokenMap[] = { { XML_NAMESPACE_STYLE, XML_REL_WIDTH, XML_TOK_COLUMN_WIDTH }, diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx index 9d13c810b240d..4dd5c1e76f902 100644 --- a/xmloff/source/text/XMLTextMarkImportContext.cxx +++ b/xmloff/source/text/XMLTextMarkImportContext.cxx @@ -107,11 +107,15 @@ XMLTextMarkImportContext::XMLTextMarkImportContext( { } +namespace { + enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd, TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd, TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd }; +} + static SvXMLEnumMapEntry const lcl_aMarkTypeMap[] = { { XML_REFERENCE_MARK, TypeReference }, diff --git a/xmloff/source/text/txtdropi.cxx b/xmloff/source/text/txtdropi.cxx index 8e7dc0e2100b2..cceb49caa51c3 100644 --- a/xmloff/source/text/txtdropi.cxx +++ b/xmloff/source/text/txtdropi.cxx @@ -37,6 +37,7 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::style; using namespace ::xmloff::token; +namespace { enum SvXMLTokenMapDropAttrs { @@ -46,6 +47,8 @@ enum SvXMLTokenMapDropAttrs XML_TOK_DROP_STYLE }; +} + static const SvXMLTokenMapEntry aDropAttrTokenMap[] = { { XML_NAMESPACE_STYLE, XML_LINES, XML_TOK_DROP_LINES }, diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index cde1edd6daa34..10e246596821f 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -2666,6 +2666,7 @@ void XMLReferenceFieldImportContext::PrepareField( // field declarations container +namespace { enum DdeFieldDeclAttrs { @@ -2676,6 +2677,8 @@ enum DdeFieldDeclAttrs XML_TOK_DDEFIELD_UPDATE }; +} + static const SvXMLTokenMapEntry aDdeDeclAttrTokenMap[] = { { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_DDEFIELD_NAME }, diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 0238e918535dc..00b4968aa5fe1 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -355,6 +355,8 @@ static const sal_Char* aParagraphPropertyNamesAuto[] = nullptr }; +namespace { + enum eParagraphPropertyNamesEnumAuto { NUMBERING_RULES_AUTO = 0, @@ -362,6 +364,8 @@ enum eParagraphPropertyNamesEnumAuto PARA_STYLE_NAME_AUTO = 2 }; +} + static const sal_Char* aParagraphPropertyNames[] = { "NumberingIsNumber", @@ -373,6 +377,8 @@ static const sal_Char* aParagraphPropertyNames[] = nullptr }; +namespace { + enum eParagraphPropertyNamesEnum { NUMBERING_IS_NUMBER = 0, @@ -383,6 +389,8 @@ enum eParagraphPropertyNamesEnum TEXT_SECTION = 5 }; +} + void BoundFrames::Fill(const filter_t& rFilter) { if(!m_xEnumAccess.is()) diff --git a/xmloff/source/text/txtvfldi.cxx b/xmloff/source/text/txtvfldi.cxx index 5a1f2255035e9..e2ddd6ec42d55 100644 --- a/xmloff/source/text/txtvfldi.cxx +++ b/xmloff/source/text/txtvfldi.cxx @@ -1052,6 +1052,7 @@ void XMLDatabaseDisplayImportContext::EndElement() // value import helper +namespace { enum ValueType { @@ -1064,6 +1065,8 @@ enum ValueType XML_VALUE_TYPE_BOOLEAN }; +} + static SvXMLEnumMapEntry const aValueTypeMap[] = { { XML_FLOAT, XML_VALUE_TYPE_FLOAT }, -- cgit