From: Peter Eisentraut Date: Wed, 1 Apr 2026 05:48:47 +0000 (+0200) Subject: Enable test_cplusplusext with MSVC X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c05ad248f99c729b53f6fa83939266b509682c33;p=thirdparty%2Fpostgresql.git 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. There is no equivalent change in configure, since this change mainly targets MSVC. Co-authored-by: Jelte Fennema-Nio Discussion: https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com --- 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