diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-19 16:32:49 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-22 12:57:32 +0100 |
commit | f853ec317f6af1b8c65cc5bd758371689c75118d (patch) | |
tree | b86d729bf9a9465ee619ead3b5635efa62a1804e /i18npool | |
parent | f31d36966bceb90e261cbecd42634bde4448d527 (diff) |
Extend loplugin:external to warn about classes
...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 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"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
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "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."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) 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 <sbergman@redhat.com>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/breakiterator/breakiterator_unicode.cxx | 4 | ||||
-rw-r--r-- | i18npool/source/calendar/calendar_jewish.cxx | 7 | ||||
-rw-r--r-- | i18npool/source/localedata/LocaleNode.cxx | 5 | ||||
-rw-r--r-- | i18npool/source/localedata/localedata.cxx | 4 | ||||
-rw-r--r-- | i18npool/source/localedata/saxparser.cxx | 4 | ||||
-rw-r--r-- | i18npool/source/nativenumber/nativenumbersupplier.cxx | 23 | ||||
-rw-r--r-- | i18npool/source/registerservices/registerservices.cxx | 10 | ||||
-rw-r--r-- | i18npool/source/textconversion/genconv_dict.cxx | 3 |
8 files changed, 56 insertions, 4 deletions
diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx b/i18npool/source/breakiterator/breakiterator_unicode.cxx index e1675ec6a41d..93f81fa9cc6c 100644 --- a/i18npool/source/breakiterator/breakiterator_unicode.cxx +++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx @@ -58,6 +58,8 @@ BreakIterator_Unicode::~BreakIterator_Unicode() { } +namespace { + /* Wrapper class to provide public access to the icu::RuleBasedBreakIterator's setbreakType method. @@ -79,6 +81,8 @@ class OOoRuleBasedBreakIterator : public icu::RuleBasedBreakIterator }; +} + // loading ICU breakiterator on demand. void BreakIterator_Unicode::loadICUBreakIterator(const css::lang::Locale& rLocale, sal_Int16 rBreakType, sal_Int16 nWordType, const sal_Char *rule, const OUString& rText) diff --git a/i18npool/source/calendar/calendar_jewish.cxx b/i18npool/source/calendar/calendar_jewish.cxx index 996d01d73f49..549bae3c12aa 100644 --- a/i18npool/source/calendar/calendar_jewish.cxx +++ b/i18npool/source/calendar/calendar_jewish.cxx @@ -128,6 +128,7 @@ static sal_Int32 LastDayOfHebrewMonth(sal_Int32 month, sal_Int32 year) { return 30; } +namespace { class HebrewDate { private: @@ -187,6 +188,8 @@ public: }; +} + // Gregorian dates static int LastDayOfGregorianMonth(int month, int year) { @@ -207,6 +210,8 @@ static int LastDayOfGregorianMonth(int month, int year) { } } +namespace { + class GregorianDate { private: int year; // 1... @@ -246,6 +251,8 @@ public: }; +} + // map field value from gregorian calendar to other calendar, it can be overwritten by derived class. void Calendar_jewish::mapFromGregorian() { diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index 273d40698a8f..80972f61092c 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -1966,10 +1966,15 @@ void LCTransliterationNode::generateCode (const OFileWriter &of) const of.writeFunction("getTransliterations_", "nbOfTransliterations", "LCTransliterationsArray"); } +namespace { + struct NameValuePair { const sal_Char *name; const sal_Char *value; }; + +} + static const NameValuePair ReserveWord[] = { { "trueWord", "true" }, { "falseWord", "false" }, diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 0679407cc81b..91e4c5de21bb 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -1318,6 +1318,8 @@ LocaleDataImpl::getContinuousNumberingLevels( const lang::Locale& rLocale ) // OutlineNumbering helper class +namespace { + struct OutlineNumberingLevel_Impl { OUString sPrefix; @@ -1351,6 +1353,8 @@ public: virtual sal_Bool SAL_CALL hasElements( ) override; }; +} + Sequence< Reference<container::XIndexAccess> > LocaleDataImpl::getOutlineNumberingLevels( const lang::Locale& rLocale ) { diff --git a/i18npool/source/localedata/saxparser.cxx b/i18npool/source/localedata/saxparser.cxx index ace747d8286f..e667f523316c 100644 --- a/i18npool/source/localedata/saxparser.cxx +++ b/i18npool/source/localedata/saxparser.cxx @@ -46,6 +46,7 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::io; +namespace { /************ * Sequence of bytes -> InputStream @@ -88,6 +89,7 @@ public: Sequence< sal_Int8> m_seq; }; +} // Helper : create an input stream from a file @@ -135,6 +137,7 @@ static Reference< XInputStream > createStreamFromFile( return r; } +namespace { class TestDocumentHandler : public WeakImplHelper< XExtendedDocumentHandler , XEntityResolver , XErrorHandler > @@ -292,6 +295,7 @@ public: OFileWriter of; }; +} SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index c19e6521d347..89d56a97826d 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -38,6 +38,8 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::lang; +namespace { + struct Number { sal_Int16 number; const sal_Unicode *multiplierChar; @@ -46,6 +48,7 @@ struct Number { const sal_Int16 *multiplierExponent; }; +} #define NUMBER_OMIT_ZERO (1 << 0) #define NUMBER_OMIT_ONLY_ZERO (1 << 1) @@ -65,8 +68,12 @@ struct Number { namespace i18npool { +namespace { + struct theNatNumMutex : public rtl::Static<osl::Mutex, theNatNumMutex> {}; +} + static OUString getHebrewNativeNumberString(const OUString& aNumberString, bool useGeresh); static OUString getCyrillicNativeNumberString(const OUString& aNumberString); @@ -981,10 +988,16 @@ sal_Int16 SAL_CALL NativeNumberSupplierService::convertFromXmlAttributes( const // see numerical system in the Hebrew Numbering System in following link for details, // http://smontagu.org/writings/HebrewNumbers.html +namespace { + struct HebrewNumberChar { sal_Unicode code; sal_Int16 value; -} const HebrewNumberCharArray[] = { +}; + +} + +HebrewNumberChar const HebrewNumberCharArray[] = { { 0x05ea, 400 }, { 0x05ea, 400 }, { 0x05e9, 300 }, @@ -1089,10 +1102,16 @@ static const sal_Unicode cyrillicThousandsMark = 0x0482; static const sal_Unicode cyrillicTitlo = 0x0483; static const sal_Unicode cyrillicTen = 0x0456; +namespace { + struct CyrillicNumberChar { sal_Unicode code; sal_Int16 value; -} const CyrillicNumberCharArray[] = { +}; + +} + +CyrillicNumberChar const CyrillicNumberCharArray[] = { { 0x0446, 900 }, { 0x047f, 800 }, { 0x0471, 700 }, diff --git a/i18npool/source/registerservices/registerservices.cxx b/i18npool/source/registerservices/registerservices.cxx index dd891558696d..eb71012e90eb 100644 --- a/i18npool/source/registerservices/registerservices.cxx +++ b/i18npool/source/registerservices/registerservices.cxx @@ -247,11 +247,17 @@ IMPL_CREATEINSTANCE( halfwidthKatakanaToFullwidthKatakana ) IMPL_CREATEINSTANCE( fullwidthToHalfwidthLikeASC ) IMPL_CREATEINSTANCE( halfwidthToFullwidthLikeJIS ) -static const struct InstancesArray { +namespace { + +struct InstancesArray { const sal_Char* pServiceNm; const sal_Char* pImplementationNm; FN_CreateInstance pFn; -} aInstances[] = { +}; + +} + +static const InstancesArray aInstances[] = { { "com.sun.star.i18n.IndexEntrySupplier", "com.sun.star.i18n.IndexEntrySupplier", &IndexEntrySupplier_CreateInstance }, diff --git a/i18npool/source/textconversion/genconv_dict.cxx b/i18npool/source/textconversion/genconv_dict.cxx index 4173d898622d..8cebdb7f1a52 100644 --- a/i18npool/source/textconversion/genconv_dict.cxx +++ b/i18npool/source/textconversion/genconv_dict.cxx @@ -319,6 +319,7 @@ void make_stc_char(FILE *sfp, FILE *cfp) fprintf (cfp, "\tconst sal_Unicode* getSTC_CharData_T2S() { return STC_CharData_T2S; }\n"); } +namespace { struct Index { sal_uInt16 address; @@ -326,6 +327,8 @@ struct Index { sal_Unicode *data; }; +} + extern "C" { static int Index_comp(const void* s1, const void* s2) { |