I tried to compile in Windows 10(MinGW64) with [gcc version 11.2.0 (Rev5, Built by MSYS2 project)].
Changing optimization level to -O1 solved the problem and it compiled successfully.
I never got mingw/msys2 working from a Windows host but if you've gotten this far it's worth pursuing.
If you have git an issue would be appropriate for tracking.
It compiles ok with gcc 11.2.0 on Ubuntu-21-10 but I don't have mingw setup for that. I currently use gcc 9.3.0
in Ubuntu 20.04 to build the Windows binaries as documentd on the Wiki.
It's odd that it would compile depending on compiler optimizations, also that it's old code.
If I can identify what code is causing it there might be a better way to write it even if the bug isn't obvious.
Since it compiles with -O1, unless there's a switch that turns a -O1 warning into a -O2 error, there could also
be a compiler bug.
The error you posted wasn't very useful, it only identified the file, not the line. Are there earlier errors with more info?
Relevant warnings, if any, from the -O1 compile might also be useful in figuring out why this switch makes a difference.
If you can document your procedure I'm sure a lot of people would be grateful, including me. The current procedure
using a full Linux installation, VM or separate PC, is quite cumbersome.