From 50e403a0b423fd3d9baa48411d167ce00eb9f6b3 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 13 Mar 2018 08:58:26 +0100 Subject: [PATCH] Enable "unused result" warning for MSVC Bug:https://bugs.freedesktop.org/show_bug.cgi?id=105460 --- cmake/CMakeLists.txt | 3 +++ dbus/dbus-internals.c | 1 + dbus/dbus-internals.h | 5 +++-- dbus/dbus-macros.h | 12 +++++++++--- dbus/dbus-sysdeps.c | 1 + dbus/dbus-sysdeps.h | 4 +++- dbus/dbus-threads.c | 1 + 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6349adb..39546f8 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -218,6 +218,9 @@ if(MSVC) # 4114 same type qualifier used more than once # 4133 'type' : incompatible types - from 'type1' to 'type2' set(WARNINGS_ERRORS "4002 4003 4013 4028 4031 4047 4114 4133") + if(NOT MSVC LESS 1700) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /analyze") + endif() else() set(WARNINGS "sign-compare") set(WARNINGS_DISABLED "") diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 061c527..12cd19a 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -664,6 +664,7 @@ _dbus_string_array_length (const char **array) * @param error location to store reason for failure * @returns #TRUE on success */ +_DBUS_WARN_UNUSED_RESULT_IMPL dbus_bool_t _dbus_generate_uuid (DBusGUID *uuid, DBusError *error) diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 57a67d0..ae9ab62 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -366,7 +366,8 @@ typedef enum _DBUS_N_GLOBAL_LOCKS } DBusGlobalLock; -dbus_bool_t _dbus_lock (DBusGlobalLock lock) _DBUS_GNUC_WARN_UNUSED_RESULT; +_DBUS_WARN_UNUSED_RESULT +dbus_bool_t _dbus_lock (DBusGlobalLock lock); void _dbus_unlock (DBusGlobalLock lock); #define _DBUS_LOCK_NAME(name) _DBUS_LOCK_##name @@ -399,7 +400,7 @@ union DBusGUID char as_bytes[DBUS_UUID_LENGTH_BYTES]; /**< guid as 16 single-byte values */ }; -DBUS_PRIVATE_EXPORT _DBUS_GNUC_WARN_UNUSED_RESULT +DBUS_PRIVATE_EXPORT _DBUS_WARN_UNUSED_RESULT dbus_bool_t _dbus_generate_uuid (DBusGUID *uuid, DBusError *error); DBUS_PRIVATE_EXPORT diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h index 2c8956e..52b2503 100644 --- a/dbus/dbus-macros.h +++ b/dbus/dbus-macros.h @@ -92,10 +92,16 @@ #define DBUS_ALLOC_SIZE2(x,y) #endif -#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -#define _DBUS_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +/* MSVC requires to specify this warning to the prototype and the implementation (xxx_IMPL) */ +#if defined(_MSC_VER) && (_MSC_VER >= 1700) +#define _DBUS_WARN_UNUSED_RESULT _Must_inspect_result_ +#define _DBUS_WARN_UNUSED_RESULT_IMPL _Must_inspect_result_ +#elif (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#define _DBUS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#define _DBUS_WARN_UNUSED_RESULT_IMPL #else -#define _DBUS_GNUC_WARN_UNUSED_RESULT +#define _DBUS_WARN_UNUSED_RESULT +#define _DBUS_WARN_UNUSED_RESULT_IMPL #endif /** @def _DBUS_GNUC_PRINTF diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 20bb894..8de805e 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -514,6 +514,7 @@ _dbus_string_parse_uint (const DBusString *str, * @param error location to store reason for failure * @returns #TRUE on success */ +_DBUS_WARN_UNUSED_RESULT_IMPL dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer, int n_bytes, diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index b3c73b6..a048a95 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -153,9 +153,11 @@ typedef struct { int fd; } DBusSocket; static inline int _dbus_socket_printable (DBusSocket s) { return s.fd; } +_DBUS_WARN_UNUSED_RESULT static inline dbus_bool_t _dbus_socket_is_valid (DBusSocket s) { return s.fd >= 0; } +_DBUS_WARN_UNUSED_RESULT static inline void _dbus_socket_invalidate (DBusSocket *s) { s->fd = -1; } @@ -462,7 +464,7 @@ const char* _dbus_get_tmpdir (void); /** * Random numbers */ -_DBUS_GNUC_WARN_UNUSED_RESULT +_DBUS_WARN_UNUSED_RESULT dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer, int n_bytes, DBusError *error); diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c index 12d4049..a14c7e2 100644 --- a/dbus/dbus-threads.c +++ b/dbus/dbus-threads.c @@ -333,6 +333,7 @@ init_global_locks (void) return FALSE; } +_DBUS_WARN_UNUSED_RESULT_IMPL dbus_bool_t _dbus_lock (DBusGlobalLock lock) { -- 1.9.5.msysgit.1