Your code looks sound, and is compiling, linking and working properly with g++ 14.2 on a 64-bit Debian.
It is very likely that your issue is specific to MinGW/MSYS, you should report them a bug.