diff options
-rw-r--r-- | acinclude.m4 | 85 | ||||
-rw-r--r-- | configure.ac | 26 |
2 files changed, 99 insertions, 12 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index c81f2ebd9f..a17c7a1328 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1578,6 +1578,13 @@ fi # # $1 : cflags to test # $2 : if supplied, C for C-only flags, CXX for C++-only flags +# $3 : if supplied, a program to try to compile with the flag +# and, if the compile fails when -Werror is turned on, +# we don't add the flag - used for warning flags that +# issue incorrect or non-useful warnings with some +# compiler versions +# $4 : must be supplied if $3 is supplied - a message describing +# for what the test program is testing # # The macro first determines if the compiler supports GCC-style flags. # Then it attempts to compile with the defined cflags. The defined @@ -1630,16 +1637,47 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then [ AC_MSG_RESULT(yes) # - # Remove -Werror=unknown-warning-option, if we - # added it, by setting CFLAGS to the saved value - # plus just the new option. - # - CFLAGS="$CFLAGS_saved $GCC_OPTION" - if test "$2" != C ; then + # OK, do we have a test program? If so, check + # whether it fails with this option and -Werror, + # and, if so, don't include it. + # + if test "x$3" != "x" ; then + CFLAGS="$CFLAGS -Werror" + AC_MSG_CHECKING(whether $GCC_OPTION $4) + AC_COMPILE_IFELSE([ + AC_LANG_SOURCE($3)], + [ + AC_MSG_RESULT(no) + # + # Remove -Werror=unknown-warning-option, if we + # added it, and -Werror by setting CFLAGS to + # the saved value plus just the new option. + # + CFLAGS="$CFLAGS_saved $GCC_OPTION" + if test "$2" != C ; then + # + # Add it to the C++ flags as well. + # + CXXFLAGS="$CXXFLAGS $GCC_OPTION" + fi + ], + [ + AC_MSG_RESULT(yes) + CFLAGS="$CFLAGS_saved" + ]) + else # - # Add it to the C++ flags as well. + # Remove -Werror=unknown-warning-option, if we + # added it, and -Werror by setting CFLAGS to + # the saved value plus just the new option. # - CXXFLAGS="$CXXFLAGS $GCC_OPTION" + CFLAGS="$CFLAGS_saved $GCC_OPTION" + if test "$2" != C ; then + # + # Add it to the C++ flags as well. + # + CXXFLAGS="$CXXFLAGS $GCC_OPTION" + fi fi ], [ @@ -1662,6 +1700,37 @@ if test "x$ac_supports_gcc_flags" = "xyes" ; then ]])], [ AC_MSG_RESULT(yes) + # + # OK, do we have a test program? If so, check + # whether it fails with this option and -Werror, + # and, if so, don't include it. + # + if test "x$3" != "x" ; then + CXXFLAGS="$CXXFLAGS -Werror" + AC_MSG_CHECKING(whether $GCC_OPTION $4) + AC_COMPILE_IFELSE([ + AC_LANG_SOURCE($3)], + [ + AC_MSG_RESULT(no) + # + # Remove -Werror=unknown-warning-option, if we + # added it, and -Werror by setting CXXFLAGS to + # the saved value plus just the new option. + # + CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION" + ], + [ + AC_MSG_RESULT(yes) + CXXFLAGS="$CXXFLAGS_saved" + ]) + else + # + # Remove -Werror=unknown-warning-option, if we + # added it, and -Werror by setting CXXFLAGS to + # the saved value plus just the new option. + # + CXXFLAGS="$CXXFLAGS_saved $GCC_OPTION" + fi ], [ AC_MSG_RESULT(no) diff --git a/configure.ac b/configure.ac index 1f528d7fd4..508d295ebc 100644 --- a/configure.ac +++ b/configure.ac @@ -411,10 +411,6 @@ AC_ARG_ENABLE(extra-gcc-checks, AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wmissing-prototypes) AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wmissing-declarations) # - # epan/dissectors/packet-afs.c blocks this one for now. - # - AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wshadow) - # # More cleanup needed for this on LP64. # AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wshorten-64-to-32) @@ -430,6 +426,28 @@ AC_WIRESHARK_GCC_CFLAGS_CHECK(-Warray-bounds) AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wcast-align) AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wformat-security) AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wold-style-definition, C) +# +# XXX - OK for C++? +# +# Make sure -Wshadow doesn't complain about variables in function and +# function pointer declarations shadowing other variables; if not, don't +# turn it on, as some versions of GCC (including the one in at least +# some Xcode versions that came with Mac OS X 10.5) complain about +# that. +# +AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wshadow, C, + [ +extern int atoi(char *p); + +int +foo(char *p) +{ + int (*fptr)(char *p) = atoi; + + return fptr(p) * 2; +} + ], + [warns about variables in function declarations shadowing other variables]) AC_WIRESHARK_GCC_CFLAGS_CHECK(-Wno-error=unused-but-set-variable) ## for now # # Use the faster pre gcc 4.5 floating point precision if available; |