[libcxx-commits] [libcxx] [libcxxabi] [libc++][hardening] Implement support for assertion semantics. (PR #148172)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 11 12:23:25 PDT 2025
================
@@ -147,6 +147,36 @@ _LIBCPP_HARDENING_MODE_EXTENSIVE, \
_LIBCPP_HARDENING_MODE_DEBUG
# endif
+// Hardening assertion semantics mirror the evaluation semantics of P3100 Contracts:
+// - `ignore` does not evaluate the assertion;
+// - `observe` logs an error (indicating, if possible, that the error is fatal) and continues execution;
+// - `quick-enforce` terminates the program as fast as possible (via trapping);
+// - `enforce` logs an error and then terminates the program.
+// Notes:
+// - Continuing execution after a hardening check fails results in undefined behavior; the `observe` semantic is meant
+// to make adopting hardening easier but should not be used outside of this scenario;
+// - P3471 "Standard Library Hardening" wording precludes using the Contracts `ignore` semantic for hardened
+// preconditions in the Library; allowing this semantic to be used is a libc++ vendor extension.
----------------
ldionne wrote:
```suggestion
// - C++26 "Standard Library Hardening" wording precludes a conforming "Hardened" implementation from using the Contracts `ignore` semantic when evaluating hardened preconditions in the Library. Libc++ allows using this semantic for hardened preconditions, however be aware that using `ignore` does not produce a conforming "Hardened" implementation, unlike the other semantics above.
```
https://github.com/llvm/llvm-project/pull/148172
More information about the libcxx-commits
mailing list