On 23.03.26 10:58, Jelte Fennema-Nio wrote:
On Mon, 23 Mar 2026 at 10:27, Peter Eisentraut <[email protected]> wrote:
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.)
Sounds good to me.
This has been committed.
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.
I think we should add these flags to CXXFLAGS for MSVC by default,
similar to how we add -std=gnu++11/-std=c++11 for other compilers. We
can then document on the C++ extension docs page, that MSVC compilers
require C++20 support.
Here is another tidied up patch set for this. I didn't go quite as far
as enabling C++20 by default in meson.build, this would just take more
time to work out and test all the different combinations, but I added
the flag to the Cirrus CI task, since there we know what compiler we have.
From a9f04ed6fd4ce8ea5b01cbafec2181a2d69a2783 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 27 Mar 2026 11:45:36 +0100
Subject: [PATCH v11 1/3] meson: Make room for C++-only warning flags for MSVC
Refactor the MSVC warning option handling to have a list of common
flags and lists of flags specific to C and C++.
---
meson.build | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/meson.build b/meson.build
index ea31cbce9c0..42b0a9a6a71 100644
--- a/meson.build
+++ b/meson.build
@@ -2293,27 +2293,42 @@ endforeach
if cc.get_id() == 'msvc'
- cflags_warn += [
+ msvc_common_warning_flags = [
+ # Disable warnings in system headers
+ '/external:anglebrackets',
+ '/external:W0',
+
# Warnings to disable:
- # from /W1:
- '/wd4090', # different 'modifier' qualifiers
# from /W2:
'/wd4244', # conversion from 'type1' to 'type2', possible loss of data
+
+ # Additional warnings to enable:
+ '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is
not handled [like -Wswitch]
+ '/w24102', # unreferenced label [like -Wunused-label]
+ ]
+
+ msvc_c_warning_flags = [
+ # Warnings to disable:
+ # from /W1:
+ '/wd4090', # different 'modifier' qualifiers
# from /W3:
'/wd4018', # signed/unsigned mismatch
'/wd4101', # unreferenced local variable [like -Wunused-variable, but
there is no "unused" attribute, so too noisy]
'/wd4267', # conversion from 'size_t' to 'type', possible loss of data
# Additional warnings to enable:
- '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is
not handled [like -Wswitch]
- '/w24102', # unreferenced label [like -Wunused-label]
'/w24255', # 'function' : no function prototype given: converting '()' to
'(void)' [like -Wstrict-prototypes]
+ ]
- # Disable warnings in system headers
- '/external:anglebrackets',
- '/external:W0',
+ msvc_cxx_warning_flags = [
]
+ cflags_warn += msvc_common_warning_flags
+ cflags_warn += msvc_c_warning_flags
+
+ cxxflags_warn += msvc_common_warning_flags
+ cxxflags_warn += msvc_cxx_warning_flags
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
--
2.53.0
From 543f49124a45804584c193d4083bebe3bab74f71 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 26 Mar 2026 08:35:45 +0100
Subject: [PATCH v11 2/3] Disable some C++ warnings in MSVC
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.)
---
meson.build | 3 +++
1 file changed, 3 insertions(+)
diff --git a/meson.build b/meson.build
index 42b0a9a6a71..64a5bb888d6 100644
--- a/meson.build
+++ b/meson.build
@@ -2321,6 +2321,9 @@ if cc.get_id() == 'msvc'
]
msvc_cxx_warning_flags = [
+ # Warnings to disable:
+ # from /W2:
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union
[widely used in PostgreSQL C headers]
]
cflags_warn += msvc_common_warning_flags
--
2.53.0
From ca2797018cca5b705d55456dcaca6d18db4816e4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
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