diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 2acd3cd04afa2a6d91d8177b2e2aa20c84cbdee7..98081bee25803ab7c6116184bc9c32d40403a6fc 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -1,5 +1,5 @@
 # Macros to detect C compiler features
-# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.12 2004/02/02 04:07:18 tgl Exp $
+# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.13 2004/10/20 02:12:07 neilc Exp $
 
 
 # PGAC_C_SIGNED
@@ -121,35 +121,19 @@ AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
 fi
 fi])# PGAC_C_FUNCNAME_SUPPORT
 
-
-# PGAC_PROG_CC_NO_STRICT_ALIASING
-# -------------------------------
-# Find out how to turn off strict aliasing in the C compiler.
-AC_DEFUN([PGAC_PROG_CC_NO_STRICT_ALIASING],
-[AC_CACHE_CHECK([how to turn off strict aliasing in $CC],
-                pgac_cv_prog_cc_no_strict_aliasing,
-[pgac_save_CFLAGS=$CFLAGS
-if test "$GCC" = yes; then
-  pgac_try="-fno-strict-aliasing"
-else
-  # Maybe fill in later...
-  pgac_try=
-fi
-
-for pgac_flag in $pgac_try; do
-  CFLAGS="$pgac_save_CFLAGS $pgac_flag"
-  _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
-                     [pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
-break])
-done
-
-CFLAGS=$pgac_save_CFLAGS
-])
-
-if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
-  CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
-fi])# PGAC_PROG_CC_NO_STRICT_ALIASING
-
+# PGAC_PROG_CC_CFLAGS_OPT
+# -----------------------
+# Given a string, check if the compiler supports the string as a
+# command-line option. If it does, add the string to CFLAGS.
+AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
+[AC_MSG_CHECKING([if $CC supports $1])
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS $1"
+_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+                   AC_MSG_RESULT(yes),
+                   [CFLAGS="$pgac_save_CFLAGS"
+                    AC_MSG_RESULT(no)])
+])# PGAC_PROG_CC_CFLAGS_OPT
 
 # The below backpatches the following Autoconf change:
 #
diff --git a/configure b/configure
index 7ae60e8d3961983939f4d030f1ee41e942898f7e..5eaa809ae88d01a8115897f5ace7b59a8c06b733 100755
--- a/configure
+++ b/configure
@@ -2432,23 +2432,61 @@ else
   fi
 fi
 
-# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
-echo "$as_me:$LINENO: checking how to turn off strict aliasing in $CC" >&5
-echo $ECHO_N "checking how to turn off strict aliasing in $CC... $ECHO_C" >&6
-if test "${pgac_cv_prog_cc_no_strict_aliasing+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  pgac_save_CFLAGS=$CFLAGS
 if test "$GCC" = yes; then
-  pgac_try="-fno-strict-aliasing"
+  CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
+
+  # Some versions of GCC support some additional useful warning flags.
+  # Check whether they are supported, and add them to CFLAGS if so.
+  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
+pgac_save_CFLAGS=$CFLAGS
+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
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
 else
-  # Maybe fill in later...
-  pgac_try=
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+                    echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
 fi
+rm -f conftest.$ac_objext conftest.$ac_ext
 
-for pgac_flag in $pgac_try; do
-  CFLAGS="$pgac_save_CFLAGS $pgac_flag"
-  cat >conftest.$ac_ext <<_ACEOF
+  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
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -Wold-style-definition"
+cat >conftest.$ac_ext <<_ACEOF
 #line $LINENO "configure"
 #include "confdefs.h"
 
@@ -2478,23 +2516,109 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
-break
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
 else
   echo "$as_me: failed program was:" >&5
 cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+                    echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
-done
 
-CFLAGS=$pgac_save_CFLAGS
+  echo "$as_me:$LINENO: checking if $CC supports -Wendif-labels" >&5
+echo $ECHO_N "checking if $CC supports -Wendif-labels... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+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
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+                    echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+
+  # Disable strict-aliasing rules; needed for gcc 3.3+
+  echo "$as_me:$LINENO: checking if $CC supports -fno-strict-aliasing" >&5
+echo $ECHO_N "checking if $CC supports -fno-strict-aliasing... $ECHO_C" >&6
+pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS -fno-strict-aliasing"
+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
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+CFLAGS="$pgac_save_CFLAGS"
+                    echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
 fi
-echo "$as_me:$LINENO: result: $pgac_cv_prog_cc_no_strict_aliasing" >&5
-echo "${ECHO_T}$pgac_cv_prog_cc_no_strict_aliasing" >&6
+rm -f conftest.$ac_objext conftest.$ac_ext
 
-if test x"$pgac_cv_prog_cc_no_strict_aliasing" != x""; then
-  CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
 fi
 
 # supply -g if --enable-debug
diff --git a/configure.in b/configure.in
index b023cf9c038e1393c4c6923d25eef24cf6f737a7..9348a4e9afd5b8fc332616f84788de3cc3f4becf 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $PostgreSQL: pgsql/configure.in,v 1.381 2004/10/15 05:10:59 momjian Exp $
+dnl $PostgreSQL: pgsql/configure.in,v 1.382 2004/10/20 02:12:06 neilc Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -250,8 +250,18 @@ else
   fi
 fi
 
-# Need to specify -fno-strict-aliasing too in case it's gcc 3.3 or later.
-PGAC_PROG_CC_NO_STRICT_ALIASING
+if test "$GCC" = yes; then
+  CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wpointer-arith"
+
+  # Some versions of GCC support some additional useful warning flags.
+  # Check whether they are supported, and add them to CFLAGS if so.
+  PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
+  PGAC_PROG_CC_CFLAGS_OPT([-Wold-style-definition])
+  PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
+
+  # Disable strict-aliasing rules; needed for gcc 3.3+
+  PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
+fi
 
 # supply -g if --enable-debug
 if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 467575bdaba35fafe11b426f93c7652d488b873f..02c32de3a0f1fa2f1dad6a941333eabaf91c5319 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.203 2004/10/15 17:10:58 momjian Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.204 2004/10/20 02:12:07 neilc Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -184,9 +184,6 @@ endif # not PGXS
 CC = @CC@
 GCC = @GCC@
 CFLAGS = @CFLAGS@
-ifeq ($(GCC), yes)
-  CFLAGS += -Wall -Wmissing-prototypes -Wmissing-declarations
-endif
 
 # Kind-of compilers