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 /sal/osl/unx | |
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 'sal/osl/unx')
-rw-r--r-- | sal/osl/unx/conditn.cxx | 4 | ||||
-rw-r--r-- | sal/osl/unx/file.cxx | 4 | ||||
-rw-r--r-- | sal/osl/unx/file_path_helper.cxx | 4 | ||||
-rw-r--r-- | sal/osl/unx/process.cxx | 4 | ||||
-rw-r--r-- | sal/osl/unx/process_impl.cxx | 8 | ||||
-rw-r--r-- | sal/osl/unx/profile.cxx | 4 | ||||
-rw-r--r-- | sal/osl/unx/thread.cxx | 20 |
7 files changed, 46 insertions, 2 deletions
diff --git a/sal/osl/unx/conditn.cxx b/sal/osl/unx/conditn.cxx index cede35a86d04..d73d67e91b37 100644 --- a/sal/osl/unx/conditn.cxx +++ b/sal/osl/unx/conditn.cxx @@ -29,6 +29,8 @@ #include <osl/conditn.h> #include <osl/time.h> +namespace { + struct oslConditionImpl { pthread_cond_t m_Condition; @@ -36,6 +38,8 @@ struct oslConditionImpl bool m_State; }; +} + oslCondition SAL_CALL osl_createCondition() { oslConditionImpl* pCond; diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index b6a0acaae2c4..cfd71419d3fe 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -60,6 +60,8 @@ #include <android/asset_manager.h> #endif +namespace { + struct FileHandle_Impl { pthread_mutex_t m_mutex; @@ -155,6 +157,8 @@ struct FileHandle_Impl }; }; +} + FileHandle_Impl::Guard::Guard(pthread_mutex_t * pMutex) : m_mutex(pMutex) { diff --git a/sal/osl/unx/file_path_helper.cxx b/sal/osl/unx/file_path_helper.cxx index 4d629f849868..163deb0c2493 100644 --- a/sal/osl/unx/file_path_helper.cxx +++ b/sal/osl/unx/file_path_helper.cxx @@ -158,6 +158,8 @@ bool osl_systemPathIsLocalOrParentDirectoryEntry( dirent == ".."); } +namespace { + /** Simple iterator for a path list separated by the specified character */ class path_list_iterator @@ -225,6 +227,8 @@ private: const sal_Unicode* m_path_segment_end; }; +} + bool osl_searchPath( const rtl_uString* pustrFilePath, const rtl_uString* pustrSearchPathList, diff --git a/sal/osl/unx/process.cxx b/sal/osl/unx/process.cxx index 41d6de0b04ea..d479e0d40cfc 100644 --- a/sal/osl/unx/process.cxx +++ b/sal/osl/unx/process.cxx @@ -788,6 +788,8 @@ void SAL_CALL osl_freeProcessHandle(oslProcess Process) } #if defined(LINUX) +namespace { + struct osl_procStat { /* from 'stat' */ @@ -848,6 +850,8 @@ struct osl_procStat unsigned long vm_lib; /* library size */ }; +} + static bool osl_getProcStat(pid_t pid, struct osl_procStat* procstat) { int fd = 0; diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx index 35a5b90ece0d..fe7dc9db5ccf 100644 --- a/sal/osl/unx/process_impl.cxx +++ b/sal/osl/unx/process_impl.cxx @@ -140,6 +140,8 @@ oslProcessError bootstrap_getExecutableFile(rtl_uString ** ppFileURL) #endif +namespace { + struct CommandArgs_Impl { pthread_mutex_t m_mutex; @@ -147,6 +149,8 @@ struct CommandArgs_Impl rtl_uString ** m_ppArgs; }; +} + static struct CommandArgs_Impl g_command_args = { PTHREAD_MUTEX_INITIALIZER, @@ -409,12 +413,16 @@ oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir return result; } +namespace { + struct ProcessLocale_Impl { pthread_mutex_t m_mutex; rtl_Locale * m_pLocale; }; +} + static struct ProcessLocale_Impl g_process_locale = { PTHREAD_MUTEX_INITIALIZER, diff --git a/sal/osl/unx/profile.cxx b/sal/osl/unx/profile.cxx index ad8868b5490c..717316c0817c 100644 --- a/sal/osl/unx/profile.cxx +++ b/sal/osl/unx/profile.cxx @@ -58,8 +58,6 @@ enum osl_TLockMode un_lock, read_lock, write_lock }; -} - struct osl_TFile { int m_Handle; @@ -104,6 +102,8 @@ struct osl_TProfileImpl bool m_bIsValid; }; +} + static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption ProfileFlags); static osl_TStamp closeFileImpl(osl_TFile* pFile, oslProfileOption Flags); static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode); diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx index 5ea77495daa6..fb694ebd92cd 100644 --- a/sal/osl/unx/thread.cxx +++ b/sal/osl/unx/thread.cxx @@ -75,6 +75,8 @@ #define THREADIMPL_FLAGS_ATTACHED 0x00010 #define THREADIMPL_FLAGS_DESTROYED 0x00020 +namespace { + typedef struct osl_thread_impl_st { pthread_t m_hThread; @@ -95,18 +97,26 @@ struct osl_thread_priority_st int m_Lowest; }; +} + #define OSL_THREAD_PRIORITY_INITIALIZER { 127, 96, 64, 32, 0 } static void osl_thread_priority_init_Impl(); +namespace { + struct osl_thread_textencoding_st { pthread_key_t m_key; /* key to store thread local text encoding */ rtl_TextEncoding m_default; /* the default text encoding */ }; +} + #define OSL_THREAD_TEXTENCODING_INITIALIZER { 0, RTL_TEXTENCODING_DONTKNOW } static void osl_thread_textencoding_init_Impl(); +namespace { + struct osl_thread_global_st { pthread_once_t m_once; @@ -114,6 +124,8 @@ struct osl_thread_global_st struct osl_thread_textencoding_st m_textencoding; }; +} + static struct osl_thread_global_st g_thread = { PTHREAD_ONCE_INIT, @@ -555,6 +567,8 @@ void SAL_CALL osl_setThreadName(char const * name) /* osl_getThreadIdentifier @@@ see TODO @@@ */ +namespace { + struct HashEntry { pthread_t Handle; @@ -562,6 +576,8 @@ struct HashEntry HashEntry * Next; }; +} + static HashEntry* HashTable[31]; static const int HashSize = SAL_N_ELEMENTS(HashTable); @@ -951,12 +967,16 @@ oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread) return Priority; } +namespace { + struct wrapper_pthread_key { pthread_key_t m_key; oslThreadKeyCallbackFunction pfnCallback; }; +} + oslThreadKey SAL_CALL osl_createThreadKey( oslThreadKeyCallbackFunction pCallback ) { wrapper_pthread_key *pKey = static_cast<wrapper_pthread_key*>(malloc(sizeof(wrapper_pthread_key))); |