On 13.02.26 11:28, Jelte Fennema-Nio wrote:
After discussing the topic in-person with Peter at FOSDEM. We agreed that the best road forward was to not bother with MSVC for now. No-one has actually expressed an interest in being able to build C++ extension using MSVC, and the effort to support it is both non-trivial and not without downsides to the rest of the codebase. We can always come back to this later, possibly requiring C++20 on MSVC.
I checked what would currently be missing to get MSVC supported. Attached is the patch.
I think we should commit the pg_list.h changes, since the C-style compound literals are not a C++ feature at all, and so without this MSVC would never get supported. (Or you couldn't use PostgreSQL lists, which would be very limiting.)
Here is a Compiler Explorer link that I used to check that the generated code doesn't change: https://godbolt.org/z/ovKKzEfs6
The other changes deal with designated initializers and flexible array members. These are not a blocker, since extension authors could deal with them themselves by adding appropriate compiler options or similar.
From bf1a3fb2cee222a26660c1266089a4c94147c0cb Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <[email protected]> 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
