pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jelte Fennema-Nio <postgres@jeltef.nl>
To: Peter Smith <smithpb2250@gmail.com>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: tests: Add a test C++ extension module
Date: Wed, 21 Jan 2026 09:50:44 +0100
Message-ID: <DFU506DCCMQ6.SWR87ADZHSCT@jeltef.nl> (raw)
In-Reply-To: <CAHut+Psr0yk7nbtX63Mc5+C_dND1LV-SxO7uw=mWbvHxhKwUrQ@mail.gmail.com>
References: <E1viDt1-001d7E-2I@gemulon.postgresql.org>
	<CAHut+Psr0yk7nbtX63Mc5+C_dND1LV-SxO7uw=mWbvHxhKwUrQ@mail.gmail.com>

On Wed Jan 21, 2026 at 4:27 AM CET, Peter Smith wrote:
> 'make check-world' is suddenly failing for me, apparently caused by
> this new test.
>
> FYI - I am building in a 'Linux CentOS7-x64 ' environment, which I
> know has reached end-of-life, but even so, everything was fine before
> this test appeared.


I'm still not clear on what our policy is on supporting such EOL
distros. But this patch seems sensible regardless and it fixes
compilation for me when running on a centos 7 docker image.

Attachments:

v1-0001-Detect-if-flags-are-needed-for-C-11-support.patch (text/x-patch, 5.3K) download From 2af93c10fe716090f8d8ab1f884f11ee9b9a86cc Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <postgres@jeltef.nl> Date: Wed, 21 Jan 2026 09:18:53 +0100 Subject: [PATCH v1] Detect if flags are needed for C++11 support Just like we only support compiling with C11, we only support compiling extensions with C++11 and up. Some compilers support C++11 but don't enable it by default. This detects if flags are needed to enable C++11 support, in a similar way to how we check the same for C11 support. --- configure | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 28 +++++++++++++++++++++++++- meson.build | 28 ++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 04eeb1a741c..4c6f604c276 100755 --- a/configure +++ b/configure @@ -4770,7 +4770,61 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_ct_CXX"; then +# Detect option needed for C++11 +# PostgreSQL headers use C11 features (like alignas) which require C++11. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CXX option to accept ISO C++11" >&5 +$as_echo_n "checking for $CXX option to accept ISO C++11... " >&6; } + +if ${pgac_cv_prog_cxx_cxx11+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_cv_prog_cxx_cxx11=no +pgac_save_CXX=$CXX +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 + +for pgac_arg in '' '-std=gnu++11' '-std=c++11'; do + CXX="$pgac_save_CXX $pgac_arg" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + pgac_cv_prog_cxx_cxx11=$pgac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test x"$pgac_cv_prog_cxx_cxx11" != x"no" && break +done +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 + +CXX=$pgac_save_CXX +fi + + +if test x"$pgac_cv_prog_cxx_cxx11" = x"no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C++ compiler \"$CXX\" does not support C++11" >&5 +$as_echo "$as_me: WARNING: C++ compiler \"$CXX\" does not support C++11" >&2;} +elif test x"$pgac_cv_prog_cxx_cxx11" = x""; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_cxx_cxx11" >&5 +$as_echo "$pgac_cv_prog_cxx_cxx11" >&6; } + CXX="$CXX $pgac_cv_prog_cxx_cxx11" +fi + +if test -n "$ac_ct_CXX" -a x"$pgac_cv_prog_cxx_cxx11" != x"no"; then have_cxx=yes else have_cxx=no diff --git a/configure.ac b/configure.ac index 13c75170f7a..a329484e426 100644 --- a/configure.ac +++ b/configure.ac @@ -387,7 +387,33 @@ fi AC_PROG_CXX([$pgac_cxx_list]) -if test -n "$ac_ct_CXX"; then +# Detect option needed for C++11 +AC_MSG_CHECKING([for $CXX option to accept ISO C++11]) +AC_CACHE_VAL([pgac_cv_prog_cxx_cxx11], +[pgac_cv_prog_cxx_cxx11=no +pgac_save_CXX=$CXX +AC_LANG_PUSH([C++]) +for pgac_arg in '' '-std=gnu++11' '-std=c++11'; do + CXX="$pgac_save_CXX $pgac_arg" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif]])], [[pgac_cv_prog_cxx_cxx11=$pgac_arg]]) + test x"$pgac_cv_prog_cxx_cxx11" != x"no" && break +done +AC_LANG_POP([C++]) +CXX=$pgac_save_CXX]) + +if test x"$pgac_cv_prog_cxx_cxx11" = x"no"; then + AC_MSG_RESULT([unsupported]) + AC_MSG_WARN([C++ compiler "$CXX" does not support C++11]) +elif test x"$pgac_cv_prog_cxx_cxx11" = x""; then + AC_MSG_RESULT([none needed]) +else + AC_MSG_RESULT([$pgac_cv_prog_cxx_cxx11]) + CXX="$CXX $pgac_cv_prog_cxx_cxx11" +fi + +if test -n "$ac_ct_CXX" -a x"$pgac_cv_prog_cxx_cxx11" != x"no"; then have_cxx=yes else have_cxx=no diff --git a/meson.build b/meson.build index 6d304f32fb0..f88a23b9f3a 100644 --- a/meson.build +++ b/meson.build @@ -585,6 +585,34 @@ if not cc.compiles(c11_test, name: 'C11') endif endif +# Do we need an option to enable C++11? +if have_cxx + cxx11_test = ''' +#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif +''' + + if not cxx.compiles(cxx11_test, name: 'C++11') + have_cxx = false + if cxx.get_id() == 'msvc' + cxx11_test_args = ['/std:c++11'] + else + cxx11_test_args = ['-std=gnu++11', '-std=c++11'] + endif + foreach arg : cxx11_test_args + if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg]) + have_cxx = true + cxxflags += arg + break + endif + endforeach + if not have_cxx + warning('C++ compiler does not support C++11') + endif + endif +endif + postgres_inc = [include_directories(postgres_inc_d)] test_lib_d = postgres_lib_d base-commit: b4555cb070f134c04328df54ce31d4ef1970f3bb -- 2.52.0

view thread (10+ messages)  latest in thread

Message-ID: <DFU506DCCMQ6.SWR87ADZHSCT@jeltef.nl>
Permalink:  ../DFU506DCCMQ6.SWR87ADZHSCT@jeltef.nl/
Also on:    postgresql.org/message-id/DFU506DCCMQ6.SWR87ADZHSCT@jeltef.nl

 ·  · 

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: pgsql-committers@postgresql.org
  Cc: postgres@jeltef.nl, smithpb2250@gmail.com, peter@eisentraut.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: tests: Add a test C++ extension module
  In-Reply-To: <DFU506DCCMQ6.SWR87ADZHSCT@jeltef.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox