EDITIt appears, that this problem is harder to reproduce than anticipated - godbolt doesn't allow me to run it with msvc compiler. At first glance, it seems to be connected with Catch2 testing framework. I've setup a github repo with the required cross-platform cmake setup to reproduce it consistently. It will automatically fetch Catch2 testing framework for you. Once you clone, just open the CMakeLists.txt with visual studio 2022, and it should work out-of-the-box.
Building with /O1 and /O2 flags fixes the problem, as demonstrated in the repository, and since this happens only in Release, that's a completely viable solution!I'm still curious as to why it happens, though. It might be a sign of a deeper problem.
3a8082e126