Only enable warn-unused-result for recent gcc

The attribute was introduced with gcc-3.4, but the ability to suppress
warnings from misapplied attributes (-Wno-attributes) was only introduced
later. Without the supression, gcc will emit tens of warnings for each
compilation completely drowning the real errors that the programmer
must see.
This commit is contained in:
Chris Wilson 2007-04-10 23:09:13 +01:00 committed by Carl Worth
parent f53c2b418c
commit 54134dd901
3 changed files with 30 additions and 12 deletions

View file

@ -654,10 +654,24 @@ AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
cairo_cv_warn_maybe=$MAYBE_WARN
AC_MSG_CHECKING([which warning flags were supported])])
WARN_CFLAGS=$cairo_cv_warn_cflags
WARN_CFLAGS="$cairo_cv_warn_cflags"
CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
PIXMAN_CFLAGS="$PIXMAN_CFLAGS $WARN_CFLAGS"
# We only wish to enable attribute(warn_unused_result) if we can prevent
# gcc from generating thousands of warnings about the misapplication of the
# attribute to void functions and variables.
AC_MSG_CHECKING([how to enable unused result warnings])
warn_unused_result=""
if echo $WARN_CFLAGS | grep -e '-Wno-attributes' >/dev/null; then
AC_TRY_COMPILE([__attribute__((__warn_unused_result__))
int f (int i) { return i; }], [],
[warn_unused_result="__attribute__((__warn_unused_result__))"])
fi
AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$warn_unused_result],
[Define to the value your compiler uses to support the warn-unused-result attribute])
AC_MSG_RESULT([$warn_unused_result])
CAIRO_CC_TRY_FLAG([-fno-strict-aliasing],
[CAIRO_CFLAGS="$CAIRO_CFLAGS -fno-strict-aliasing"
PIXMAN_CFLAGS="$PIXMAN_CFLAGS -fno-strict-aliasing"])
@ -845,7 +859,8 @@ AC_CONFIG_COMMANDS([src/cairo-features.h],
# define CAIRO_END_DECLS
#endif
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
/* only enable warnings if they can be suppressed (-Wno-attributes) */
#define CAIRO_WARN_UNUSED_RESULT \
__attribute__((__warn_unused_result__))
#else

View file

@ -100,13 +100,17 @@ SOFTWARE.
#include "pixman-remap.h"
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun__)
#define pixman_private __attribute__((__visibility__("hidden"),__warn_unused_result__))
#define pixman_private_no_warn __attribute__((__visibility__("hidden")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
#define pixman_private __hidden
#define pixman_private_no_warn __hidden
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
#define pixman_private
#define pixman_private_no_warn
#endif
/* Add attribute(warn_unused_result) if supported */
#define pixman_warn WARN_UNUSED_RESULT
#define pixman_private pixman_private_no_warn pixman_warn
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

View file

@ -103,17 +103,16 @@ CAIRO_BEGIN_DECLS
/* slim_internal.h */
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
#define cairo_private __attribute__((__visibility__("hidden"),__warn_unused_result__))
#define cairo_private_no_warn __attribute__((__visibility__("hidden")))
#define cairo_private_no_warn __attribute__((__visibility__("hidden")))
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
#define cairo_private __hidden CAIRO_WARN_UNUSED_RESULT
#define cairo_private_no_warn __hidden
#define cairo_private_no_warn __hidden
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
#define cairo_private CAIRO_WARN_UNUSED_RESULT
#define cairo_private_no_warn
#define cairo_private_no_warn
#endif
#define cairo_warn CAIRO_WARN_UNUSED_RESULT
/* Add attribute(warn_unused_result) if supported */
#define cairo_warn WARN_UNUSED_RESULT
#define cairo_private cairo_private_no_warn cairo_warn
/* This macro allow us to deprecate a function by providing an alias
for the old function name to the new function name. With this