https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108300
Bug ID: 108300 Summary: `abort()` macro cause bootstrap failure on *-w64-mingw32 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: bootstrap Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- Recently, mingw-w64 has got updated <msxml.h> from Wine. GCC then ceases to build: ``` ../../gcc/gcc/system.h:791:30: error: expected identifier before string constant 791 | #define abort() fancy_abort (__FILE__, __LINE__, __FUNCTION__) | ^~~~~~~~ ``` The reason is elaborated in this piece of log of #gcc on OFTC: ``` [16:51:28] <lh_ideapad> on Windows hosts, <windows.h> now involves <msxml.h>, which brings a struct that has `abort()` as a member function, so if the macro above is expanded there it will become nonsense. [16:52:34] <lh_ideapad> if GCC does not use that struct (and a plenty more) the standard way to prevent them from being included is to define `WIN32_LEAN_AND_MEAN` before inclusion of <windows.h>. unfortunately, not all GCC source files do so. [16:53:31] <lh_ideapad> there are about thirty to forty files that include <windows.h> without defining `WIN32_LEAN_AND_MEAN`. do you think it is a good idea to patch them all? [16:54:11] <lh_ideapad> this can be generated by an sed command, but it's gonna be a large patch, touching files that I am not familiar with. [16:55:03] <lh_ideapad> or, we can patch mingw-w64 msxml.h to `#undef abort`. [16:57:22] <iains> can you fixincludes windows.h to add a wrapperr that defines WIN32_LEAN_AND_MEAN and then include_next windows.h? [16:58:11] <iains> (that means you do not have to patch the original file .. you could also use fixincludes to do that too - but it seems maybe more complicated than the wrapper) [17:06:14] <iains> .. of course, that does not help if the files are sources that need to be built by the bootstrap compiler - it’s only going to succeed if they are all target-libs related. [17:23:52] <iains> .. hmm but if they are sources in the gcc tree, I’d suppose that windows.h should not be included directly - but via system.h where you could place the #define before the inclusion. [17:34:14] <Arsen> ugh, the wonders of macros [17:34:25] <Arsen> maybe that can be a static inline fn instead? [17:34:41] <Arsen> (or even just regular ol inline) [18:08:19] <jwakely> yeah, GCC should not #define abort like that, it's disgusting [18:08:40] <jwakely> "but we've always done it like that" - time to stop ``` I create this PR for the record. In my opinion, including <windows.h> without `WIN32_LEAN_AND_MEAN` pulls in tons of unnecessary stuff and is almost never desired. This can be fixed by ``` sed -Ei 's,^( *)#( *)include <windows\.h>,\1#\2define WIN32_LEAN_AND_MEAN 1\n&,' \ $(grep --inc "*.[hc]" --inc "*.cc" -Flr "<windows.h>") ``` (Some source files already have it.)