This seems to be a MinGW compiler bug since when using MSVC in Visual Studio to compile the code, the same exception does not occur either.
4
solved std::ifstream crashes in release build on Windows with exit code 0xC0000409: Unknown software exception