On 30.03.26 00:53, Jelte Fennema-Nio wrote:
On Fri, 27 Mar 2026 at 12:23, Peter Eisentraut <[email protected]>
wrote:
Here is another tidied up patch set for this. I didn't go quite as far
as enabling C++20 by default in meson.build, this would just take more
time to work out and test all the different combinations, but I added
the flag to the Cirrus CI task, since there we know what compiler we
have.
I think 0001 and 0002 are good.
0003 seems awkward though. Attached is an approach that I think is
better: It actually checks for the required featureset and adds the
necessary flags to the compiler.
Hmm, note that C++ is also used for LLVM/JIT, and by requiring this
additional feature set we are also imposing new requirements for those
users. This has not been fully explored, and I hesitate to add such a
new requirement at the last moment.
But how about this: We add the feature test that you propose and enable
the extension based on that. See attached patch. This reduces to
essentially a three-line patch, much simpler than all previous proposals.
From ec7e12b1c0e53a9a1a46d1f43479fdf71d4ba8eb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Tue, 31 Mar 2026 09:48:52 +0200
Subject: [PATCH] Enable test_cplusplusext with MSVC
The test_cplusplusext test module has so far been disabled on MSVC.
The only remaining problem now is that designated initializers, as
used in PG_MODULE_MAGIC, require C++20. (With GCC and Clang they work
in older C++ versions as well.)
This adds another test in the top-level meson.build to check that the
compiler supports C++20 designated initializers. This is not
required, we are just checking and recording the answer. If yes, we
can enable the test module.
Most current compilers likely won't be in C++20 mode by default. This
doesn't change that; we are not doing anything to try to switch the
compiler into that mode. This might be a separate project, but for
now we'll leave that for the user or the test scaffolding.
The VS task on Cirrus CI is changed to provide the required flag to
turn on C++20 mode.
Discussion:
https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com
---
.cirrus.tasks.yml | 1 +
meson.build | 14 ++++++++++++++
src/test/modules/test_cplusplusext/meson.build | 7 +------
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 0f32827952f..a22cef063f3 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -782,6 +782,7 @@ task:
CIRRUS_WINDOWS_ERROR_MODE: 0x8001
MESON_FEATURES:
+ -Dcpp_args=/std:c++20
-Dauto_features=disabled
-Dldap=enabled
-Dssl=openssl
diff --git a/meson.build b/meson.build
index c4b4cd4af06..8b134b28a69 100644
--- a/meson.build
+++ b/meson.build
@@ -2176,6 +2176,20 @@ choke me
endif
+# Check whether the C++ compiler supports designated initializers.
+# These are used by PG_MODULE_MAGIC, and we use the result of this
+# test to decide whether to enable the test_cplusplusext test module.
+# Designated initializers only got standardized in C++20. In GCC and
+# Clang they also work when using earlier C++ versions, but MSVC
+# really only supports them when its configured to be in C++20 mode or
+# higher.
+if have_cxx
+ have_cxx_desinit = cxx.compiles('struct S { int x; } s = { .x = 1 };', name:
'C++ designated initializers')
+else
+ have_cxx_desinit = false
+endif
+
+
###############################################################
# Compiler flags
diff --git a/src/test/modules/test_cplusplusext/meson.build
b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..5860464a503 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -1,11 +1,6 @@
# Copyright (c) 2025-2026, PostgreSQL Global Development Group
-if not have_cxx
- subdir_done()
-endif
-
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
+if not have_cxx or not have_cxx_desinit
subdir_done()
endif
--
2.53.0