[libcxx-commits] [libcxx] [libc++][hardening] Allow setting the assertion semantic via CMake. (PR #167636)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 13 10:30:41 PST 2025


================
@@ -135,13 +135,25 @@ _LIBCPP_HARDENING_MODE_EXTENSIVE, \
 _LIBCPP_HARDENING_MODE_DEBUG
 #endif
 
-// Hardening assertion semantics generally mirror the evaluation semantics of C++26 Contracts:
+// The library provides the macro `_LIBCPP_ASSERTION_SEMANTIC` for configuring the assertion semantic used by hardening;
+// it can be set to one of the following values:
+//
+// - `_LIBCPP_ASSERTION_SEMANTIC_IGNORE`;
+// - `_LIBCPP_ASSERTION_SEMANTIC_OBSERVE`;
+// - `_LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE`;
+// - `_LIBCPP_ASSERTION_SEMANTIC_ENFORCE`.
+//
+// libc++ assertion semantics generally mirror the evaluation semantics of C++26 Contracts:
 // - `ignore` evaluates the assertion but doesn't do anything if it fails (note that it differs from the Contracts
 //   `ignore` semantic which wouldn't evaluate the assertion at all);
 // - `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.
 //
+// Additionally, a special `hardening-dependent` value selects the assertion semantic based on the hardening mode in
+// effect: the production-capable modes (`fast` and `extensive`) map to `quick_enforce` and the `debug` mode maps to
+// `enforce`.
----------------
ldionne wrote:

```suggestion
// `enforce`. The hardening-dependent assertion cannot be selected explicitly, it is only used when no assertion semantic is provided by the user and the library's default semantic is configured to be dependent on hardening.
```


https://github.com/llvm/llvm-project/pull/167636


More information about the libcxx-commits mailing list