This patch adds code to "configure" to check if GCC supports the
following warning flags: -Wdeclaration-after-statement (GCC 3.4+),
-Wold-style-definition (GCC 3.4+), and -Wendif-labels (GCC 3.3+). Any of
these options that are supported by $CC are added to $CFLAGS. The patch
also removes -Wmissing-declarations from the default CFLAGS, on the
grounds that it is (I believe) redundant when -Wmissing-prototypes is
also specified.

(I didn't mention -Wendif-labels in my mail to -hackers, but it should
be pretty innocuous: "Warn whenever an #else or an #endif are followed
by text.")

This patch updates configure.in and configure (I re-ran autoconf 2.53).
It doesn't introduce any additional warning messages locally (Linux, GCC
3.4), but might do so on some platforms (the code in src/port/ is likely
to trigger some warnings, I think). Because of that, I think it is
probably best to save this for 8.1

-Neil

Index: configure
===================================================================
RCS file: /var/lib/cvs/pgsql/configure,v
retrieving revision 1.402
diff -c -r1.402 configure
*** configure	15 Oct 2004 05:10:53 -0000	1.402
--- configure	18 Oct 2004 03:56:37 -0000
***************
*** 2497,2502 ****
--- 2497,2676 ----
    CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
  fi
  
+ # Check if we're using a recent version of GCC; if so, enable some
+ # additional warning flags
+ echo "$as_me:$LINENO: checking if $CC supports -Wdeclaration-after-statement" >&5
+ echo $ECHO_N "checking if $CC supports -Wdeclaration-after-statement... $ECHO_C" >&6
+ if test "${pgac_cv_prog_cc_warn_decl_after_stmt+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_decl_after_stmt=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wdeclaration-after-statement"
+   cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+ 
+ #ifdef F77_DUMMY_MAIN
+ #  ifdef __cplusplus
+      extern "C"
+ #  endif
+    int F77_DUMMY_MAIN() { return 1; }
+ #endif
+ int
+ main ()
+ {
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+          { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   pgac_cv_prog_cc_warn_decl_after_stmt=yes
+ break
+ else
+   echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ fi
+ rm -f conftest.$ac_objext conftest.$ac_ext
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ 
+ fi
+ echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_warn_decl_after_stmt" >&5
+ echo "${ECHO_T}$pgac_cv_prog_cc_warn_decl_after_stmt" >&6
+ 
+ if test "$pgac_cv_prog_cc_warn_decl_after_stmt" = yes; then
+   CFLAGS="$CFLAGS -Wdeclaration-after-statement"
+ fi
+ echo "$as_me:$LINENO: checking if $CC supports -Wold-style-definition" >&5
+ echo $ECHO_N "checking if $CC supports -Wold-style-definition... $ECHO_C" >&6
+ if test "${pgac_cv_prog_cc_warn_old_style_definition+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_old_style_definition=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
+   cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+ 
+ #ifdef F77_DUMMY_MAIN
+ #  ifdef __cplusplus
+      extern "C"
+ #  endif
+    int F77_DUMMY_MAIN() { return 1; }
+ #endif
+ int
+ main ()
+ {
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+          { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   pgac_cv_prog_cc_warn_old_style_definition=yes
+ break
+ else
+   echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ fi
+ rm -f conftest.$ac_objext conftest.$ac_ext
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ 
+ fi
+ echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_warn_old_style_definition" >&5
+ echo "${ECHO_T}$pgac_cv_prog_cc_warn_old_style_definition" >&6
+ 
+ if test "$pgac_cv_prog_cc_warn_old_style_definition" = yes; then
+   CFLAGS="$CFLAGS -Wold-style-definition"
+ fi
+ echo "$as_me:$LINENO: checking if $CC supports -Wendif-labels" >&5
+ echo $ECHO_N "checking if $CC supports -Wendif-labels... $ECHO_C" >&6
+ if test "${pgac_cv_prog_cc_warn_endif_labels+set}" = set; then
+   echo $ECHO_N "(cached) $ECHO_C" >&6
+ else
+   pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_endif_labels=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wendif-labels"
+   cat >conftest.$ac_ext <<_ACEOF
+ #line $LINENO "configure"
+ #include "confdefs.h"
+ 
+ #ifdef F77_DUMMY_MAIN
+ #  ifdef __cplusplus
+      extern "C"
+ #  endif
+    int F77_DUMMY_MAIN() { return 1; }
+ #endif
+ int
+ main ()
+ {
+ 
+   ;
+   return 0;
+ }
+ _ACEOF
+ rm -f conftest.$ac_objext
+ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+   (eval $ac_compile) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); } &&
+          { ac_try='test -s conftest.$ac_objext'
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+   (eval $ac_try) 2>&5
+   ac_status=$?
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   (exit $ac_status); }; }; then
+   pgac_cv_prog_cc_warn_endif_labels=yes
+ break
+ else
+   echo "$as_me: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ fi
+ rm -f conftest.$ac_objext conftest.$ac_ext
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ 
+ fi
+ echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_warn_endif_labels" >&5
+ echo "${ECHO_T}$pgac_cv_prog_cc_warn_endif_labels" >&6
+ 
+ if test "$pgac_cv_prog_cc_warn_endif_labels" = yes; then
+   CFLAGS="$CFLAGS -Wendif-labels"
+ fi
+ 
  # supply -g if --enable-debug
  if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
    CFLAGS="$CFLAGS -g"
Index: configure.in
===================================================================
RCS file: /var/lib/cvs/pgsql/configure.in,v
retrieving revision 1.381
diff -c -r1.381 configure.in
*** configure.in	15 Oct 2004 05:10:59 -0000	1.381
--- configure.in	18 Oct 2004 03:55:25 -0000
***************
*** 253,258 ****
--- 253,264 ----
  # Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
  PGAC_PROG_CC_NO_STRICT_ALIASING
  
+ # Check if we're using a recent version of GCC; if so, enable some
+ # additional warning flags
+ PGAC_PROG_CC_WARN_DECL_AFTER_STMT
+ PGAC_PROG_CC_WARN_OLD_STYLE_DEFN
+ PGAC_PROG_CC_WARN_ENDIF_LABELS
+ 
  # supply -g if --enable-debug
  if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
    CFLAGS="$CFLAGS -g"
Index: config/c-compiler.m4
===================================================================
RCS file: /var/lib/cvs/pgsql/config/c-compiler.m4,v
retrieving revision 1.12
diff -c -r1.12 c-compiler.m4
*** config/c-compiler.m4	2 Feb 2004 04:07:18 -0000	1.12
--- config/c-compiler.m4	18 Oct 2004 03:37:10 -0000
***************
*** 150,155 ****
--- 150,228 ----
    CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
  fi])# PGAC_PROG_CC_NO_STRICT_ALIASING
  
+ # PGAC_PROG_CC_WARN_DECL_AFTER_STMT
+ # -------------------------------
+ # Recent versions of GCC allow statements and declarations to be
+ # intermixed by default (this is per C99 but violates both C89 and a
+ # long-standing convention in our source). Recent versions of GCC also
+ # support a -Wdeclaration-after-statement flag to warn when this
+ # feature is used.
+ AC_DEFUN([PGAC_PROG_CC_WARN_DECL_AFTER_STMT],
+ [AC_CACHE_CHECK([if $CC supports -Wdeclaration-after-statement],
+                 pgac_cv_prog_cc_warn_decl_after_stmt,
+ [pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_decl_after_stmt=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wdeclaration-after-statement"
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+                      [pgac_cv_prog_cc_warn_decl_after_stmt=yes
+ break])
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ ])
+ 
+ if test "$pgac_cv_prog_cc_warn_decl_after_stmt" = yes; then
+   CFLAGS="$CFLAGS -Wdeclaration-after-statement"
+ fi]) # PGAC_PROG_CC_WARN_DECL_AFTER_STMT
+ 
+ # PGAC_PROG_CC_WARN_OLD_STYLE_DEFN
+ # -------------------------------
+ # Recent versions of GCC support -Wold-style-definition; check for it
+ # and add it to CFLAGS if available
+ AC_DEFUN([PGAC_PROG_CC_WARN_OLD_STYLE_DEFN],
+ [AC_CACHE_CHECK([if $CC supports -Wold-style-definition],
+                 pgac_cv_prog_cc_warn_old_style_definition,
+ [pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_old_style_definition=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+                      [pgac_cv_prog_cc_warn_old_style_definition=yes
+ break])
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ ])
+ 
+ if test "$pgac_cv_prog_cc_warn_old_style_definition" = yes; then
+   CFLAGS="$CFLAGS -Wold-style-definition"
+ fi]) # PGAC_PROG_CC_WARN_OLD_STYLE_DEFN
+ 
+ 
+ # PGAC_PROG_CC_WARN_ENDIF_LABELS
+ # -------------------------------
+ # Recent versions of GCC support -Wendif-labels; check for it and add
+ # it to CFLAGS if available
+ 
+ AC_DEFUN([PGAC_PROG_CC_WARN_ENDIF_LABELS],
+ [AC_CACHE_CHECK([if $CC supports -Wendif-labels],
+                 pgac_cv_prog_cc_warn_endif_labels,
+ [pgac_save_CFLAGS=$CFLAGS
+ pgac_cv_prog_cc_warn_endif_labels=no
+ if test "$GCC" = yes; then
+   CFLAGS="$pgac_save_CFLAGS -Wendif-labels"
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+                      [pgac_cv_prog_cc_warn_endif_labels=yes
+ break])
+ fi
+ 
+ CFLAGS=$pgac_save_CFLAGS
+ ])
+ 
+ if test "$pgac_cv_prog_cc_warn_endif_labels" = yes; then
+   CFLAGS="$CFLAGS -Wendif-labels"
+ fi]) # PGAC_PROG_CC_WARN_ENDIF_LABELS
  
  # The below backpatches the following Autoconf change:
  #
Index: src/Makefile.global.in
===================================================================
RCS file: /var/lib/cvs/pgsql/src/Makefile.global.in,v
retrieving revision 1.203
diff -c -r1.203 Makefile.global.in
*** src/Makefile.global.in	15 Oct 2004 17:10:58 -0000	1.203
--- src/Makefile.global.in	18 Oct 2004 03:52:33 -0000
***************
*** 185,191 ****
  GCC = @GCC@
  CFLAGS = @CFLAGS@
  ifeq ($(GCC), yes)
!   CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
  endif
  
  # Kind-of compilers
--- 185,191 ----
  GCC = @GCC@
  CFLAGS = @CFLAGS@
  ifeq ($(GCC), yes)
!   CFLAGS += -Wall -Wmissing-prototypes
  endif
  
  # Kind-of compilers
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to