The default behavior of assert
in C++ is to do nothing in release builds. I presume this is done for performance reasons and maybe to prevent users from seeing nasty error messages.
However, I’d argue that those situations where an assert
would have fired but was disabled are even more troublesome because the application will then probably crash in an even worse way down the line because some invariant was broken.
Additionally, the performance argument for me only counts when it is a measurable problem. Most assert
s in my code aren’t much more complex than
assert(ptr != nullptr);
which will have small impact on most code.
This leads me to the question: Should assert
s be active in release builds? Why (not)?