]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Enable test_cplusplusext with MSVC
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 1 Apr 2026 05:48:47 +0000 (07:48 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 1 Apr 2026 05:48:47 +0000 (07:48 +0200)
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.

There is no equivalent change in configure, since this change mainly
targets MSVC.

Co-authored-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com

.cirrus.tasks.yml
meson.build
src/test/modules/test_cplusplusext/meson.build

index 0f32827952fcd48851e7410c79c352fdc946bfe2..a22cef063f337ababbaec245413d4d254a6bf4c4 100644 (file)
@@ -782,6 +782,7 @@ task:
     CIRRUS_WINDOWS_ERROR_MODE: 0x8001
 
     MESON_FEATURES:
+      -Dcpp_args=/std:c++20
       -Dauto_features=disabled
       -Dldap=enabled
       -Dssl=openssl
index c4b4cd4af066ec4af2d9dbef02f0fc66c6773973..8b134b28a6948605965442712875ff1c5610a8f0 100644 (file)
@@ -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
index d13210ca593bbb37a651b882a948ae053ae7365f..5860464a5032c258ce6e48a6382eff59aeecace5 100644 (file)
@@ -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