Contracts in C++26 provide a formal way to specify and verify software component interfaces through preconditions, postconditions, and invariants. The feature includes four evaluation semantics (ignore, observe, enforce, quick-enforce) that can be configured at compile time, link time, or runtime. Contract violations occur when predicates return false, throw exceptions, or fail to be constant expressions at compile time. Current restrictions apply to virtual functions, defaulted/deleted functions, and constructors/destructors, with preconditions evaluated after parameter initialization and postconditions evaluated before local variable destruction.
Table of contents
What are Contracts?Modernes C++ MentoringPoint of EvaluationEvaluation SemanticWhat’s next?Sort: