This works with the latest MSYS2 with both the CLANG32 and CLANG64 environment, but not with the MINGW32 environment. However, using the last MSYS2 that still supported Windows XP, it works in the MINGW32 environment as well. Additionally, it works when I use Clang to cross-compile from Linux.

This means it's a bug in current MSYS2's MINGW32 environment and there are plenty of other solutions that work. Closing.