Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
RIEGELI_EVAL_ASSERT*
family of assertion macros.
They are similar to the `RIEGELI_ASSERT*` family, but they always evaluate the arguments. They replace the `if (!condition) RIEGELI_ASSERT_UNREACHABLE()` idiom, being consistent with other macros and printing compared values if the assumption fails in debug mode. Also they do not allow the compiler to optimize under the assumption that the condition holds, because this is not expected in most cases. Use `RIEGELI_ASSUME*` instead if that is useful. Add `RIEGELI_ASSUME*` family of assertion macros. They are similar to the `RIEGELI_ASSERT*` family, but they allow the compiler to optimize based on the assumption that the condition holds. In the current implementation the condition is evaluated unconditionally, but this should not be relied upon. The name reminds of C++23 `[[assume(condition)]];`. Rename `RIEGELI_ASSERT_NOTNULL` to `RIEGELI_EVAL_ASSUME_NOTNULL`, and `RIEGELI_ASSERT_UNREACHABLE` to `RIEGELI_ASSUME_UNREACHABLE`. They already had the semantics corresponding to new names. Add `RIEGELI_{CHECK,ASSERT,EVAL_ASSERT,ASSUME}_OK` for checking `absl::Status`, `absl::StatusOr<T>`, and the status of instances of classes deriving from `Object`. Use `ABSL_LOG()` in `RIEGELI_CHECK*` macros instead of writing to stderr. Rework their implementation. This version tries harder to optimize for the code size, by moving more code to out of line functions. Use `if (type variable = init)` syntax. This is cleaner than `while` which relied on process termination in the false case to avoid an infinite loop, and this can be used also when the false case is not fatal. PiperOrigin-RevId: 700231814
- Loading branch information