From 55967ace36311575febde467d8d1665e17422245 Mon Sep 17 00:00:00 2001
From: Jelte Fennema <github-tech@jeltef.nl>
Date: Mon, 7 Dec 2020 17:50:18 +0100
Subject: [PATCH 1/6] Allow declaration after statement

---
 configure                 | 48 ---------------------------------------
 configure.ac              |  8 -------
 contrib/pgcrypto/Makefile |  3 ---
 src/Makefile.global.in    |  1 -
 src/common/Makefile       |  7 ------
 5 files changed, 67 deletions(-)

diff --git a/configure b/configure
index 7542fe30a1..311dfd83bd 100755
--- a/configure
+++ b/configure
@@ -737,7 +737,6 @@ BITCODE_CXXFLAGS
 BITCODE_CFLAGS
 CFLAGS_VECTORIZE
 CFLAGS_UNROLL_LOOPS
-PERMIT_DECLARATION_AFTER_STATEMENT
 LLVM_BINPATH
 LLVM_CXXFLAGS
 LLVM_CFLAGS
@@ -5295,53 +5294,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
   CXXFLAGS="-Wall -Wpointer-arith"
   # These work in some but not all gcc versions
   save_CFLAGS=$CFLAGS
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wdeclaration-after-statement, for CFLAGS" >&5
-$as_echo_n "checking whether ${CC} supports -Wdeclaration-after-statement, for CFLAGS... " >&6; }
-if ${pgac_cv_prog_CC_cflags__Wdeclaration_after_statement+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  pgac_save_CFLAGS=$CFLAGS
-pgac_save_CC=$CC
-CC=${CC}
-CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
-ac_save_c_werror_flag=$ac_c_werror_flag
-ac_c_werror_flag=yes
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  pgac_cv_prog_CC_cflags__Wdeclaration_after_statement=yes
-else
-  pgac_cv_prog_CC_cflags__Wdeclaration_after_statement=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_c_werror_flag=$ac_save_c_werror_flag
-CFLAGS="$pgac_save_CFLAGS"
-CC="$pgac_save_CC"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" >&5
-$as_echo "$pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" >&6; }
-if test x"$pgac_cv_prog_CC_cflags__Wdeclaration_after_statement" = x"yes"; then
-  CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
-fi
-
-
-  # -Wdeclaration-after-statement isn't applicable for C++.  Specific C files
-  # disable it, so AC_SUBST the negative form.
-  PERMIT_DECLARATION_AFTER_STATEMENT=
-  if test x"$save_CFLAGS" != x"$CFLAGS"; then
-    PERMIT_DECLARATION_AFTER_STATEMENT=-Wno-declaration-after-statement
-  fi
-
   # Really don't want VLAs to be used in our dialect of C
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Werror=vla, for CFLAGS" >&5
diff --git a/configure.ac b/configure.ac
index ed3cdb9a8e..c7311298c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -484,14 +484,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
   CXXFLAGS="-Wall -Wpointer-arith"
   # These work in some but not all gcc versions
   save_CFLAGS=$CFLAGS
-  PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
-  # -Wdeclaration-after-statement isn't applicable for C++.  Specific C files
-  # disable it, so AC_SUBST the negative form.
-  PERMIT_DECLARATION_AFTER_STATEMENT=
-  if test x"$save_CFLAGS" != x"$CFLAGS"; then
-    PERMIT_DECLARATION_AFTER_STATEMENT=-Wno-declaration-after-statement
-  fi
-  AC_SUBST(PERMIT_DECLARATION_AFTER_STATEMENT)
   # Really don't want VLAs to be used in our dialect of C
   PGAC_PROG_CC_CFLAGS_OPT([-Werror=vla])
   # On macOS, complain about usage of symbols newer than the deployment target
diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile
index c0b4f1fcf6..4e08493b68 100644
--- a/contrib/pgcrypto/Makefile
+++ b/contrib/pgcrypto/Makefile
@@ -78,9 +78,6 @@ SHLIB_LINK += $(filter -leay32, $(LIBS))
 SHLIB_LINK += -lws2_32
 endif
 
-# Upstream uses a larger subset of C99.
-imath.o: CFLAGS+=$(PERMIT_DECLARATION_AFTER_STATEMENT)
-
 rijndael.o: rijndael.tbl
 
 rijndael.tbl:
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 6e2f224cc4..16125a4255 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -263,7 +263,6 @@ CFLAGS_UNROLL_LOOPS = @CFLAGS_UNROLL_LOOPS@
 CFLAGS_VECTORIZE = @CFLAGS_VECTORIZE@
 CFLAGS_SSE42 = @CFLAGS_SSE42@
 CFLAGS_ARMV8_CRC32C = @CFLAGS_ARMV8_CRC32C@
-PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
 CXXFLAGS = @CXXFLAGS@
 
 LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
diff --git a/src/common/Makefile b/src/common/Makefile
index 880722fcf5..ac868254b6 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -178,13 +178,6 @@ kwlist_d.h: $(top_srcdir)/src/include/parser/kwlist.h $(GEN_KEYWORDLIST_DEPS)
 # that you don't get broken parsing code, even in a non-enable-depend build.
 keywords.o keywords_shlib.o keywords_srv.o: kwlist_d.h
 
-# The code imported from Ryu gets a pass on declaration-after-statement,
-# in order to keep it more closely aligned with its upstream.
-RYU_FILES = d2s.o f2s.o
-RYU_OBJS = $(RYU_FILES) $(RYU_FILES:%.o=%_shlib.o) $(RYU_FILES:%.o=%_srv.o)
-
-$(RYU_OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
-
 # kwlist_d.h is in the distribution tarball, so it is not cleaned here.
 clean distclean:
 	rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
-- 
2.17.1

