Re: MSVC: Improve warning options set

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Bryan Green <dbryan(dot)green(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: MSVC: Improve warning options set
Date: 2025-11-03 18:56:16
Message-ID: c4557039-2ae3-4afb-9d83-6201d658ae79@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 31.10.25 14:31, Bryan Green wrote:
> Regarding the environ declaration-- it comes down to which C runtime is
> being targeted.
>
> The old MSVCRT (msvcrt.dll) actually exported environ as a data symbol,
> so declaring "extern char **environ;" worked fine. MinGW traditionally
> targeted this runtime, and older MSVC versions used it too.
>
> The Universal CRT (UCRT), introduced with VS2015, changed the ABI. It
> doesn't export environ directly—instead it exports __p__environ() as a
> function and provides the _environ macro. That's why modern MSVC
> complains about the declaration.
>
> So when commit 7bc9a8bdd2d added || defined(_MSC_VER), it was probably
> correct for whatever toolchains were supported at that time. But if we
> now require VS2015+ (which I think we do), then removing that condition
> makes sense.
>
> The real question is MinGW. If we still support MinGW builds targeting
> the old MSVCRT, those need the environ declaration. If we require MinGW
> with UCRT, we don't. You'd need something like "#if defined(MINGW32)
> && !defined(_UCRT)" to distinguish them, if it matters.

As of commit 1758d424461 (PG18) we require UCRT if using MinGW.

I don't know if we still support MSVCRT if using MSVC, or how long we
still need to support it. (Or, for example, how to tell which variant
CI or the buildfarm uses.)

> What's our minimum supported MSVC version these days? I am partially
> interested in this answer because it would be aesthetically pleasing to
> get rid of the unneeded ones listed in win32env.c--

As of commit 8fd9bb1d965 (PG19) we require Visual Studio 2019.

> static const char *const modulenames[] = {
>         "msvcrt",                /* Visual Studio 6.0 / MinGW */
>         "msvcrtd",
>         "msvcr70",                /* Visual Studio 2002 */
>         "msvcr70d",
>         "msvcr71",                /* Visual Studio 2003 */
>         "msvcr71d",
>         "msvcr80",                /* Visual Studio 2005 */
>         "msvcr80d",
>         "msvcr90",                /* Visual Studio 2008 */
>         "msvcr90d",
>         "msvcr100",                /* Visual Studio 2010 */
>         "msvcr100d",
>         "msvcr110",                /* Visual Studio 2012 */
>         "msvcr110d",
>         "msvcr120",                /* Visual Studio 2013 */
>         "msvcr120d",
>         "ucrtbase",                /* Visual Studio 2015 and later */
>         "ucrtbased",
>         NULL
>     };

So that would mean we can remove all but the two ucrt* entries? Is
there no more msvcr* after VS 2015?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Verite 2025-11-03 19:14:03 Re: Remaining dependency on setlocale()
Previous Message Pickett, Eshe N 2025-11-03 18:55:40 [PATCH v1 1/1] PostgreSQL Patch: AVX-Optimized ASCII Validation