nocfbot-0001-Try-test_cplusplusext-with-MSVC.patch

text/plain

Filename: nocfbot-0001-Try-test_cplusplusext-with-MSVC.patch
Type: text/plain
Part: 0
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 0001
Subject: Try test_cplusplusext with MSVC
File+
src/include/nodes/pg_list.h 37 4
src/test/modules/test_cplusplusext/meson.build 5 7
src/test/modules/test_cplusplusext/test_cplusplusext.cpp 8 0
From bf1a3fb2cee222a26660c1266089a4c94147c0cb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 23 Mar 2026 10:15:04 +0100
Subject: [PATCH] Try test_cplusplusext with MSVC

- Compound literals, as used in pg_list.h, are not a C++ feature.
  MSVC doesn't accept these.  (GCC and Clang accept them, but they would
  warn in -pedantic mode.)  Replace with inline functions.  (This is the
  only instance of a compound literal used in PostgreSQL header files.)

- Flexible array members, as used in many PostgreSQL header files, are
  not a C++ feature.  MSVC warns about these.  Disable the
  warning.  (GCC and Clang accept them, but they would warn in -pedantic
  mode.)

- Designated initializers, as used in PG_MODULE_MAGIC, require C++20.

ci-os-only: windows
---
 src/include/nodes/pg_list.h                   | 41 +++++++++++++++++--
 .../modules/test_cplusplusext/meson.build     | 12 +++---
 .../test_cplusplusext/test_cplusplusext.cpp   |  8 ++++
 3 files changed, 50 insertions(+), 11 deletions(-)

diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..09b84aa0933 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -204,10 +204,43 @@ list_length(const List *l)
 /*
  * Convenience macros for building fixed-length lists
  */
-#define list_make_ptr_cell(v)	((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v)	((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v)	((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v)	((ListCell) {.xid_value = (v)})
+
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+	ListCell	c;
+
+	c.ptr_value = v;
+	return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+	ListCell	c;
+
+	c.int_value = v;
+	return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+	ListCell	c;
+
+	c.oid_value = v;
+	return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+	ListCell	c;
+
+	c.xid_value = v;
+	return c;
+}
+#endif
 
 #define list_make1(x1) \
 	list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..34f54cf1335 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,11 +4,6 @@ if not have_cxx
   subdir_done()
 endif
 
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
-  subdir_done()
-endif
-
 test_cplusplusext_sources = files(
   'test_cplusplusext.cpp',
 )
@@ -21,8 +16,11 @@ endif
 
 test_cplusplusext = shared_module('test_cplusplusext',
   test_cplusplusext_sources,
-  kwargs: pg_test_mod_args,
-)
+  kwargs: pg_test_mod_args + {
+            # C++20 is required for designated initializers in PG_MODULE_MAGIC.
+            'cpp_args': pg_test_mod_args['cpp_args'] + (cxx.get_id() == 'msvc' ? ['/std:c++20'] : []),
+          },
+                                 )
 test_install_libs += test_cplusplusext
 
 test_install_data += files(
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 93cd7dd07f7..8381bef412a 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -14,6 +14,14 @@
  * -------------------------------------------------------------------------
  */
 
+/*
+ * The warning "nonstandard extension used: zero-sized array in
+ * struct/union" appears for many PostgreSQL header files.
+ */
+#ifdef _MSC_VER
+#pragma warning(disable : 4200)
+#endif
+
 extern "C" {
 #include "postgres.h"
 #include "fmgr.h"
-- 
2.53.0