diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-12-09 02:52:33 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-12-09 02:52:33 +0000 |
commit | b961881fb35d6d678daeb82fdf51e625b90c206b (patch) | |
tree | 15ee61537fcbbb442c08a228cafd2fdc45871769 | |
parent | ea47ca37b1aca1b6da320597379178a21f8bc388 (diff) |
Add some additional arguments to AC_WIRESHARK_GCC_CFLAGS_CHECK() to make
it do an additional check, if it finds that a given compiler option is
supported by the compiler, to see whether it's supported but
undesirable. The arguments are a chunk of code to try to compile with
-Werror, and a string to be used in the "checking..." message printed
when trying to compile the cunk of code.
Try enabling -Wshadow again, but have it check whether
extern int atoi(char *p);
int
foo(char *p)
{
int (*fptr)(char *p) = atoi;
return fptr(p) * 2;
}
compiles with -Wshadow and -Werror, so that we don't use -Wshadow with
compilers that complain about that; some older versions of GCC complain
about that, and it's really not worth our effort to eliminate or rename
arguments in function prototypes to make -Wshadow work even with those
compilers.
svn path=/trunk/; revision=46475
-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; |