On 03.06.25 06:51, Michael Paquier wrote:
Dropping VS 2015 and going up to VS 2019 brings other benefits, __VA_ARGS__ coming in mind.
Yes, this was going to be my next step. As we're already talking about it, here is my proposed patch.
For an explanation, the background is that MSVC has a "traditional" preprocessor and a new "conforming" one. The latter is available starting in VS 2019, but it's not the default. We have some code, especially around __VA_ARGS__ that specifically caters to this traditional preprocessor.
Turning on C11 mode in MSVC (/std:c11) automatically turns on the conforming preprocessor, which would currently break compilation on MSVC because the code expects it to be in traditional mode.
So my first patch is that we fix that bit and turn on just the conforming preprocessor (/Zc:preprocessor), without turning on C11 yet. That way, we get that part out of the way, and we update the documentation about requiring VS 2019. (And we'd flush out anyone who might still be running pre-VS-2019 build jobs somewhere.) Later, when we turn on C11, we can remove the explicit /Zc:preprocessor option again.
(An alternative approach would be to turn on C11 and add another option to explicitly turn the traditional preprocessor back on, but that seems pointless, and the documentation also suggests that that combination is not well supported.)
So the attached patch is my proposal to commit early in PG19.
From 0e2e4f6dd4dc4250f48736ec5a1b9bd40aad4fff Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <pe...@eisentraut.org> Date: Wed, 4 Jun 2025 07:09:42 +0200 Subject: [PATCH] Enable MSVC conforming preprocessor Switch MSVC to use the conforming preprocessor, using the /Zc:preprocessor option. This allows us to drop the alternative implementation of VA_ARGS_NARGS() for the previous "traditional" preprocessor. This also prepares the way for enabling C11 mode in the future, which enables the conforming preprocessor by default. This now requires Visual Studio 2019. The installation documentation is adjusted accordingly. Discussion: https://www.postgresql.org/message-id/flat/01a69441-af54-4822-891b-ca28e05b215a%40eisentraut.org --- doc/src/sgml/installation.sgml | 8 ++------ meson.build | 4 ++++ src/include/c.h | 19 ------------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index de19f3ad929..cb53530cc4f 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -3847,17 +3847,13 @@ <title>Visual Studio</title> <para> Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite. 32-bit PostgreSQL builds are possible with - <productname>Visual Studio 2015</productname> to + <productname>Visual Studio 2019</productname> to <productname>Visual Studio 2022</productname>, as well as standalone Windows SDK releases 10 and above. 64-bit PostgreSQL builds are supported with <productname>Microsoft Windows SDK</productname> version 10 and above or - <productname>Visual Studio 2015</productname> and above. + <productname>Visual Studio 2019</productname> and above. <!-- - For 2015 requirements: - https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2015-sysrequirements-vs - For 2017 requirements: - https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-system-requirements-vs For 2019 requirements: https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements For 2022 requirements: diff --git a/meson.build b/meson.build index d142e3e408b..61cc0236612 100644 --- a/meson.build +++ b/meson.build @@ -279,6 +279,10 @@ elif host_system == 'windows' # define before including <time.h> for getting localtime_r() etc. on MinGW cppflags += '-D_POSIX_C_SOURCE' endif + if cc.get_id() == 'msvc' + # required for VA_ARGS_NARGS() in c.h; requires VS 2019 + cppflags += '/Zc:preprocessor' + endif export_file_format = 'win' export_file_suffix = 'def' diff --git a/src/include/c.h b/src/include/c.h index 8cdc16a0f4a..04fd23577de 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -376,25 +376,7 @@ * pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up * the call so that that is the appropriate one of the list of constants. * This idea is due to Laurent Deniau. - * - * MSVC has an implementation of __VA_ARGS__ that doesn't conform to the - * standard unless you use the /Zc:preprocessor compiler flag, but that - * isn't available before Visual Studio 2019. For now, use a different - * definition that also works on older compilers. */ -#ifdef _MSC_VER -#define EXPAND(args) args -#define VA_ARGS_NARGS(...) \ - VA_ARGS_NARGS_ EXPAND((__VA_ARGS__, \ - 63,62,61,60, \ - 59,58,57,56,55,54,53,52,51,50, \ - 49,48,47,46,45,44,43,42,41,40, \ - 39,38,37,36,35,34,33,32,31,30, \ - 29,28,27,26,25,24,23,22,21,20, \ - 19,18,17,16,15,14,13,12,11,10, \ - 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#else - #define VA_ARGS_NARGS(...) \ VA_ARGS_NARGS_(__VA_ARGS__, \ 63,62,61,60, \ @@ -404,7 +386,6 @@ 29,28,27,26,25,24,23,22,21,20, \ 19,18,17,16,15,14,13,12,11,10, \ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) -#endif #define VA_ARGS_NARGS_( \ _01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \ base-commit: 7f3381c7ee661e552634f06509a3452988a15845 -- 2.49.0