The contracts-jac-kona branch includes an implementation of assertion contracts as outlined by the working draft, P1332R0, P1429R0, and P1290R1. Each proposal is implemented using the same underlying framework which maps roles and varios modes onto a small set of concrete semantics.
The five concrete semantics defined in P1332 are implemented and usable as explicit semantics in source. These are:
From the working draft: -fcontract-build-level=<off|default|audit> Determines the highest level of contract for which runtime checks are emitted. -fcontract-continuation-mode=<on|off> Determines whether execution resumes after a failed contract check (default off).
From P1290: -fcontract-axiom-mode=<on|off> Determines whether a compile time assumption is emitted for axioms. If set to on (the default) the optimizer may assume the contract condition is true.
From P1429: -fcontract-mode=<on|off> When set to off, treats all contracts as if they have the ignore semantic -fcontract-semantic=<level>:<semantic> Treats the specified level as having the given concrete semantic.
From P1332: -fcontract-role=<id>:<semantics> Given a comma delimited set of semantics, create or update a role's semantic mapping.
Semantics using WD and P1290 flags
Semantics for each level are selected through a combination of modes. With the contract level shown as rows and the -fcontract-build-level shown as columns the defaults are:
When -fcontract-continuation-mode=on is given, the check_never_continue above are replaced with check_maybe_continue.
When -fcontract-axiom-mode=off is given, the axiom row turns into ignore under all build levels.
When -fcontract-mode=off is given, each entry is turned into ignore.
Semantics using P1429 and P1332 flags
The default semantics using explicit assignment switches are:
(this corresponds to the default semantics from the previous section)
Any individual level's semantic can be changed using -fcontract-semantic=<level>:<semantic>.
All three semantics can be changed at once using -fcontract-role=default:<semantics>.
All contract semantics (including ones explicitly defined in the source) can be changed to ignore by using the -fcontract-mode=off flag.
A custom contract violation handler can be installed by defining void handle_contract_violation(const std::contract_violation &violation) (you must #include <contract> for this to work) or by using LD_PRELOAD. An example of defining the handler in the main TU can be found in the testsuite here. Examples of how to use LD_PRELOAD to install a custom violation handler are available in the contracts folder inside the testsuite.