Commit 37b6e180 authored by Daniel Wendt's avatar Daniel Wendt Committed by Simon McVittie

Enable "unused result" warning for Visual Studio >= 2012 (MSVC 11.0)

The _Must_inspect_result_ annotation is documented to be used in both
the declaration and implementation, but in testing with the MSVC 2012
compiler it appears to be sufficient to use the annotation only in the
declaration to get a compiler warning, as with the GCC compiler.
So the annotation is not necessary in the C implementation.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105460
[smcv: Rebase dbus-sysdeps.h changes on master]
[smcv: Clarify commit message]
Reviewed-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
Tested-by: default avatarDaniel Wendt <daniel.wendt@linux.com>
parent 29afefef
...@@ -165,6 +165,10 @@ x11 only: ...@@ -165,6 +165,10 @@ x11 only:
// Build with X11 auto launch support // Build with X11 auto launch support
DBUS_BUILD_X11:BOOL=ON DBUS_BUILD_X11:BOOL=ON
MSVC only (Visual Studio >= 2012):
// Enable code analyzing for MSVC compiler: /analyze
DBUS_MSVC_ANALYZE:BOOL=OFF
Note: The above mentioned options could be extracted after Note: The above mentioned options could be extracted after
configuring from the output of running "<maketool> help-options" configuring from the output of running "<maketool> help-options"
......
...@@ -170,6 +170,7 @@ if(MSVC) ...@@ -170,6 +170,7 @@ if(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /FIconfig.h") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /FIconfig.h")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /FIconfig.h") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /FIconfig.h")
option (DBUS_MSVC_ANALYZE "Enable code analyzing for MSVC compiler: /analyze" OFF)
endif() endif()
# #
...@@ -212,6 +213,9 @@ if(MSVC) ...@@ -212,6 +213,9 @@ if(MSVC)
# 4114 same type qualifier used more than once # 4114 same type qualifier used more than once
# 4133 'type' : incompatible types - from 'type1' to 'type2' # 4133 'type' : incompatible types - from 'type1' to 'type2'
set(WARNINGS_ERRORS "4002 4003 4013 4028 4031 4047 4114 4133") set(WARNINGS_ERRORS "4002 4003 4013 4028 4031 4047 4114 4133")
if(DBUS_MSVC_ANALYZE AND MSVC_VERSION GREATER 1600)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /analyze")
endif()
else() else()
set(WARNINGS "sign-compare") set(WARNINGS "sign-compare")
set(WARNINGS_DISABLED "") set(WARNINGS_DISABLED "")
...@@ -588,6 +592,9 @@ message(" Docbook Generator: ${DOCBOOK_GENERATOR_NAME} " ...@@ -588,6 +592,9 @@ message(" Docbook Generator: ${DOCBOOK_GENERATOR_NAME} "
message(" gcc coverage profiling: ${DBUS_GCOV_ENABLED} ") message(" gcc coverage profiling: ${DBUS_GCOV_ENABLED} ")
if(MSVC)
message(" MSVC code analyze mode: ${DBUS_MSVC_ANALYZE} ")
endif()
message(" Building unit tests: ${DBUS_BUILD_TESTS} ") message(" Building unit tests: ${DBUS_BUILD_TESTS} ")
message(" Building with GLib: ${DBUS_WITH_GLIB} ") message(" Building with GLib: ${DBUS_WITH_GLIB} ")
message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ") message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ")
......
...@@ -366,7 +366,8 @@ typedef enum ...@@ -366,7 +366,8 @@ typedef enum
_DBUS_N_GLOBAL_LOCKS _DBUS_N_GLOBAL_LOCKS
} DBusGlobalLock; } 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); void _dbus_unlock (DBusGlobalLock lock);
#define _DBUS_LOCK_NAME(name) _DBUS_LOCK_##name #define _DBUS_LOCK_NAME(name) _DBUS_LOCK_##name
...@@ -399,7 +400,7 @@ union DBusGUID ...@@ -399,7 +400,7 @@ union DBusGUID
char as_bytes[DBUS_UUID_LENGTH_BYTES]; /**< guid as 16 single-byte values */ 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, dbus_bool_t _dbus_generate_uuid (DBusGUID *uuid,
DBusError *error); DBusError *error);
DBUS_PRIVATE_EXPORT DBUS_PRIVATE_EXPORT
......
...@@ -92,10 +92,24 @@ ...@@ -92,10 +92,24 @@
#define DBUS_ALLOC_SIZE2(x,y) #define DBUS_ALLOC_SIZE2(x,y)
#endif #endif
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) /** @def _DBUS_WARN_UNUSED_RESULT
#define _DBUS_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) *
* An attribute for functions whose result must be checked by the caller.
*
* This macro is used in function declarations. Unlike gcc-specific
* attributes, to avoid compilation failure with MSVC it must appear
* somewhere before the function name in the declaration. Our preferred
* coding style is to place it before the return type, for example:
*
* DBUS_PRIVATE_EXPORT _DBUS_WARN_UNUSED_RESULT
* dbus_bool_t _dbus_user_database_lock_system (void);
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1700)
#define _DBUS_WARN_UNUSED_RESULT _Must_inspect_result_
#elif (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define _DBUS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else #else
#define _DBUS_GNUC_WARN_UNUSED_RESULT #define _DBUS_WARN_UNUSED_RESULT
#endif #endif
/** @def _DBUS_GNUC_PRINTF /** @def _DBUS_GNUC_PRINTF
...@@ -104,9 +118,6 @@ ...@@ -104,9 +118,6 @@
/** @def _DBUS_GNUC_NORETURN /** @def _DBUS_GNUC_NORETURN
* used to tell gcc about functions that never return, such as _dbus_abort() * used to tell gcc about functions that never return, such as _dbus_abort()
*/ */
/** @def _DBUS_GNUC_WARN_UNUSED_RESULT
* used to tell gcc about functions whose result must be used
*/
/* Normally docs are in .c files, but there isn't a .c file for this. */ /* Normally docs are in .c files, but there isn't a .c file for this. */
/** /**
......
...@@ -132,18 +132,18 @@ typedef struct { SOCKET sock; } DBusSocket; ...@@ -132,18 +132,18 @@ typedef struct { SOCKET sock; } DBusSocket;
# define DBUS_SOCKET_FORMAT "Iu" # define DBUS_SOCKET_FORMAT "Iu"
# define DBUS_SOCKET_INIT { INVALID_SOCKET } # define DBUS_SOCKET_INIT { INVALID_SOCKET }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline SOCKET static inline SOCKET
_dbus_socket_printable (DBusSocket s) { return s.sock; } _dbus_socket_printable (DBusSocket s) { return s.sock; }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline dbus_bool_t static inline dbus_bool_t
_dbus_socket_is_valid (DBusSocket s) { return s.sock != INVALID_SOCKET; } _dbus_socket_is_valid (DBusSocket s) { return s.sock != INVALID_SOCKET; }
static inline void static inline void
_dbus_socket_invalidate (DBusSocket *s) { s->sock = INVALID_SOCKET; } _dbus_socket_invalidate (DBusSocket *s) { s->sock = INVALID_SOCKET; }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline int static inline int
_dbus_socket_get_int (DBusSocket s) { return (int)s.sock; } _dbus_socket_get_int (DBusSocket s) { return (int)s.sock; }
...@@ -153,24 +153,24 @@ typedef struct { int fd; } DBusSocket; ...@@ -153,24 +153,24 @@ typedef struct { int fd; } DBusSocket;
# define DBUS_SOCKET_FORMAT "d" # define DBUS_SOCKET_FORMAT "d"
# define DBUS_SOCKET_INIT { -1 } # define DBUS_SOCKET_INIT { -1 }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline int static inline int
_dbus_socket_printable (DBusSocket s) { return s.fd; } _dbus_socket_printable (DBusSocket s) { return s.fd; }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline dbus_bool_t static inline dbus_bool_t
_dbus_socket_is_valid (DBusSocket s) { return s.fd >= 0; } _dbus_socket_is_valid (DBusSocket s) { return s.fd >= 0; }
static inline void static inline void
_dbus_socket_invalidate (DBusSocket *s) { s->fd = -1; } _dbus_socket_invalidate (DBusSocket *s) { s->fd = -1; }
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline int static inline int
_dbus_socket_get_int (DBusSocket s) { return s.fd; } _dbus_socket_get_int (DBusSocket s) { return s.fd; }
#endif /* not DBUS_WIN */ #endif /* not DBUS_WIN */
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
static inline DBusSocket static inline DBusSocket
_dbus_socket_get_invalid (void) _dbus_socket_get_invalid (void)
{ {
...@@ -469,7 +469,7 @@ const char* _dbus_get_tmpdir (void); ...@@ -469,7 +469,7 @@ const char* _dbus_get_tmpdir (void);
/** /**
* Random numbers * Random numbers
*/ */
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer, dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer,
int n_bytes, int n_bytes,
DBusError *error); DBusError *error);
......
...@@ -93,8 +93,8 @@ void _dbus_group_info_free_allocated (DBusGroupInfo *info); ...@@ -93,8 +93,8 @@ void _dbus_group_info_free_allocated (DBusGroupInfo *info);
DBUS_PRIVATE_EXPORT DBUS_PRIVATE_EXPORT
DBusUserDatabase* _dbus_user_database_get_system (void); DBusUserDatabase* _dbus_user_database_get_system (void);
DBUS_PRIVATE_EXPORT DBUS_PRIVATE_EXPORT _DBUS_WARN_UNUSED_RESULT
dbus_bool_t _dbus_user_database_lock_system (void) _DBUS_GNUC_WARN_UNUSED_RESULT; dbus_bool_t _dbus_user_database_lock_system (void);
DBUS_PRIVATE_EXPORT DBUS_PRIVATE_EXPORT
void _dbus_user_database_unlock_system (void); void _dbus_user_database_unlock_system (void);
void _dbus_user_database_flush_system (void); void _dbus_user_database_flush_system (void);
......
...@@ -10,16 +10,16 @@ ...@@ -10,16 +10,16 @@
#include <dbus/dbus-internals.h> #include <dbus/dbus-internals.h>
typedef DBusLoop TestMainContext; typedef DBusLoop TestMainContext;
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
TestMainContext *test_main_context_get (void); TestMainContext *test_main_context_get (void);
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
TestMainContext *test_main_context_try_get (void); TestMainContext *test_main_context_try_get (void);
TestMainContext *test_main_context_ref (TestMainContext *ctx); TestMainContext *test_main_context_ref (TestMainContext *ctx);
void test_main_context_unref (TestMainContext *ctx); void test_main_context_unref (TestMainContext *ctx);
void test_main_context_iterate (TestMainContext *ctx, void test_main_context_iterate (TestMainContext *ctx,
dbus_bool_t may_block); dbus_bool_t may_block);
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
dbus_bool_t test_connection_try_setup (TestMainContext *ctx, dbus_bool_t test_connection_try_setup (TestMainContext *ctx,
DBusConnection *connection); DBusConnection *connection);
void test_connection_setup (TestMainContext *ctx, void test_connection_setup (TestMainContext *ctx,
...@@ -27,7 +27,7 @@ void test_connection_setup (TestMainContext *ctx, ...@@ -27,7 +27,7 @@ void test_connection_setup (TestMainContext *ctx,
void test_connection_shutdown (TestMainContext *ctx, void test_connection_shutdown (TestMainContext *ctx,
DBusConnection *connection); DBusConnection *connection);
_DBUS_GNUC_WARN_UNUSED_RESULT _DBUS_WARN_UNUSED_RESULT
dbus_bool_t test_server_try_setup (TestMainContext *ctx, dbus_bool_t test_server_try_setup (TestMainContext *ctx,
DBusServer *server); DBusServer *server);
void test_server_setup (TestMainContext *ctx, void test_server_setup (TestMainContext *ctx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment