summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-11-19 16:32:49 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-11-22 12:57:32 +0100
commitf853ec317f6af1b8c65cc5bd758371689c75118d (patch)
treeb86d729bf9a9465ee619ead3b5635efa62a1804e /comphelper
parentf31d36966bceb90e261cbecd42634bde4448d527 (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 'comphelper')
-rw-r--r--comphelper/qa/container/comphelper_ifcontainer.cxx4
-rw-r--r--comphelper/source/compare/AnyCompareFactory.cxx4
-rw-r--r--comphelper/source/container/IndexedPropertyValuesContainer.cxx4
-rw-r--r--comphelper/source/container/NamedPropertyValuesContainer.cxx4
-rw-r--r--comphelper/source/container/enumerablemap.cxx20
-rw-r--r--comphelper/source/container/namecontainer.cxx4
-rw-r--r--comphelper/source/eventattachermgr/eventattachermgr.cxx2
-rw-r--r--comphelper/source/misc/anycompare.cxx3
-rw-r--r--comphelper/source/misc/asyncnotification.cxx11
-rw-r--r--comphelper/source/misc/docpasswordrequest.cxx2
-rw-r--r--comphelper/source/misc/random.cxx4
-rw-r--r--comphelper/source/misc/threadpool.cxx4
-rw-r--r--comphelper/source/property/MasterPropertySet.cxx4
-rw-r--r--comphelper/source/property/genericpropertyset.cxx3
-rw-r--r--comphelper/source/streaming/memorystream.cxx4
-rw-r--r--comphelper/source/xml/ofopxmlhelper.cxx3
16 files changed, 76 insertions, 4 deletions
diff --git a/comphelper/qa/container/comphelper_ifcontainer.cxx b/comphelper/qa/container/comphelper_ifcontainer.cxx
index 8bd9bf75f660..4d28c496fe2e 100644
--- a/comphelper/qa/container/comphelper_ifcontainer.cxx
+++ b/comphelper/qa/container/comphelper_ifcontainer.cxx
@@ -31,6 +31,8 @@ using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
+namespace {
+
struct ContainerStats {
int m_nAlive;
int m_nDisposed;
@@ -50,6 +52,8 @@ public:
}
};
+}
+
namespace comphelper_ifcontainer
{
static const int nTests = 10;
diff --git a/comphelper/source/compare/AnyCompareFactory.cxx b/comphelper/source/compare/AnyCompareFactory.cxx
index e4cec19feeed..7a31f10f1f71 100644
--- a/comphelper/source/compare/AnyCompareFactory.cxx
+++ b/comphelper/source/compare/AnyCompareFactory.cxx
@@ -31,6 +31,8 @@ using namespace com::sun::star::ucb;
using namespace com::sun::star::lang;
using namespace com::sun::star::i18n;
+namespace {
+
class AnyCompare : public ::cppu::WeakImplHelper< XAnyCompare >
{
Reference< XCollator > m_xCollator;
@@ -68,6 +70,8 @@ public:
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
};
+}
+
sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 )
{
sal_Int16 aResult = 0;
diff --git a/comphelper/source/container/IndexedPropertyValuesContainer.cxx b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
index 0053cc8e4374..ecd1c2dbb2f8 100644
--- a/comphelper/source/container/IndexedPropertyValuesContainer.cxx
+++ b/comphelper/source/container/IndexedPropertyValuesContainer.cxx
@@ -34,6 +34,8 @@ using namespace com::sun::star;
typedef std::vector < uno::Sequence< beans::PropertyValue > > IndexedPropertyValues;
+namespace {
+
class IndexedPropertyValuesContainer : public cppu::WeakImplHelper< container::XIndexContainer, lang::XServiceInfo >
{
public:
@@ -63,6 +65,8 @@ private:
IndexedPropertyValues maProperties;
};
+}
+
IndexedPropertyValuesContainer::IndexedPropertyValuesContainer() throw()
{
}
diff --git a/comphelper/source/container/NamedPropertyValuesContainer.cxx b/comphelper/source/container/NamedPropertyValuesContainer.cxx
index 13b8f855866f..79a7d714b5e6 100644
--- a/comphelper/source/container/NamedPropertyValuesContainer.cxx
+++ b/comphelper/source/container/NamedPropertyValuesContainer.cxx
@@ -32,6 +32,8 @@ using namespace com::sun::star;
typedef std::map< OUString, uno::Sequence<beans::PropertyValue> > NamedPropertyValues;
+namespace {
+
class NamedPropertyValuesContainer : public cppu::WeakImplHelper< container::XNameContainer, lang::XServiceInfo >
{
public:
@@ -62,6 +64,8 @@ private:
NamedPropertyValues maProperties;
};
+}
+
NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw()
{
}
diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx
index bee5d03963b2..f9e5cfa8989a 100644
--- a/comphelper/source/container/enumerablemap.cxx
+++ b/comphelper/source/container/enumerablemap.cxx
@@ -76,9 +76,16 @@ namespace comphelper
using ::com::sun::star::uno::TypeDescription;
using ::com::sun::star::lang::DisposedException;
+ namespace {
+
class MapEnumerator;
+ }
+
typedef std::map< Any, Any, LessPredicateAdapter > KeyedValues;
+
+ namespace {
+
struct MapData
{
Type m_aKeyType;
@@ -106,6 +113,7 @@ namespace comphelper
MapData& operator=( const MapData& _source ) = delete;
};
+ }
static void lcl_registerMapModificationListener( MapData& _mapData, MapEnumerator& _listener )
{
@@ -141,6 +149,8 @@ namespace comphelper
, XServiceInfo
> Map_IFace;
+ namespace {
+
class EnumerableMap: public Map_IFace, public ComponentBase
{
protected:
@@ -194,15 +204,11 @@ namespace comphelper
MapData m_aData;
};
- namespace {
-
enum EnumerationType
{
eKeys, eValues, eBoth
};
- }
-
class MapEnumerator final
{
public:
@@ -249,6 +255,8 @@ namespace comphelper
bool m_disposed;
};
+ }
+
static void lcl_notifyMapDataListeners_nothrow( const MapData& _mapData )
{
for ( MapEnumerator* loop : _mapData.m_aModListeners )
@@ -259,6 +267,9 @@ namespace comphelper
typedef ::cppu::WeakImplHelper < XEnumeration
> MapEnumeration_Base;
+
+ namespace {
+
class MapEnumeration :public ComponentBase
,public MapEnumeration_Base
{
@@ -294,6 +305,7 @@ namespace comphelper
MapEnumerator m_aEnumerator;
};
+ }
EnumerableMap::EnumerableMap()
:Map_IFace( m_aMutex )
diff --git a/comphelper/source/container/namecontainer.cxx b/comphelper/source/container/namecontainer.cxx
index 0f905fac9124..bed257ca50c7 100644
--- a/comphelper/source/container/namecontainer.cxx
+++ b/comphelper/source/container/namecontainer.cxx
@@ -31,6 +31,8 @@ typedef std::map<OUString, css::uno::Any> SvGenericNameContainerMapImpl;
namespace comphelper
{
+ namespace {
+
/** this is the base helper class for NameContainer that's also declared in this header. */
class NameContainer : public ::cppu::WeakImplHelper< css::container::XNameContainer >
{
@@ -58,6 +60,8 @@ namespace comphelper
const css::uno::Type maType;
osl::Mutex maMutex;
};
+
+ }
}
using namespace ::comphelper;
diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx
index 209d0ac6deb6..6651c6033bb6 100644
--- a/comphelper/source/eventattachermgr/eventattachermgr.cxx
+++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx
@@ -62,6 +62,7 @@ using namespace osl;
namespace comphelper
{
+namespace {
struct AttachedObject_Impl
{
@@ -149,6 +150,7 @@ public:
virtual void SAL_CALL disposing(const EventObject& Source) override;
};
+}
AttacherAllListener_Impl::AttacherAllListener_Impl
(
diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx
index f4d2a8b5d260..bb77544c957e 100644
--- a/comphelper/source/misc/anycompare.cxx
+++ b/comphelper/source/misc/anycompare.cxx
@@ -49,6 +49,8 @@ namespace comphelper
using ::com::sun::star::util::Time;
using ::com::sun::star::util::DateTime;
+ namespace {
+
class DatePredicateLess : public IKeyPredicateLess
{
public:
@@ -158,6 +160,7 @@ namespace comphelper
}
};
+ }
std::unique_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator )
{
diff --git a/comphelper/source/misc/asyncnotification.cxx b/comphelper/source/misc/asyncnotification.cxx
index c73bd22cf163..a360b7207fe4 100644
--- a/comphelper/source/misc/asyncnotification.cxx
+++ b/comphelper/source/misc/asyncnotification.cxx
@@ -38,6 +38,8 @@ namespace comphelper
{
}
+ namespace {
+
struct ProcessableEvent
{
AnyEventRef aEvent;
@@ -54,9 +56,11 @@ namespace comphelper
}
};
+ }
typedef std::deque< ProcessableEvent > EventQueue;
+ namespace {
struct EqualProcessor
{
@@ -69,6 +73,8 @@ namespace comphelper
}
};
+ }
+
struct EventNotifierImpl
{
::osl::Mutex aMutex;
@@ -178,7 +184,12 @@ namespace comphelper
return AsyncEventNotifierBase::terminate();
}
+ namespace {
+
struct theNotifiersMutex : public rtl::Static<osl::Mutex, theNotifiersMutex> {};
+
+ }
+
static std::vector<std::weak_ptr<AsyncEventNotifierAutoJoin>> g_Notifiers;
void JoinAsyncEventNotifiers()
diff --git a/comphelper/source/misc/docpasswordrequest.cxx b/comphelper/source/misc/docpasswordrequest.cxx
index e1092df36f0b..56644d4d6e59 100644
--- a/comphelper/source/misc/docpasswordrequest.cxx
+++ b/comphelper/source/misc/docpasswordrequest.cxx
@@ -41,6 +41,7 @@ using ::com::sun::star::task::XInteractionPassword2;
namespace comphelper {
+namespace {
class AbortContinuation : public ::cppu::WeakImplHelper< XInteractionAbort >
{
@@ -48,6 +49,7 @@ public:
virtual void SAL_CALL select() override {}
};
+}
class PasswordContinuation : public ::cppu::WeakImplHelper< XInteractionPassword2 >
{
diff --git a/comphelper/source/misc/random.cxx b/comphelper/source/misc/random.cxx
index ddc970efe321..f001b06195d6 100644
--- a/comphelper/source/misc/random.cxx
+++ b/comphelper/source/misc/random.cxx
@@ -38,6 +38,8 @@ namespace rng
// http://en.wikipedia.org/wiki/Mersenne_twister
#define STD_RNG_ALGO std::mt19937
+namespace {
+
struct RandomNumberGenerator
{
std::mutex mutex;
@@ -77,6 +79,8 @@ struct RandomNumberGenerator
class theRandomNumberGenerator : public rtl::Static<RandomNumberGenerator, theRandomNumberGenerator> {};
+}
+
// uniform ints [a,b] distribution
int uniform_int_distribution(int a, int b)
{
diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx
index 95b6f2dff091..9b1991b7f3a1 100644
--- a/comphelper/source/misc/threadpool.cxx
+++ b/comphelper/source/misc/threadpool.cxx
@@ -105,6 +105,8 @@ ThreadPool::~ThreadPool()
assert(maTasks.empty());
}
+namespace {
+
struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPool >,
ThreadPoolStatic >
{
@@ -114,6 +116,8 @@ struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPoo
};
};
+}
+
ThreadPool& ThreadPool::getSharedOptimalPool()
{
return *ThreadPoolStatic::get();
diff --git a/comphelper/source/property/MasterPropertySet.cxx b/comphelper/source/property/MasterPropertySet.cxx
index 61e6f84ecdd5..82f9d85d7525 100644
--- a/comphelper/source/property/MasterPropertySet.cxx
+++ b/comphelper/source/property/MasterPropertySet.cxx
@@ -28,6 +28,8 @@
#include <memory>
#include <vector>
+namespace {
+
class AutoOGuardArray
{
std::vector<std::unique_ptr< osl::Guard< comphelper::SolarMutex > >> maGuardArray;
@@ -38,6 +40,8 @@ public:
std::unique_ptr< osl::Guard< comphelper::SolarMutex > > & operator[] ( sal_Int32 i ) { return maGuardArray[i]; }
};
+}
+
AutoOGuardArray::AutoOGuardArray( sal_Int32 nNumElements ) : maGuardArray(nNumElements)
{
}
diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx
index b5414b5c52d8..72cec45e2992 100644
--- a/comphelper/source/property/genericpropertyset.cxx
+++ b/comphelper/source/property/genericpropertyset.cxx
@@ -42,6 +42,8 @@ using namespace ::com::sun::star::lang;
namespace comphelper
{
+ namespace {
+
struct IMPL_GenericPropertySet_MutexContainer
{
Mutex maMutex;
@@ -84,6 +86,7 @@ namespace comphelper
virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
};
+ }
}
diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx
index 8d120989eec6..940c9012f149 100644
--- a/comphelper/source/streaming/memorystream.cxx
+++ b/comphelper/source/streaming/memorystream.cxx
@@ -45,6 +45,8 @@ using namespace ::osl;
namespace comphelper
{
+namespace {
+
class UNOMemoryStream : public WeakImplHelper<XServiceInfo, XStream, XSeekableInputStream, XOutputStream, XTruncate>
{
public:
@@ -84,6 +86,8 @@ private:
sal_Int32 mnCursor;
};
+}
+
UNOMemoryStream::UNOMemoryStream()
: mnCursor(0)
{
diff --git a/comphelper/source/xml/ofopxmlhelper.cxx b/comphelper/source/xml/ofopxmlhelper.cxx
index 21f097531363..46785b35cbba 100644
--- a/comphelper/source/xml/ofopxmlhelper.cxx
+++ b/comphelper/source/xml/ofopxmlhelper.cxx
@@ -39,6 +39,8 @@ using namespace ::com::sun::star;
namespace comphelper {
+namespace {
+
// this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format
class OFOPXMLHelper_Impl
: public cppu::WeakImplHelper< css::xml::sax::XDocumentHandler >
@@ -65,6 +67,7 @@ public:
virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
};
+}
namespace OFOPXMLHelper {