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 /sdext | |
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 'sdext')
-rw-r--r-- | sdext/source/minimizer/pppoptimizertoken.cxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/filterdet.cxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/odf/odfemitter.cxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/pdfparse/pdfparse.cxx | 3 | ||||
-rw-r--r-- | sdext/source/pdfimport/test/pdfunzip.cxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/treevisitorfactory.cxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/wrapper/wrapper.cxx | 4 | ||||
-rw-r--r-- | sdext/source/presenter/PresenterAccessibility.cxx | 8 |
8 files changed, 31 insertions, 4 deletions
diff --git a/sdext/source/minimizer/pppoptimizertoken.cxx b/sdext/source/minimizer/pppoptimizertoken.cxx index 31cb4ecb524a..d4d4c99c4ba5 100644 --- a/sdext/source/minimizer/pppoptimizertoken.cxx +++ b/sdext/source/minimizer/pppoptimizertoken.cxx @@ -32,12 +32,16 @@ static ::osl::Mutex& getHashMapMutex() return s_aHashMapProtection; } +namespace { + struct TokenTable { const char* pS; PPPOptimizerTokenEnum const pE; }; +} + static const TokenTable pTokenTableArray[] = { { "rdmNavi", TK_rdmNavi }, diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx index 03931f47edb0..004d2d813abf 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -46,6 +46,8 @@ namespace pdfi // TODO(T3): locking/thread safety +namespace { + class FileEmitContext : public pdfparse::EmitContext { private: @@ -69,6 +71,8 @@ public: const uno::Reference< io::XStream >& getContextStream() const { return m_xContextStream; } }; +} + FileEmitContext::FileEmitContext( const OUString& rOrigFile, const uno::Reference< uno::XComponentContext >& xContext, const pdfparse::PDFContainer* pTop ) : diff --git a/sdext/source/pdfimport/odf/odfemitter.cxx b/sdext/source/pdfimport/odf/odfemitter.cxx index dd5b4e5872b7..b191462eef15 100644 --- a/sdext/source/pdfimport/odf/odfemitter.cxx +++ b/sdext/source/pdfimport/odf/odfemitter.cxx @@ -31,6 +31,8 @@ using namespace com::sun::star; namespace pdfi { +namespace { + class OdfEmitter : public XmlEmitter { private: @@ -46,6 +48,8 @@ public: virtual void endTag( const char* pTag ) override; }; +} + OdfEmitter::OdfEmitter( const uno::Reference<io::XOutputStream>& xOutput ) : m_xOutput( xOutput ), m_aLineFeed(1), diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx b/sdext/source/pdfimport/pdfparse/pdfparse.cxx index 0be394d58eb1..03dd5aca4dea 100644 --- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx @@ -52,6 +52,7 @@ using namespace boost::spirit; using namespace pdfparse; +namespace { class StringEmitContext : public EmitContext { @@ -548,6 +549,8 @@ public: } }; +} + #ifdef _WIN32 std::unique_ptr<PDFEntry> PDFReader::read( const char* pBuffer, unsigned int nLen ) { diff --git a/sdext/source/pdfimport/test/pdfunzip.cxx b/sdext/source/pdfimport/test/pdfunzip.cxx index 7d27aaf3253d..7c857e884bd6 100644 --- a/sdext/source/pdfimport/test/pdfunzip.cxx +++ b/sdext/source/pdfimport/test/pdfunzip.cxx @@ -52,6 +52,8 @@ static void printHelp( const char* pExe ) , pExe, pExe, pExe, pExe, pExe ); } +namespace { + class FileEmitContext : public EmitContext { oslFileHandle m_aHandle; @@ -70,6 +72,8 @@ class FileEmitContext : public EmitContext virtual unsigned int readOrigBytes( unsigned int nOrigOffset, unsigned int nLen, void* pBuf ) throw() override; }; +} + FileEmitContext::FileEmitContext( const char* pFileName, const char* pOrigName, const PDFContainer* pTop ) : EmitContext( pTop ), m_aHandle( nullptr ), diff --git a/sdext/source/pdfimport/tree/treevisitorfactory.cxx b/sdext/source/pdfimport/tree/treevisitorfactory.cxx index 094fe0935c22..a9cf73cc2aa8 100644 --- a/sdext/source/pdfimport/tree/treevisitorfactory.cxx +++ b/sdext/source/pdfimport/tree/treevisitorfactory.cxx @@ -24,6 +24,8 @@ namespace pdfi { + namespace { + struct WriterTreeVisitorFactory : public TreeVisitorFactory { WriterTreeVisitorFactory() {} @@ -94,6 +96,8 @@ namespace pdfi } }; + } + TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory() { return TreeVisitorFactorySharedPtr(new WriterTreeVisitorFactory()); diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index 3d36e77110be..5074258605a5 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -952,6 +952,8 @@ static bool checkEncryption( const OUString& i_rPa return bSuccess; } +namespace { + class Buffering { static const int SIZE = 64*1024; @@ -991,6 +993,8 @@ public: } }; +} + bool xpdf_ImportFromFile(const OUString& rURL, const ContentSinkSharedPtr& rSink, const uno::Reference<task::XInteractionHandler>& xIHdl, diff --git a/sdext/source/presenter/PresenterAccessibility.cxx b/sdext/source/presenter/PresenterAccessibility.cxx index 14c3c81ede7f..c69f3f15b96f 100644 --- a/sdext/source/presenter/PresenterAccessibility.cxx +++ b/sdext/source/presenter/PresenterAccessibility.cxx @@ -198,7 +198,6 @@ namespace { typedef ::cppu::WeakComponentImplHelper < css::accessibility::XAccessibleStateSet > AccessibleStateSetInterfaceBase; -} class AccessibleStateSet : public ::cppu::BaseMutex, @@ -225,11 +224,9 @@ private: //===== AccessibleRelationSet ================================================= -namespace { typedef ::cppu::WeakComponentImplHelper < css::accessibility::XAccessibleRelationSet > AccessibleRelationSetInterfaceBase; -} class AccessibleRelationSet : public ::cppu::BaseMutex, @@ -258,7 +255,6 @@ private: //===== PresenterAccessibleParagraph ========================================== -namespace { typedef ::cppu::ImplInheritanceHelper < PresenterAccessible::AccessibleObject, css::accessibility::XAccessibleText @@ -340,6 +336,8 @@ private: //===== AccessibleConsole ===================================================== +namespace { + class AccessibleConsole { public: @@ -453,6 +451,8 @@ private: AccessibleFocusManager(); }; +} + //===== PresenterAccessible =================================================== PresenterAccessible::PresenterAccessible ( |