public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bertrand Drouvot <[email protected]>
Subject: [PATCH v1] configure: Apply -Werror=vla to C++ as well as C
Date: Fri, 27 Mar 2026 12:39:33 +0000
The comment part of d9dd406fe281 mentioned that -Wvla is not applicable
for C++. That is not fully correct: it is true that VLAs are not part of the
C++ standard, and g++ with -pedantic will also warn about them as a non-standard
extension. However, -Wvla itself works fine in C++ and will catch VLA
usage just as in C.
Fix configure.ac to apply -Werror=vla to C++ as well. There is no need to
fix meson.build as it already includes it in common_warning_flags.
Author: Bertrand Drouvot <[email protected]>
Suggested-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/7bf60ab1-2b5d-4a77-93ce-815072a0a014%40eisentraut.org
---
configure | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--
configure.ac | 4 ++--
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index 8e0e7483c1d..e022617cbdc 100755
--- a/configure
+++ b/configure
@@ -5300,7 +5300,7 @@ fi
PERMIT_DECLARATION_AFTER_STATEMENT=-Wno-declaration-after-statement
fi
- # Really don't want VLAs to be used in our dialect of C
+ # Really don't want VLAs to be used
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Werror=vla, for CFLAGS" >&5
$as_echo_n "checking whether ${CC} supports -Werror=vla, for CFLAGS... " >&6; }
@@ -5341,7 +5341,57 @@ if test x"$pgac_cv_prog_CC_cflags__Werror_vla" = x"yes"; then
fi
- # -Wvla is not applicable for C++
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Werror=vla, for CXXFLAGS" >&5
+$as_echo_n "checking whether ${CXX} supports -Werror=vla, for CXXFLAGS... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__Werror_vla+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS} -Werror=vla"
+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__Werror_vla=yes
+else
+ pgac_cv_prog_CXX_cxxflags__Werror_vla=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__Werror_vla" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__Werror_vla" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__Werror_vla" = x"yes"; then
+ CXXFLAGS="${CXXFLAGS} -Werror=vla"
+fi
+
+
# On macOS, complain about usage of symbols newer than the deployment target
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Werror=unguarded-availability-new, for CFLAGS" >&5
diff --git a/configure.ac b/configure.ac
index 2baac5e9da7..4c12ecb1078 100644
--- a/configure.ac
+++ b/configure.ac
@@ -547,9 +547,9 @@ if test "$GCC" = yes -a "$ICC" = no; 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
+ # Really don't want VLAs to be used
PGAC_PROG_CC_CFLAGS_OPT([-Werror=vla])
- # -Wvla is not applicable for C++
+ PGAC_PROG_CXX_CFLAGS_OPT([-Werror=vla])
# 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])
--
2.34.1
--Tf7PCX808vMWq/ju--
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v1] configure: Apply -Werror=vla to C++ as well as C
In-Reply-To: <no-message-id-724835@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox