Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there any compiler option to have it yell at you if you mark something that can throw as `noexcept`, which seems to be the cause of (at least some of) the slowdowns where the compiler is forced to accommodate with `std::terminate`? I feel like these situations are more commonly mistakes, and not the user wanting to "collapse" exceptions into terminations. So the current approach to dealing with these cases seems to be suboptimal not only from a performance perspective, but a behavior perspective as well.


No, calling throw in a noexcept function is a defined behavior (call std::terminate), and that behavior is not a diagnostic

I think maybe WG21 was concerned a compiler engineer would be clever if throwing in noexcept were UB, for example and assume any block that throws is unreachable and could just be removed along with all blocks it postdominates. Compiler guys love optimizations that just remove code. The fastest and smallest code is code that can’t run and doesn’t exist


Compilers are allowed to and do diagnose defined but undesirable behavior though, even more so if that's only enabled with an option.


Until yesterday I thought I was the only person in the world who thought the designed behavior was undesirable, though




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: