Known pitfalls in C++26 Contracts


Details
Contracts let developers specify formal correctness conditions, improving clarity, catching errors, and enabling optimizations. On our March meetup, Ran Regev will talk about Contracts in C++ - a feature that's expected to enter the C++26 revision after over a decade of discussions. Ran has been taking part in these discussions and is familiar with the feature's strenghs and weaknesses. In this talk, Ran will discuss Contracts pitfalls and how to avoid them.
Agenda:
17:30 - Gathering @ Cadence office, refreshments, and mingling
18:00 - Known pitfalls in C++26 Contracts
19:00 - Wrap-up
Talk abstract:
Contracts are a feature expected to be included in C++26, allowing developers to formally specify preconditions, postconditions, and invariants within their code. By explicitly defining these conditions, contracts provide a mechanism for expressing assumptions and guarantees, helping to catch logic errors early, improve code clarity, and enable better optimization opportunities. This feature aims to bring a structured, language-supported approach to runtime and potentially compile-time validation, reducing reliance on ad-hoc assertions and comments to convey intent.
While contracts are a strong and useful tool, using them is not free of pitfalls, despite a lengthy standardization process. This talk will start with an intro to the contracts mechanism and its C++ implementation, then describe the status of the feature, and finally review known pitfalls in using the new C++ contracts and how to overcome them.
Speaker bio:
Ran Regev is a professional C++ developer in the last 25 years. Ran spends his time in SG21 (Contracts Study Group) trying to improve the feature as much as possible.
Our generous hosts:
Cadence is a pivotal leader in electronic systems design, building upon more than 30 years of computational software expertise. The company applies its underlying Intelligent System Design strategy to deliver software, hardware, and IP that turn design concepts into reality.
Cadence customers are the world’s most innovative companies, delivering extraordinary products from chips to systems, chemicals to drugs, and specification to manufacturing for the most dynamic market applications, including hyperscale computing, 5G communications, automotive, mobile, aerospace, consumer, industrial, and life sciences.

Known pitfalls in C++26 Contracts