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 /stoc | |
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 'stoc')
-rw-r--r-- | stoc/source/corereflection/crcomp.cxx | 3 | ||||
-rw-r--r-- | stoc/source/corereflection/crenum.cxx | 3 | ||||
-rw-r--r-- | stoc/source/corereflection/criface.cxx | 6 | ||||
-rw-r--r-- | stoc/source/implementationregistration/mergekeys.cxx | 5 | ||||
-rw-r--r-- | stoc/source/invocation/invocation.cxx | 8 | ||||
-rw-r--r-- | stoc/source/invocation_adapterfactory/iafactory.cxx | 8 | ||||
-rw-r--r-- | stoc/source/javaloader/javaloader.cxx | 4 | ||||
-rw-r--r-- | stoc/source/namingservice/namingservice.cxx | 2 | ||||
-rw-r--r-- | stoc/source/security/permissions.cxx | 9 | ||||
-rw-r--r-- | stoc/source/typeconv/convert.cxx | 3 |
10 files changed, 51 insertions, 0 deletions
diff --git a/stoc/source/corereflection/crcomp.cxx b/stoc/source/corereflection/crcomp.cxx index 0e05a88192fb..a42ee6742f92 100644 --- a/stoc/source/corereflection/crcomp.cxx +++ b/stoc/source/corereflection/crcomp.cxx @@ -33,6 +33,7 @@ using namespace css::uno; namespace stoc_corefl { +namespace { class IdlCompFieldImpl : public IdlMemberImpl @@ -70,6 +71,8 @@ public: virtual void SAL_CALL set( Any & rObj, const Any & rValue ) override; }; +} + // XInterface Any IdlCompFieldImpl::queryInterface( const Type & rType ) diff --git a/stoc/source/corereflection/crenum.cxx b/stoc/source/corereflection/crenum.cxx index bbe3fa3e800e..a225a2b63f25 100644 --- a/stoc/source/corereflection/crenum.cxx +++ b/stoc/source/corereflection/crenum.cxx @@ -31,6 +31,7 @@ using namespace css::uno; namespace stoc_corefl { +namespace { class IdlEnumFieldImpl : public IdlMemberImpl @@ -67,6 +68,8 @@ public: virtual void SAL_CALL set( Any & rObj, const Any & rValue ) override; }; +} + // XInterface Any IdlEnumFieldImpl::queryInterface( const Type & rType ) diff --git a/stoc/source/corereflection/criface.cxx b/stoc/source/corereflection/criface.cxx index 8dd7d55e7fd7..f958994d7b1d 100644 --- a/stoc/source/corereflection/criface.cxx +++ b/stoc/source/corereflection/criface.cxx @@ -55,6 +55,7 @@ std::size_t multipleOf16(std::size_t n) { namespace stoc_corefl { +namespace { class IdlAttributeFieldImpl : public IdlMemberImpl @@ -95,6 +96,8 @@ private: uno_Any * exception, Reference< XInterface > const & context) const; }; +} + // XInterface Any IdlAttributeFieldImpl::queryInterface( const Type & rType ) @@ -313,6 +316,7 @@ void IdlAttributeFieldImpl::checkException( cppu::throwException(e); } +namespace { class IdlInterfaceMethodImpl : public IdlMemberImpl @@ -352,6 +356,8 @@ public: virtual Any SAL_CALL invoke( const Any & rObj, Sequence< Any > & rArgs ) override; }; +} + // XInterface Any IdlInterfaceMethodImpl::queryInterface( const Type & rType ) diff --git a/stoc/source/implementationregistration/mergekeys.cxx b/stoc/source/implementationregistration/mergekeys.cxx index 0fddd887d732..1a8f8fcce8c4 100644 --- a/stoc/source/implementationregistration/mergekeys.cxx +++ b/stoc/source/implementationregistration/mergekeys.cxx @@ -33,6 +33,8 @@ using namespace ::com::sun::star; namespace stoc_impreg { +namespace { + struct Link { OUString const m_name; @@ -43,6 +45,9 @@ struct Link , m_target( target ) {} }; + +} + typedef ::std::vector< Link > t_links; diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx index 0969578620db..d70ed15cc2b8 100644 --- a/stoc/source/invocation/invocation.cxx +++ b/stoc/source/invocation/invocation.cxx @@ -81,6 +81,7 @@ static Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< return xRefl->forName( rType.getTypeName() ); } +namespace { class Invocation_Impl : public OWeakObject @@ -214,6 +215,7 @@ private: bool const mbFromOLE; }; +} Invocation_Impl::Invocation_Impl ( @@ -694,6 +696,7 @@ Any Invocation_Impl::invoke( const OUString& FunctionName, const Sequence<Any>& throw aExc; } +namespace { // Struct to optimize sorting struct MemberItem @@ -708,6 +711,8 @@ struct MemberItem sal_Int32 nIndex; }; +} + // Implementation of getting name or info // String sequence will be filled when pStringSeq != NULL // Info sequence will be filled when pInfoSeq != NULL @@ -1004,6 +1009,7 @@ Sequence< sal_Int8 > SAL_CALL Invocation_Impl::getImplementationId( ) return css::uno::Sequence<sal_Int8>(); } +namespace { class InvocationService : public WeakImplHelper< XSingleServiceFactory, XServiceInfo > @@ -1028,6 +1034,8 @@ private: Reference<XIdlReflection> xCoreReflection; }; +} + InvocationService::InvocationService( const Reference<XComponentContext> & xCtx ) : mxCtx( xCtx ) , mxSMgr( xCtx->getServiceManager() ) diff --git a/stoc/source/invocation_adapterfactory/iafactory.cxx b/stoc/source/invocation_adapterfactory/iafactory.cxx index 4a8c716dbeb4..4aecc1899c69 100644 --- a/stoc/source/invocation_adapterfactory/iafactory.cxx +++ b/stoc/source/invocation_adapterfactory/iafactory.cxx @@ -68,14 +68,20 @@ static OUString invadp_getImplementationName() return IMPLNAME; } +namespace { + struct hash_ptr { size_t operator() ( void * p ) const { return reinterpret_cast<size_t>(p); } }; + +} + typedef std::unordered_set< void *, hash_ptr > t_ptr_set; typedef std::unordered_map< void *, t_ptr_set, hash_ptr > t_ptr_map; +namespace { class FactoryImpl : public ::cppu::WeakImplHelper< lang::XServiceInfo, @@ -161,6 +167,8 @@ struct AdapterImpl AdapterImpl & operator= (const AdapterImpl &) = delete; }; +} + inline AdapterImpl::~AdapterImpl() { for ( size_t nPos = m_vInterfaces.size(); nPos--; ) diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx index 4af288f737b8..274de5c79990 100644 --- a/stoc/source/javaloader/javaloader.cxx +++ b/stoc/source/javaloader/javaloader.cxx @@ -76,6 +76,8 @@ static OUString loader_getImplementationName() return "com.sun.star.comp.stoc.JavaComponentLoader"; } +namespace { + class JavaComponentLoader : public WeakImplHelper<XImplementationLoader, XServiceInfo> { css::uno::Reference<XComponentContext> m_xComponentContext; @@ -111,6 +113,8 @@ public: const OUString& implementationLoaderUrl, const OUString& locationUrl) override; }; +} + const css::uno::Reference<XImplementationLoader> & JavaComponentLoader::getJavaLoader() { MutexGuard aGuard(getInitMutex()); diff --git a/stoc/source/namingservice/namingservice.cxx b/stoc/source/namingservice/namingservice.cxx index 8b35ec58b3c5..6e613f11fd7d 100644 --- a/stoc/source/namingservice/namingservice.cxx +++ b/stoc/source/namingservice/namingservice.cxx @@ -57,6 +57,7 @@ static OUString ns_getImplementationName() typedef std::unordered_map< OUString, Reference<XInterface > > HashMap_OWString_Interface; +namespace { class NamingService_Impl : public WeakImplHelper < XServiceInfo, XNamingService > @@ -76,6 +77,7 @@ public: virtual void SAL_CALL revokeObject( const OUString& Name ) override; }; +} static Reference<XInterface> NamingService_Impl_create( SAL_UNUSED_PARAMETER const Reference<XComponentContext> & ) diff --git a/stoc/source/security/permissions.cxx b/stoc/source/security/permissions.cxx index 9568602c1fb4..ed05614bb2a0 100644 --- a/stoc/source/security/permissions.cxx +++ b/stoc/source/security/permissions.cxx @@ -96,6 +96,7 @@ static OUString makeStrings( return buf.makeStringAndClear(); } +namespace { class SocketPermission : public Permission { @@ -120,6 +121,8 @@ public: virtual OUString toString() const override; }; +} + char const * SocketPermission::s_actions [] = { "accept", "connect", "listen", "resolve", nullptr }; SocketPermission::SocketPermission( @@ -263,6 +266,7 @@ OUString SocketPermission::toString() const return buf.makeStringAndClear(); } +namespace { class FilePermission : public Permission { @@ -280,6 +284,8 @@ public: virtual OUString toString() const override; }; +} + char const * FilePermission::s_actions [] = { "read", "write", "execute", "delete", nullptr }; static OUString const & getWorkingDir() @@ -406,6 +412,7 @@ OUString FilePermission::toString() const return buf.makeStringAndClear(); } +namespace { class RuntimePermission : public Permission { @@ -422,6 +429,8 @@ public: virtual OUString toString() const override; }; +} + bool RuntimePermission::implies( Permission const & perm ) const { // check type diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx index b74a3d1a5714..37d6c63e3d4b 100644 --- a/stoc/source/typeconv/convert.cxx +++ b/stoc/source/typeconv/convert.cxx @@ -208,6 +208,7 @@ static bool getHyperValue( sal_Int64 & rnVal, const OUString & rStr ) return false; } +namespace { class TypeConverter_Impl : public WeakImplHelper< XTypeConverter, XServiceInfo > { @@ -231,6 +232,8 @@ public: virtual Any SAL_CALL convertToSimpleType( const Any& aFrom, TypeClass aDestinationType ) override; }; +} + TypeConverter_Impl::TypeConverter_Impl() {} // XServiceInfo |