Details
-
Task
-
Status: Stalled (View Workflow)
-
Major
-
Resolution: Unresolved
-
None
Description
An assertion is basically a test of an invariant, that should be true during the program run. Having it false makes a program run into an undefined behavior. This is also true for an optimized, code, where the assertion is not checked, but it has no benefit of this invariant.
Let's add this benefit by instrumenting DBUG_ASSERT with a platform-dependent c++23 analog of [[assume(cond)]].
For optimized builds, it'll bring an extra freedom for a compiler in the code optimization., for example it can reorganize while-do loops into do-while, if it knows that the loop will run at least once.
For debug builds, it'll help data flow analysis tools, like clang-tidy, to make correct assumptions.
Additionally, it will resolve a problem with all-around IF_DBUG use for avoiding unused variable warnings in release builds.