+if test "$GCC"
+then
+
+# Enable useful warnings
+# Some of them are commented out because the code needs cleanup first
+# Clang needs to be tested with -Werror=unknown-warning-option
+AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],
+[cflags_test="-Werror=unknown-warning-option"],
+[cflags_test=""])
+MY_APPEND_COMPILE_FLAGS([-Wall -Wextra dnl
+dnl -Wcast-align dnl
+dnl -Wconversion dnl
+-Wdeclaration-after-statement dnl
+dnl -Wformat-nonliteral dnl
+-Wformat-security dnl
+-Winit-self dnl
+-Wlogical-op dnl
+-Wmissing-prototypes dnl
+-Wnested-externs dnl
+-Wold-style-definition dnl
+-Wpacked dnl
+-Wpointer-arith dnl
+-Wredundant-decls dnl
+dnl -Wshadow dnl
+-Wstrict-prototypes dnl
+dnl too prone to false positives: -Wsuggest-attribute=format dnl
+dnl -Wswitch-default dnl
+-Wundef dnl
+-Wno-unused-parameter dnl
+], [], [$cflags_test])
+
+# No multiple definitions of uninitialized global variables
+MY_APPEND_COMPILE_FLAGS([-fno-common])
+
+# Reign in overzealous optimizers
+#
+# Contemporary compilers can squeeze out some extra performance by
+# assuming the program never executes code that has undefined behavior
+# according to the C standard. Unfortunately, this can break
+# programs. Pointing out that these programs are non-conforming is as
+# correct as it is unhelpful, at least as long as the compiler is
+# unable to diagnose the non-conformingness.
+#
+# Since keeping our programs working is a lot more important to us
+# than running them as fast as possible, forbid some assumptions that
+# are known to break real-world programs:
+#
+# * Aliasing: perfectly clean programs don't engage in type-punning,
+# and perfectly conforming programs do it only in full accordance
+# with the standard's (subtle!) aliasing rules. Neither kind of
+# perfection is realistic for us, therefore -fno-strict-aliasing.
+#
+# * Signed integer overflow: perfectly clean programs won't ever do
+# signed integer arithmetic that overflows. This is an imperfect
+# program, therefore -fno-strict-overflow.
+#
+MY_APPEND_COMPILE_FLAGS([dnl
+-fno-strict-aliasing dnl
+-fno-strict-overflow])
+
+# Emit extra code to check for buffer overflows
+# Could fall back to -fstack-protector when -fstack-protector-strong
+# isnt't supported, for users of older compilers. Doesn't seem worth
+# the trouble, though.
+# Some ports of the GNU toolchain reportedly support it in the
+# compiler, but not libc. Use a test program that makes the compiler
+# emit the extra stack checking code, and test it compiles and links.
+AX_APPEND_LINK_FLAGS([-fstack-protector-strong], [], [],
+ [AC_LANG_SOURCE([[
+int
+main(int argc, char *argv[])
+{
+ char arr[64], *dst = arr, *src = argv[0];
+ while ((*dst++ = *src++)) ;
+}
+ ]])])
+
+fi # $GCC