On 18.03.26 14:32, Peter Eisentraut wrote:
On 16.03.26 10:55, Peter Eisentraut wrote:
On 09.03.26 17:39, Bertrand Drouvot wrote:
0001: Prevent -Wstrict-prototypes and -Wold-style-definition warnings
It fixes the remaining warnings that those new flags would generate.
I have committed this one. I'll look at the rest next.
Also committed.
I have a couple of follow-up patches that I had developed while playing
with this.
There is a warning option for MSVC that appears to have a very similar
effect to the ones we added here, so I propose we add that one as well.
Additionally, there is an option for MSVC to disable warnings in system
headers, similar to the default behavior of GCC. This would be required
here because some system header files have non-strict prototypes.
Additionally, I propose to add -Wold-style-declaration, which is
completely unrelated to -Wold-style-definition, but it has popped up a
few times via the buildfarm (grep for it in git log), so I think we
might as well add it so that everyone sees it.
Finally, I think we can remove the option -Wendif-labels, which doesn't
do anything anymore that isn't the default. (It was only not the
default before gcc 4.0.)
From a0f3b0681a42d87ed4806936bd922d863066dadf Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Mon, 23 Mar 2026 16:04:02 +0100
Subject: [PATCH v2 1/4] Disable warnings in system headers in MSVC
This matches the standard behavior in GCC.
The required option is available since VS 2017.
Then, we can remove one workaround for avoiding a warning from a
system header.
---
meson.build | 4 ++++
src/backend/port/win32/crashdump.c | 14 --------------
2 files changed, 4 insertions(+), 14 deletions(-)
diff --git a/meson.build b/meson.build
index 0a181909fab..79cc7b4e758 100644
--- a/meson.build
+++ b/meson.build
@@ -2309,6 +2309,10 @@ if cc.get_id() == 'msvc'
'/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is
not handled [like -Wswitch]
'/w24102', # unreferenced label [like -Wunused-label]
'/w24777', # 'function' : format string 'string' requires an argument of
type 'type1', but variadic argument number has type 'type2' [like -Wformat]
+
+ # Disable warnings in system headers
+ '/external:anglebrackets',
+ '/external:W0',
]
cppflags += [
diff --git a/src/backend/port/win32/crashdump.c
b/src/backend/port/win32/crashdump.c
index 05790ba6ac1..0efeb9a9236 100644
--- a/src/backend/port/win32/crashdump.c
+++ b/src/backend/port/win32/crashdump.c
@@ -38,21 +38,7 @@
#include "postgres.h"
-/*
- * Some versions of the MS SDK contain "typedef enum { ... } ;" which the MS
- * compiler quite sanely complains about. Well done, Microsoft.
- * This pragma disables the warning just while we include the header.
- * The pragma is known to work with all (as at the time of writing) supported
- * versions of MSVC.
- */
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable : 4091)
-#endif
#include <dbghelp.h>
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
/*
* Much of the following code is based on CodeProject and MSDN examples,
base-commit: 085a531983e210318d9e7d7088482cf4090b1fa6
--
2.53.0
From 61761a488443420ace79442c77a8f159bb650d83 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Mon, 23 Mar 2026 16:04:02 +0100
Subject: [PATCH v2 2/4] Enable warning like -Wstrict-prototypes on MSVC as
well
---
meson.build | 1 +
1 file changed, 1 insertion(+)
diff --git a/meson.build b/meson.build
index 79cc7b4e758..cfd590117dc 100644
--- a/meson.build
+++ b/meson.build
@@ -2308,6 +2308,7 @@ if cc.get_id() == 'msvc'
# Additional warnings to enable:
'/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is
not handled [like -Wswitch]
'/w24102', # unreferenced label [like -Wunused-label]
+ '/w24255', # 'function' : no function prototype given: converting '()' to
'(void)' [like -Wstrict-prototypes]
'/w24777', # 'function' : format string 'string' requires an argument of
type 'type1', but variadic argument number has type 'type2' [like -Wformat]
# Disable warnings in system headers
--
2.53.0
From 560c28ad38386f8a9579e2a32ddb6a7b903d754b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Mon, 23 Mar 2026 16:04:02 +0100
Subject: [PATCH v2 3/4] Remove -Wendif-labels
This has been the default since gcc 4.0. (Introduced in 3.3, so it
was only available but turned off for a relatively short time.)
---
configure | 91 ----------------------------------------------------
configure.ac | 2 --
meson.build | 1 -
3 files changed, 94 deletions(-)
diff --git a/configure b/configure
index 0d3f634abec..8e0e7483c1d 100755
--- a/configure
+++ b/configure
@@ -5435,97 +5435,6 @@ fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports
-Wendif-labels, for CFLAGS" >&5
-$as_echo_n "checking whether ${CC} supports -Wendif-labels, for CFLAGS... "
>&6; }
-if ${pgac_cv_prog_CC_cflags__Wendif_labels+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CFLAGS=$CFLAGS
-pgac_save_CC=$CC
-CC=${CC}
-CFLAGS="${CFLAGS} -Wendif-labels"
-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__Wendif_labels=yes
-else
- pgac_cv_prog_CC_cflags__Wendif_labels=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__Wendif_labels" >&5
-$as_echo "$pgac_cv_prog_CC_cflags__Wendif_labels" >&6; }
-if test x"$pgac_cv_prog_CC_cflags__Wendif_labels" = x"yes"; then
- CFLAGS="${CFLAGS} -Wendif-labels"
-fi
-
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports
-Wendif-labels, for CXXFLAGS" >&5
-$as_echo_n "checking whether ${CXX} supports -Wendif-labels, for CXXFLAGS... "
>&6; }
-if ${pgac_cv_prog_CXX_cxxflags__Wendif_labels+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CXXFLAGS=$CXXFLAGS
-pgac_save_CXX=$CXX
-CXX=${CXX}
-CXXFLAGS="${CXXFLAGS} -Wendif-labels"
-ac_save_cxx_werror_flag=$ac_cxx_werror_flag
-ac_cxx_werror_flag=yes
-ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS
conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
- pgac_cv_prog_CXX_cxxflags__Wendif_labels=yes
-else
- pgac_cv_prog_CXX_cxxflags__Wendif_labels=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext
$LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_cxx_werror_flag=$ac_save_cxx_werror_flag
-CXXFLAGS="$pgac_save_CXXFLAGS"
-CXX="$pgac_save_CXX"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result:
$pgac_cv_prog_CXX_cxxflags__Wendif_labels" >&5
-$as_echo "$pgac_cv_prog_CXX_cxxflags__Wendif_labels" >&6; }
-if test x"$pgac_cv_prog_CXX_cxxflags__Wendif_labels" = x"yes"; then
- CXXFLAGS="${CXXFLAGS} -Wendif-labels"
-fi
-
-
-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports
-Wmissing-format-attribute, for CFLAGS" >&5
$as_echo_n "checking whether ${CC} supports -Wmissing-format-attribute, for
CFLAGS... " >&6; }
if ${pgac_cv_prog_CC_cflags__Wmissing_format_attribute+:} false; then :
diff --git a/configure.ac b/configure.ac
index f8327a7020a..2baac5e9da7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -553,8 +553,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
# On macOS, complain about usage of symbols newer than the deployment target
PGAC_PROG_CC_CFLAGS_OPT([-Werror=unguarded-availability-new])
PGAC_PROG_CXX_CFLAGS_OPT([-Werror=unguarded-availability-new])
- PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
- PGAC_PROG_CXX_CFLAGS_OPT([-Wendif-labels])
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-format-attribute])
diff --git a/meson.build b/meson.build
index cfd590117dc..ec9188af49e 100644
--- a/meson.build
+++ b/meson.build
@@ -2204,7 +2204,6 @@ common_warning_flags = [
'-Werror=vla',
# On macOS, complain about usage of symbols newer than the deployment target
'-Werror=unguarded-availability-new',
- '-Wendif-labels',
'-Wmissing-format-attribute',
'-Wcast-function-type',
'-Wshadow=compatible-local',
--
2.53.0
From 0ca80851beaf81a3f661b19f61df7fff81780ce7 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Mon, 23 Mar 2026 16:04:02 +0100
Subject: [PATCH v2 4/4] Add warning option -Wold-style-declaration
---
configure | 41 +++++++++++++++++++++++++++++++++++++++++
configure.ac | 2 ++
meson.build | 1 +
3 files changed, 44 insertions(+)
diff --git a/configure b/configure
index 8e0e7483c1d..d058605c7ad 100755
--- a/configure
+++ b/configure
@@ -5526,6 +5526,47 @@ fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports
-Wold-style-declaration, for CFLAGS" >&5
+$as_echo_n "checking whether ${CC} supports -Wold-style-declaration, for
CFLAGS... " >&6; }
+if ${pgac_cv_prog_CC_cflags__Wold_style_declaration+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ pgac_save_CFLAGS=$CFLAGS
+pgac_save_CC=$CC
+CC=${CC}
+CFLAGS="${CFLAGS} -Wold-style-declaration"
+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__Wold_style_declaration=yes
+else
+ pgac_cv_prog_CC_cflags__Wold_style_declaration=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__Wold_style_declaration" >&5
+$as_echo "$pgac_cv_prog_CC_cflags__Wold_style_declaration" >&6; }
+if test x"$pgac_cv_prog_CC_cflags__Wold_style_declaration" = x"yes"; then
+ CFLAGS="${CFLAGS} -Wold-style-declaration"
+fi
+
+
+ # -Wold-style-declaration is not applicable for C++
+
# To require fallthrough attribute annotations, use
# -Wimplicit-fallthrough=5 with gcc and -Wimplicit-fallthrough with
# clang. The latter is also accepted on gcc but does not enforce
diff --git a/configure.ac b/configure.ac
index 2baac5e9da7..c27afee1822 100644
--- a/configure.ac
+++ b/configure.ac
@@ -555,6 +555,8 @@ if test "$GCC" = yes -a "$ICC" = no; then
PGAC_PROG_CXX_CFLAGS_OPT([-Werror=unguarded-availability-new])
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-format-attribute])
+ PGAC_PROG_CC_CFLAGS_OPT([-Wold-style-declaration])
+ # -Wold-style-declaration is not applicable for C++
# To require fallthrough attribute annotations, use
# -Wimplicit-fallthrough=5 with gcc and -Wimplicit-fallthrough with
diff --git a/meson.build b/meson.build
index ec9188af49e..b4428760676 100644
--- a/meson.build
+++ b/meson.build
@@ -2199,6 +2199,7 @@ unroll_loops_cflags =
cc.get_supported_arguments(['-funroll-loops'])
common_warning_flags = [
'-Wmissing-prototypes',
+ '-Wold-style-declaration',
'-Wpointer-arith',
# Really don't want VLAs to be used in our dialect of C
'-Werror=vla',
--
2.53.0