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 /cppu | |
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 'cppu')
-rw-r--r-- | cppu/source/AffineBridge/AffineBridge.cxx | 7 | ||||
-rw-r--r-- | cppu/source/UnsafeBridge/UnsafeBridge.cxx | 4 | ||||
-rw-r--r-- | cppu/source/helper/purpenv/helper_purpenv_Environment.cxx | 4 | ||||
-rw-r--r-- | cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx | 4 | ||||
-rw-r--r-- | cppu/source/threadpool/current.cxx | 3 | ||||
-rw-r--r-- | cppu/source/threadpool/threadpool.cxx | 7 | ||||
-rw-r--r-- | cppu/source/typelib/static_types.cxx | 4 | ||||
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 10 | ||||
-rw-r--r-- | cppu/source/uno/EnvStack.cxx | 6 | ||||
-rw-r--r-- | cppu/source/uno/IdentityMapping.cxx | 4 | ||||
-rw-r--r-- | cppu/source/uno/cascade_mapping.cxx | 4 | ||||
-rw-r--r-- | cppu/source/uno/lbmap.cxx | 15 |
12 files changed, 72 insertions, 0 deletions
diff --git a/cppu/source/AffineBridge/AffineBridge.cxx b/cppu/source/AffineBridge/AffineBridge.cxx index 1e2a45ac84cf..156d6eb9c7a0 100644 --- a/cppu/source/AffineBridge/AffineBridge.cxx +++ b/cppu/source/AffineBridge/AffineBridge.cxx @@ -29,6 +29,7 @@ #include <cppu/helper/purpenv/Mapping.hxx> #include <memory> +namespace { class InnerThread; class OuterThread; @@ -86,6 +87,8 @@ public: } }; +} + void InnerThread::run() { osl_setThreadName("UNO AffineBridge InnerThread"); @@ -95,6 +98,8 @@ void InnerThread::run() m_pAffineBridge->leave(); } +namespace { + class OuterThread : public osl::Thread { virtual void SAL_CALL run() override; @@ -105,6 +110,8 @@ public: explicit OuterThread(AffineBridge * threadEnvironment); }; +} + OuterThread::OuterThread(AffineBridge * threadEnvironment) : m_pAffineBridge(threadEnvironment) { diff --git a/cppu/source/UnsafeBridge/UnsafeBridge.cxx b/cppu/source/UnsafeBridge/UnsafeBridge.cxx index 7cf945d44391..491a888c3921 100644 --- a/cppu/source/UnsafeBridge/UnsafeBridge.cxx +++ b/cppu/source/UnsafeBridge/UnsafeBridge.cxx @@ -26,6 +26,8 @@ #include <cppu/helper/purpenv/Environment.hxx> #include <cppu/helper/purpenv/Mapping.hxx> +namespace { + class UnsafeBridge : public cppu::Enterable { osl::Mutex m_mutex; @@ -46,6 +48,8 @@ public: virtual bool v_isValid(OUString * pReason) override; }; +} + UnsafeBridge::UnsafeBridge() : m_count (0), m_threadId(0) diff --git a/cppu/source/helper/purpenv/helper_purpenv_Environment.cxx b/cppu/source/helper/purpenv/helper_purpenv_Environment.cxx index ceeee6eb0deb..bb8af537c4b8 100644 --- a/cppu/source/helper/purpenv/helper_purpenv_Environment.cxx +++ b/cppu/source/helper/purpenv/helper_purpenv_Environment.cxx @@ -59,6 +59,8 @@ typedef void ExtEnv_releaseInterface (uno_ExtEnvironment * void * pInterface); } +namespace { + class Base : public cppu::Enterable { public: @@ -117,6 +119,8 @@ protected: virtual ~Base() override; }; +} + extern "C" { static void s_acquire(uno_Environment * pEnv) //SAL_THROW_EXTERN_C() { diff --git a/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx b/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx index 19c341f15d34..6255b2f0b52a 100644 --- a/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx +++ b/cppu/source/helper/purpenv/helper_purpenv_Mapping.cxx @@ -29,6 +29,8 @@ using namespace com::sun::star; +namespace { + class Mapping : public uno_Mapping { uno::Environment m_from; @@ -55,6 +57,8 @@ public: void release(); }; +} + static void s_mapInterface( uno_Mapping * puno_Mapping, void ** ppOut, diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx index f788e005a031..665f1b7c636e 100644 --- a/cppu/source/threadpool/current.cxx +++ b/cppu/source/threadpool/current.cxx @@ -81,6 +81,7 @@ static typelib_InterfaceTypeDescription * get_type_XCurrentContext() return s_type_XCurrentContext; } +namespace { class ThreadKey { @@ -119,6 +120,8 @@ public: } }; +} + extern "C" { static void delete_IdContainer( void * p ) diff --git a/cppu/source/threadpool/threadpool.cxx b/cppu/source/threadpool/threadpool.cxx index 40b031c85732..d11268b85784 100644 --- a/cppu/source/threadpool/threadpool.cxx +++ b/cppu/source/threadpool/threadpool.cxx @@ -44,6 +44,8 @@ namespace cppu_threadpool rtl::Reference<ORequestThread> const & theThread): thread(theThread) {} + namespace { + struct theDisposedCallerAdmin : public rtl::StaticWithInit< DisposedCallerAdminHolder, theDisposedCallerAdmin > { @@ -52,6 +54,8 @@ namespace cppu_threadpool } }; + } + DisposedCallerAdminHolder const & DisposedCallerAdmin::getInstance() { return theDisposedCallerAdmin::get(); @@ -328,6 +332,8 @@ namespace cppu_threadpool using namespace cppu_threadpool; +namespace { + struct uno_ThreadPool_Equal { bool operator () ( const uno_ThreadPool &a , const uno_ThreadPool &b ) const @@ -344,6 +350,7 @@ struct uno_ThreadPool_Hash } }; +} typedef std::unordered_map< uno_ThreadPool, ThreadPoolHolder, uno_ThreadPool_Hash, uno_ThreadPool_Equal > ThreadpoolHashSet; diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx index 5a400817115d..b2638979936a 100644 --- a/cppu/source/typelib/static_types.cxx +++ b/cppu/source/typelib/static_types.cxx @@ -40,6 +40,8 @@ extern "C" #pragma pack(push, 8) #endif +namespace { + /** * The double member determines the alignment. * Under OS2 and MS-Windows the Alignment is min( 8, sizeof( type ) ). @@ -59,6 +61,8 @@ struct AlignSize_Impl #endif }; +} + #ifdef _WIN32 #pragma pack(pop) #endif diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index 1604cf7b7997..c94ee1a80ec2 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -46,6 +46,8 @@ using namespace osl; #pragma pack(push, 8) #endif +namespace { + /** * The double member determines the alignment. * Under OS2 and MS-Windows the Alignment is min( 8, sizeof( type ) ). @@ -65,6 +67,8 @@ struct AlignSize_Impl #endif }; +} + #ifdef _WIN32 #pragma pack(pop) #endif @@ -138,6 +142,7 @@ static sal_Int32 getDescriptionSize( typelib_TypeClass eTypeClass ) return nSize; } +namespace { struct equalStr_Impl { @@ -152,6 +157,7 @@ struct hashStr_Impl { return rtl_ustr_hashCode( s ); } }; +} // Heavy hack, the const sal_Unicode * is hold by the typedescription reference typedef std::unordered_map< const sal_Unicode *, typelib_TypeDescriptionReference *, @@ -164,6 +170,8 @@ typedef list< typelib_TypeDescription * > TypeDescriptionList_Impl; // # of cached elements static sal_Int32 nCacheSize = 256; +namespace { + struct TypeDescriptor_Init_Impl { //sal_Bool bDesctructorCalled; @@ -206,6 +214,8 @@ struct TypeDescriptor_Init_Impl ~TypeDescriptor_Init_Impl(); }; +} + inline Mutex & TypeDescriptor_Init_Impl::getMutex() { if( !pMutex ) diff --git a/cppu/source/uno/EnvStack.cxx b/cppu/source/uno/EnvStack.cxx index 71c87bec7c37..f6b11352cf14 100644 --- a/cppu/source/uno/EnvStack.cxx +++ b/cppu/source/uno/EnvStack.cxx @@ -33,12 +33,15 @@ using namespace com::sun::star; +namespace { struct oslThreadIdentifier_equal { bool operator()(oslThreadIdentifier s1, oslThreadIdentifier s2) const; }; +} + bool oslThreadIdentifier_equal::operator()(oslThreadIdentifier s1, oslThreadIdentifier s2) const { bool result = s1 == s2; @@ -46,12 +49,15 @@ bool oslThreadIdentifier_equal::operator()(oslThreadIdentifier s1, oslThreadIden return result; } +namespace { struct oslThreadIdentifier_hash { size_t operator()(oslThreadIdentifier s1) const; }; +} + size_t oslThreadIdentifier_hash::operator()(oslThreadIdentifier s1) const { return s1; diff --git a/cppu/source/uno/IdentityMapping.cxx b/cppu/source/uno/IdentityMapping.cxx index 6b7ad09f98c6..c6dab40cefe8 100644 --- a/cppu/source/uno/IdentityMapping.cxx +++ b/cppu/source/uno/IdentityMapping.cxx @@ -28,6 +28,8 @@ using namespace ::com::sun::star; +namespace { + struct IdentityMapping : public uno_Mapping { sal_Int32 m_nRef; @@ -36,6 +38,8 @@ struct IdentityMapping : public uno_Mapping explicit IdentityMapping(uno::Environment const & rEnv); }; +} + extern "C" { diff --git a/cppu/source/uno/cascade_mapping.cxx b/cppu/source/uno/cascade_mapping.cxx index 13df4d8814e7..f57f7dc0ac87 100644 --- a/cppu/source/uno/cascade_mapping.cxx +++ b/cppu/source/uno/cascade_mapping.cxx @@ -30,6 +30,8 @@ using namespace com::sun::star; +namespace { + class MediatorMapping : public uno_Mapping { oslInterlockedCount m_refCount; @@ -53,6 +55,8 @@ public: uno_Environment * pTo); }; +} + extern "C" { static void s_acquire(uno_Mapping * mapping) { diff --git a/cppu/source/uno/lbmap.cxx b/cppu/source/uno/lbmap.cxx index a97d2a0dc829..ad27087b9b02 100644 --- a/cppu/source/uno/lbmap.cxx +++ b/cppu/source/uno/lbmap.cxx @@ -53,6 +53,8 @@ using namespace com::sun::star::uno; namespace cppu { +namespace { + class Mapping { uno_Mapping * _pMapping; @@ -80,6 +82,8 @@ public: { return (_pMapping != nullptr); } }; +} + inline Mapping::Mapping( uno_Mapping * pMapping ) : _pMapping( pMapping ) { @@ -110,6 +114,7 @@ inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) return *this; } +namespace { struct MappingEntry { @@ -134,6 +139,8 @@ struct FctPtrHash { return reinterpret_cast<size_t>(pKey); } }; +} + typedef std::unordered_map< OUString, MappingEntry * > t_OUString2Entry; typedef std::unordered_map< @@ -141,6 +148,7 @@ typedef std::unordered_map< typedef set< uno_getMappingFunc > t_CallbackSet; +namespace { struct MappingsData { @@ -155,6 +163,8 @@ struct MappingsData set<OUString> aNegativeLibs; }; +} + static MappingsData & getMappingsData() { //TODO This memory is leaked; see #i63473# for when this should be @@ -164,6 +174,8 @@ static MappingsData & getMappingsData() return *s_p; } +namespace { + /** * This class mediates two different mapping via uno, e.g. form any language to uno, * then from uno to any other language. @@ -185,6 +197,9 @@ struct uno_Mediate_Mapping : public uno_Mapping const Mapping & rFrom2Uno_, const Mapping & rUno2To_, const OUString & rAddPurpose ); }; + +} + extern "C" { |