From b874048efcee4ea985cf9e5592d289ddef2df40a Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Fri, 22 Aug 2014 19:39:11 +0000 Subject: [PATCH] Handle gcc's overzealous unused-result warning Modern static analyzers warn when a variable is set but not used. GCC warns when the result of a function marked as `__attribute__((warn_unused_result))` is not set to some variable, even when the function is cast to `(void)`, which is the recognized way of indicating the intent to ignore the result. We treat all warnings as errors. The combination of behaviors here makes it difficult if we really don't care about the result of the function; the obvious workarounds are precluded. GCC's maintainers don't consider this to be a bug: Why do you think this is a bug? warn_unused_result is for cases where "not checking the result is either a security problem or always a bug". https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509#c1 GLIBC however marks functions like `read` and `write` with this attribute. While it certainly in most cases is correct to act on their return value, in some cases we really just don't care. So when we see that we're building with GCC, and that we're building with all warnings enabled, we'll just pass -Wno-unused-result to disable the warning. ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 ref: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 7baf54ecaf..58c8a3bf20 100644 --- a/configure.ac +++ b/configure.ac @@ -464,6 +464,7 @@ if test "${enable_debug}" = "yes"; then CFLAGS="$saved_CFLAGS" if test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then + APR_ADDTO(SWITCH_AM_CFLAGS, -Wno-unused-result) APR_ADDTO(SWITCH_AM_CFLAGS, -g -ggdb) export DEBUG_CFLAGS="-g -ggdb" fi