v11-0003-Enable-test_cplusplusext-with-MSVC.patch

text/plain

Filename: v11-0003-Enable-test_cplusplusext-with-MSVC.patch
Type: text/plain
Part: 2
Message: Re: Make copyObject work in C++

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v11-0003
Subject: Enable test_cplusplusext with MSVC
File+
.cirrus.tasks.yml 1 0
meson.build 22 13
src/test/modules/test_cplusplusext/meson.build 4 2
From ca2797018cca5b705d55456dcaca6d18db4816e4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 27 Mar 2026 11:49:33 +0100
Subject: [PATCH v11 3/3] 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 is in C++20 mode.  This is not required, we are just checking
and recording the answer.  If yes and we are using MSVC, we can enable
the test module.  (With other compilers it's already always enabled
and stays that way.)

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.
---
 .cirrus.tasks.yml                             |  1 +
 meson.build                                   | 35 ++++++++++++-------
 .../modules/test_cplusplusext/meson.build     |  6 ++--
 3 files changed, 27 insertions(+), 15 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 64a5bb888d6..d9dffa19141 100644
--- a/meson.build
+++ b/meson.build
@@ -654,23 +654,32 @@ cxx11_test = '''
 #endif
 '''
 
-if have_cxx and not cxx.compiles(cxx11_test, name: 'C++11')
-  cxx11_ok = false
-  if cxx.get_id() == 'msvc'
-    cxx11_test_args = ['/std:c++14']  # oldest version supported
-  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])
-      cxx11_ok = true
-      cxxflags += arg
-      break
+cxx20_test = '''
+#if !defined __cplusplus || __cplusplus < 202002L
+# error "Compiler does not advertise C++20 conformance"
+#endif
+'''
+
+if have_cxx
+  cxx11_ok = cxx.compiles(cxx11_test, name: 'C++11')
+  if not cxx11_ok
+    if cxx.get_id() == 'msvc'
+      cxx11_test_args = ['/std:c++14']  # oldest version supported
+    else
+      cxx11_test_args = ['-std=gnu++11', '-std=c++11']
     endif
-  endforeach
+    foreach arg : cxx11_test_args
+      if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg])
+        cxx11_ok = true
+        cxxflags += arg
+        break
+      endif
+    endforeach
+  endif
   if not cxx11_ok
     error('C++ compiler does not support C++11')
   endif
+  cxx20_ok = cxx.compiles(cxx20_test, name: 'C++20')
 endif
 
 
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..a9b294d6b1c 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,8 +4,10 @@ if not have_cxx
   subdir_done()
 endif
 
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
+# Test extension requires C++20 support (for designated initializers
+# in PG_MODULE_MAGIC).  Compilers other than MSVC are ok in practice,
+# though.
+if cc.get_id() == 'msvc' and not cxx20_ok
   subdir_done()
 endif
 
-- 
2.53.0