Subject: Emacs fail to build with GCC 15

From: MAN ONE <[email-masked]>
Date: Wed, 30 Apr 2025 04:38:42 +0000

Earlier this week Msys2 upgraded GCC to version 15.1.0, which lead to this build error:

emacsclient.c:1718:9: warning: no previous declaration for 'set_fg' [-Wmissing-variable-de
clarations]
 1718 | FARPROC set_fg;  /* Pointer to AllowSetForegroundWindow.  */
      |         ^~~~~~
emacsclient.c:1719:9: warning: no previous declaration for 'get_wc' [-Wmissing-variable-de
clarations]
 1719 | FARPROC get_wc;  /* Pointer to RealGetWindowClassA.  */
      |         ^~~~~~
emacsclient.c: In function 'w32_find_emacs_process':
emacsclient.c:1759:9: error: too many arguments to function 'get_wc'; expected 0, have 3
 1759 |   if (! get_wc (hWnd, class, sizeof (class))
      |         ^~~~~~  ~~~~
emacsclient.c:1770:3: error: too many arguments to function 'set_fg'; expected 0, have 1
 1770 |   set_fg (emacs_pid);
      |   ^~~~~~  ~~~~~~~~~
emacsclient.c:1718:9: warning: no previous declaration for 'set_fg' [-Wmissing-variable-de
clarations]
 1718 | FARPROC set_fg;  /* Pointer to AllowSetForegroundWindow.  */
      |         ^~~~~~
emacsclient.c:1719:9: warning: no previous declaration for 'get_wc' [-Wmissing-variable-de
clarations]
 1719 | FARPROC get_wc;  /* Pointer to RealGetWindowClassA.  */
      |         ^~~~~~
emacsclient.c: In function 'w32_find_emacs_process':
emacsclient.c:1759:9: error: too many arguments to function 'get_wc'; expected 0, have 3
 1759 |   if (! get_wc (hWnd, class, sizeof (class))
      |         ^~~~~~  ~~~~
emacsclient.c:1770:3: error: too many arguments to function 'set_fg'; expected 0, have 1
 1770 |   set_fg (emacs_pid);
      |   ^~~~~~  ~~~~~~~~~
make[2]: *** [Makefile:446: emacsclientw.exe] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [Makefile:439: emacsclient.exe] Error 1
make[2]: Leaving directory '/e/home/repo/emacs/lib-src'
make[1]: *** [Makefile:529: lib-src] Error 2
make[1]: *** Waiting for unfinished jobs....

I think the cause is GCC 15 now use C23 by default[1], and appending ` -std=gnu17 ` compiler flag does solve the problem.

[1]https://gcc.gnu.org/gcc-15/porting_to.html#c23