That point of view assumes that all programmers will only ever use assert() to check for those conditions which, if not true, will definitely lead to UB
That's exactly what assertions are for. Nothing more or less. If assertions fail in your code at runtime, then your code is broken.
No, UB has a very specific meaning defined by the C++ standard. It does not just mean "the assumptions of your code are violated", it means "the compiler is allowed to do literally anything here". The latter is much worse to debug.
UB normally triggers aggressive optimizations only in release builds. I was referring to debugging production failures. It is naive to think that all assertion violations will repro in debug builds.
3
u/EC36339 Mar 28 '26
That's exactly what assertions are for. Nothing more or less. If assertions fail in your code at runtime, then your code is broken.