Insights derived from a talk given by Timur Doumler
Performance-critical trading systems are known to focus on speed and latency. However, correctness is just as important: Incorrect behavior in production systems can lead to significant financial loss or market disruption. To improve code correctness at scale, developers need to define what “correct” means in a way that compilers, static analysis tools, IDEs and LLMs can consume. Historically, this has been difficult.
Most codebases rely on some form of assertions, typically implemented as macros (either C assert or custom variants). They can be enabled, disabled and configured via the preprocessor. This approach has disadvantages: It can break parsing or introduce ODR violations. And it doesn’t scale well across large, heterogeneous systems.
Moreover, assertion macros must be placed inside function implementations — which may not be accessible by other parts of the system — and thus do not provide a way to express intent on interfaces.
C++26 introduces contract assertions as a built-in language feature. Unlike traditional assertions, they are part of the core language, not macros. As such, they work seamlessly across translation units, modules and large code bases.
At a basic level, contract assertions allow developers to:
One of the most important improvements is flexibility. Contract assertions support multiple evaluation semantics:
Each evaluation semantic serves a particular use case:
C++26 also introduces a contract-violation-handler, which is called when a contract assertion fails. It can be replaced at link time.
This allows developers to define what happens when a contract fails. That can include logging diagnostics and stack traces, triggering debugging workflows or performing a managed shutdown or recovery.
The system provides structured, programmatically accessible information about which assertion failed, where and in what context, aiding debugging and diagnostics.
Preconditions and Postconditions at the Interface Level
The most significant shift, compared to pre-C++26 macro-based assertions, is where the assertions live.
C++26 allows developers to define:
These are attached directly to function declarations, not buried inside implementations.
Contracts become part of the interface and are visible to developers, compilers, IDEs, static analysis tools and LLMs.
This enables earlier, more reliable detection of incorrect usage, better tooling support and clearer documentation of system behavior.
The benefits of precondition and postcondition assertions on declarations are especially important in environments where:
Contract assertions provide a way to enforce expectations on correctness without exposing internals. This is especially important in finance, where information boundaries matter.
Designed for Incremental Adoption
C++26 contracts are designed to work in real-world codebases. They can be added to existing systems without breaking behavior, and they don’t change the meaning of correct programs. They can also be introduced incrementally, component by component.
This makes adoption practical, even in the large, complex and mature production systems found throughout finance and trading.
At Citadel Securities, we actively engage with the C++ community because we believe contribution benefits both the broader developer ecosystem and our firm. We are proud of the role our C++ committee members and colleagues play in helping advance the field.
Insights derived from a talk given by Timur Doumler
Performance-critical trading systems are known to focus on speed and latency. However, correctness is just as important: Incorrect behavior in production systems can lead to significant financial loss or market disruption. To improve code correctness at scale, developers need to define what “correct” means in a way that compilers, static analysis tools, IDEs and LLMs can consume. Historically, this has been difficult.
Most codebases rely on some form of assertions, typically implemented as macros (either C assert or custom variants). They can be enabled, disabled and configured via the preprocessor. This approach has disadvantages: It can break parsing or introduce ODR violations. And it doesn’t scale well across large, heterogeneous systems.
Moreover, assertion macros must be placed inside function implementations — which may not be accessible by other parts of the system — and thus do not provide a way to express intent on interfaces.
C++26 introduces contract assertions as a built-in language feature. Unlike traditional assertions, they are part of the core language, not macros. As such, they work seamlessly across translation units, modules and large code bases.
At a basic level, contract assertions allow developers to:
One of the most important improvements is flexibility. Contract assertions support multiple evaluation semantics:
Each evaluation semantic serves a particular use case:
C++26 also introduces a contract-violation-handler, which is called when a contract assertion fails. It can be replaced at link time.
This allows developers to define what happens when a contract fails. That can include logging diagnostics and stack traces, triggering debugging workflows or performing a managed shutdown or recovery.
The system provides structured, programmatically accessible information about which assertion failed, where and in what context, aiding debugging and diagnostics.
Preconditions and Postconditions at the Interface Level
The most significant shift, compared to pre-C++26 macro-based assertions, is where the assertions live.
C++26 allows developers to define:
These are attached directly to function declarations, not buried inside implementations.
Contracts become part of the interface and are visible to developers, compilers, IDEs, static analysis tools and LLMs.
This enables earlier, more reliable detection of incorrect usage, better tooling support and clearer documentation of system behavior.
The benefits of precondition and postcondition assertions on declarations are especially important in environments where:
Contract assertions provide a way to enforce expectations on correctness without exposing internals. This is especially important in finance, where information boundaries matter.
Designed for Incremental Adoption
C++26 contracts are designed to work in real-world codebases. They can be added to existing systems without breaking behavior, and they don’t change the meaning of correct programs. They can also be introduced incrementally, component by component.
This makes adoption practical, even in the large, complex and mature production systems found throughout finance and trading.
At Citadel Securities, we actively engage with the C++ community because we believe contribution benefits both the broader developer ecosystem and our firm. We are proud of the role our C++ committee members and colleagues play in helping advance the field.