Subject: RE: MinGW compiler warnings in ecpg tests

From: "Hayato Kuroda (Fujitsu)" <[email-masked]>
Date: Fri, 10 Nov 2023 07:59:49 +0000

Dear Peter, Michael,

Sorry for reviving the old thread. While trying to build postgres on msys2 by meson,
I faced the same warning. The OS is Windows 10.

```
$ ninja
[2378/2402] Compiling C object src/interfaces/ecpg/test/sql/sqlda.exe.p/meson-generated_.._sqlda.c.obj
../postgres/src/interfaces/ecpg/test/sql/sqlda.pgc: In function 'dump_sqlda':
../postgres/src/interfaces/ecpg/test/sql/sqlda.pgc:45:33: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   45 |                                 "name sqlda descriptor: '%s' value %I64d\n",
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
   49 |                                 sqlda->sqlvar[i].sqlname.data, *(long long int *)sqlda->sqlvar[i].sqldata);
      |                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                |
      |                                                                long long int
```

Before building, I did below steps:

1. Installed required software listed in [1].
2. ran `meson setup -Dcassert=true -Ddebug=true /path/to/builddir`
3. moved to /path/to/builddir
4. ran `ninja`
5. got above warning

Attached file summarize the result of meson command, which was output at the end of it.
Also, belows show the version of meson/ninja.

```
$ ninja --version
1.11.1
$ meson -v
1.2.3
```

I was quite not sure the windows build, but I could see that gcc compiler was
used here. Does it mean that the compiler might not like the format string "%I64d"?
I modified like below and could be compiled without warnings.

```
--- a/src/interfaces/ecpg/test/sql/sqlda.pgc
+++ b/src/interfaces/ecpg/test/sql/sqlda.pgc
@@ -41,7 +41,7 @@ dump_sqlda(sqlda_t *sqlda)
                        break;
                case ECPGt_long_long:
                        printf(
-#ifdef _WIN32
+#if !defined(__GNUC__)
                                "name sqlda descriptor: '%s' value %I64d\n",
 #else
                                "name sqlda descriptor: '%s' value %lld\n",

```

[1]: https://www.postgresql.org/message-id/9f4f22be-f9f1-b350-bc06-521226b87f7a%40dunslane.net

Best Regards,
Hayato Kuroda
FUJITSU LIMITED

---

From: Thomas Munro <[email-masked]>
Date: Fri, 6 Dec 2024 01:15:52 +1300

> I faced the same warning. The OS is Windows 10.

Yeah.  This warning is visible on CI, and on fairywren since its MSYS2
upgrade a couple of months ago.  Old MinGW didn't like %lld (I think
perhaps the printf from msvcrt.dll from 1996 didn't like it and MinGW
knew that), but new MinGW doesn't like %I64d (that's interesting, but
not relevant here because %lld is clearly the correct format string,
and it works).  We should just revert that change.  Here's a patch.

That leaves only three more annoying warnings:

../pgsql/src/backend/postmaster/postmaster.c:857:31: warning:
'__p__environ' redeclared without dllimport attribute: previous
dllimport ignored [-Wattributes]
  857 |                 extern char **environ;

Those were there before the upgrade.  POSIX says that environ should
not be declared by a header, but Windows apparently declares it, or at
least its cousin _environ, in <stdlib.h> which we include in c.h.  I
have no idea why Visual Studio doesn't warn, or why the documentation
only tells you about _environ and not environ, or where the macro (?)
comes from that renames it, but it passes CI and is
warning-free on both toolchains if you just hide the offending
declarations.

---

From: Tom Lane <[email-masked]>
Date: Thu, 05 Dec 2024 10:11:11 -0500

> and it works).  We should just revert that change.  Here's a patch.

+1

> warning-free on both toolchains if you just hide the offending

Isn't this likely to break things for every other Windows toolchain?
I think the concept might be OK, but we need a tighter #if condition.

An alternative could be to add the missing dllimport on Windows;
it's not clear whether other toolchains would care.

			regards, tom lane

---

From: Thomas Munro <[email-masked]>
Date: Fri, 6 Dec 2024 15:44:20 +1300

> > and it works).  We should just revert that change.  Here's a patch.

Thanks for looking.  Pushed, and that fixed that on fairywren.

> I think the concept might be OK, but we need a tighter #if condition.

Cool, I'll do that for MinGW only then.

> it's not clear whether other toolchains would care.

I've been digging through its headers (working on a fix for the off_t
bug report) and noticed in passing that it probably thinks we're
re-declaring this function:

https://github.com/mingw-w64/mingw-w64/blob/8bcd5fc1a72c0b6da3147bf21a4a494c81d14fae/mingw-w64-headers/crt/stdlib.h#L221

Seems like a good idea to give that a wide berth :-)

---

From: Andres Freund <[email-masked]>
Date: Thu, 30 Oct 2025 17:39:24 -0400

Hi,

> Cool, I'll do that for MinGW only then.

I was looking at merging [1], however the backbranches < 18 fail in
CompilerWarnings due to this error [2], after upgrading to trixie. Seems like
we ought to backpatch 7bc9a8bdd2d.  Haven't checked yet whether 1319997d is
also required for a clean build.

Greetings,

Andres Freund

[1] https://postgr.es/m/CAN55FZ1_B1usTskAv%2BAYt1bA7abVd9YH6XrUUSbr-2Z0d5Wd8w%40mail.gmail.com
[2] https://cirrus-ci.com/task/6526575971139584

---

From: Andres Freund <[email-masked]>
Date: Tue, 4 Nov 2025 13:34:29 -0500

Hi,

> also required for a clean build.

After verifying that 1319997d is not required I backpatched 7bc9a8bdd2d to all
the branches lacking it.

Greetings,

Andres Freund