summaryrefslogtreecommitdiff
path: root/sal/inc
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-01-21 15:21:16 +0100
committerStephan Bergmann <sbergman@redhat.com>2012-01-21 15:21:16 +0100
commit7c704c78d3c652504c064b4ac7af55a2c1ee49bb (patch)
tree623358cf25839219ef4fd90eea4f3eaa55389a1f /sal/inc
parent0d5167915b47df7c3e450614ea50d845ba959df3 (diff)
Removed some unused parameters; added SAL_UNUSED_PARAMETER.
SAL_UNUSED_PARAMETER (expanding to __attribute__ ((unused)) for GCC) is used to annotate legitimately unused parameters, so that static analysis tools can tell legitimately unused parameters from truly unnecessary ones. To that end, some patches for external modules are also added, that are only applied when compiling with GCC and add necessary __attribute__ ((unused)) in headers.
Diffstat (limited to 'sal/inc')
-rw-r--r--sal/inc/rtl/allocator.hxx11
-rw-r--r--sal/inc/rtl/string.hxx2
-rw-r--r--sal/inc/rtl/ustring.hxx2
-rw-r--r--sal/inc/sal/log.hxx12
-rw-r--r--sal/inc/sal/types.h31
5 files changed, 46 insertions, 12 deletions
diff --git a/sal/inc/rtl/allocator.hxx b/sal/inc/rtl/allocator.hxx
index 7a3ac10a1f30..36bbd0036685 100644
--- a/sal/inc/rtl/allocator.hxx
+++ b/sal/inc/rtl/allocator.hxx
@@ -88,7 +88,7 @@ public:
//-----------------------------------------
template<class U>
- Allocator (const Allocator<U>&) SAL_THROW(())
+ Allocator (SAL_UNUSED_PARAMETER const Allocator<U>&) SAL_THROW(())
{}
//-----------------------------------------
@@ -126,14 +126,14 @@ public:
are not enabled, e.g. GCC under Linux and it is
in general not desired to compile sal with exceptions
enabled. */
- pointer allocate (size_type n, const void* = 0)
+ pointer allocate (size_type n, SAL_UNUSED_PARAMETER const void* = 0)
{
return reinterpret_cast<pointer>(
rtl_allocateMemory(sal_uInt32(n * sizeof(T))));
}
//-----------------------------------------
- void deallocate (pointer p, size_type /* n */)
+ void deallocate (pointer p, SAL_UNUSED_PARAMETER size_type /* n */)
{
rtl_freeMemory(p);
}
@@ -157,8 +157,9 @@ public:
// references above) that's why the operators below
// return always true or false
-template<class T, class U>
-inline bool operator== (const Allocator<T>&, const Allocator<U>&) SAL_THROW(())
+template<class T, class U> inline bool operator ==(
+ SAL_UNUSED_PARAMETER const Allocator<T>&,
+ SAL_UNUSED_PARAMETER const Allocator<U>&) SAL_THROW(())
{
return true;
}
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 2bb7af39379e..e39e0e091cdf 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -82,7 +82,7 @@ public:
private:
class DO_NOT_ACQUIRE;
- OString( rtl_String * value, DO_NOT_ACQUIRE * )
+ OString( rtl_String * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
{
pData = value;
}
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 21bd99d87e07..f13f57cd6c20 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -83,7 +83,7 @@ public:
private:
class DO_NOT_ACQUIRE{};
- OUString( rtl_uString * value, DO_NOT_ACQUIRE * )
+ OUString( rtl_uString * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
{
pData = value;
}
diff --git a/sal/inc/sal/log.hxx b/sal/inc/sal/log.hxx
index 52a06477603c..ec1fdfa61830 100644
--- a/sal/inc/sal/log.hxx
+++ b/sal/inc/sal/log.hxx
@@ -83,12 +83,14 @@ struct StreamIgnore {
typedef struct { char a[2]; } Result;
};
-inline StreamString operator <<(StreamStart const &, char const * s) {
+inline StreamString operator <<(
+ SAL_UNUSED_PARAMETER StreamStart const &, char const * s)
+{
return StreamString(s);
}
template< typename T > inline StreamIgnore operator <<(
- StreamStart const &, T const &)
+ SAL_UNUSED_PARAMETER StreamStart const &, SAL_UNUSED_PARAMETER T const &)
{
std::abort();
#if defined _MSC_VER
@@ -97,7 +99,7 @@ template< typename T > inline StreamIgnore operator <<(
}
template< typename T > inline StreamIgnore operator <<(
- StreamString const &, T const &)
+ SAL_UNUSED_PARAMETER StreamString const &, SAL_UNUSED_PARAMETER T const &)
{
std::abort();
#if defined _MSC_VER
@@ -106,7 +108,7 @@ template< typename T > inline StreamIgnore operator <<(
}
template< typename T > inline StreamIgnore operator <<(
- StreamIgnore const &, T const &)
+ SAL_UNUSED_PARAMETER StreamIgnore const &, SAL_UNUSED_PARAMETER T const &)
{
std::abort();
#if defined _MSC_VER
@@ -118,7 +120,7 @@ template< typename T > typename T::Result getResult(T const &);
inline char const * unwrapStream(StreamString const & s) { return s.string; }
-inline char const * unwrapStream(StreamIgnore const &) {
+inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
std::abort();
#if defined _MSC_VER
return 0;
diff --git a/sal/inc/sal/types.h b/sal/inc/sal/types.h
index a331fe1bc391..6c613c060a50 100644
--- a/sal/inc/sal/types.h
+++ b/sal/inc/sal/types.h
@@ -479,6 +479,37 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
# define SAL_WNODEPRECATED_DECLARATIONS_POP
#endif
+/** Annotate unused but required C++ function parameters.
+
+ An unused parameter is required if the function needs to adhere to a given
+ type (e.g., if its address is assigned to a function pointer of a specific
+ type, or if it is called from template code). This annotation helps static
+ analysis tools suppress false warnings. In the case of virtual functions
+ (where unused required parameters are common, too), the annotation is not
+ required (as static analysis tools can themselves derive the information
+ whether a function is virtual).
+
+ Use the annotation in function definitions like
+
+ void f(SAL_UNUSED_PARAMETER int) {}
+
+ C does not allow unnamed parameters, anyway, so a function definition like
+ the above needs to be written there as
+
+ void f(int dummy) { (void) dummy; / * avoid warnings * / }
+
+ without a SAL_UNUSED_PARAMETER annotation.
+
+ @since LibreOffice 3.6
+ */
+#if defined __cplusplus
+#if defined __GNUC__
+#define SAL_UNUSED_PARAMETER __attribute__ ((unused))
+#else
+#define SAL_UNUSED_PARAMETER
+#endif
+#endif
+
#endif /*_SAL_TYPES_H_ */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */