This article brought to you by LWN subscribersSubscribers to LWN.net made this article — and everything that surrounds it — possible. If you appreciate our content, please buy a subscription and make the next set of articles possible.
The International Organization for Standardization (ISO) has blessed seven C++ language revisions since 1998. The language is mostly developed by ISO's Working Group 21, which considers proposed additions and amendments, integrates them into a document, and then presents that document to the main ISO body to be voted on as a standard. On October 23, for the first time ever, ISO declined to ratify a document presented by Working Group 21, leaving the future of the C++26 standard in doubt. The decision was driven by controversy around a proposed new "contracts" feature that would add pre- and post-conditions to function signatures.
Contracts
The contracts feature proposed for inclusion in C++26 was deliberately minimal, following design disagreements stretching back to 2004. It allows programmers to write pre- and post-conditions as part of a function's signature:
double sqrt(double x) const
pre (x >= 0.0)
post (ret_value: ret_value >= 0.0);
Making contracts part of a function's signature serves as a kind of documentation for users of the function about what the function expects. Additionally, it makes the information available to compilers and formal verification tools to use when interpreting a C++ program, in a way that is more convenient than traditional assertions.
Pre-conditions can refer to the arguments passed to a function, or to class members when specified on a destructor or normal method. Post-conditions can give a name to the function's return value to use when writing the condition, and can access class members when specified on a constructor or normal method. The conditions are guaranteed to be checked, but that check can occur at compile time if the compiler is able to prove that it is always true or false, so relying on side effects that occur inside a condition (such as increments to a variable) is unwise. Calling non-const member functions from a predicate is not permitted, although it is possible to mutate a member of an object through a pointer from inside a predicate.
In classic C++ fashion, the choice of what to do when a function's pre- or post-conditions are violated is left up to the implementation, although the C++26 draft specification [large PDF] suggests that implementations should allow the user to configure the behavior. Clang and GCC use the -fcontract-evaluation-semantic flag to choose the behavior, both during compile time (in const contexts) and at run time. There are four options: ignore (which does nothing), observe (which emits a warning in const contexts and calls a handler if a violation occurs at run time), enforce (which causes a compilation error in const contexts, and stops the program at run time), and quick-enforce (which is like enforce, but skips calling a user-defined handler before the program exits).
Disagreements
The basic concept of having pre- and post-conditions for functions is generally popular. The disagreements, both within Working Group 21 and ISO as a whole, come from the details of how those conditions are evaluated and enforced. Contracts were initially proposed in 2004; that proposal was substantially reworked, tested, and argued over until 2018, when a revised design was proposed for inclusion in C++20. In 2019, the working group backtracked, removing contracts from C++20 in order to allow for more discussion of the design.
Over the next several years, two different designs for contracts were developed. The one that was eventually included in the draft of C++26 and an alternate proposal that would eliminate the observe and ignore settings for contracts. The main disagreement between proponents of the two proposals was about how much programmers should be able to rely on the assertions given by a contract. For example, a programmer might reasonably expect this code to reliably fail if either of the nested pointers is null:
int ddref(int** p)
pre(p)
pre(*p)
{ return **p; }
But that code is not correct. Pre-conditions are not guaranteed to run in order, or, in a compilation unit set to ignore contract errors, to run at all. The correct way to write the code is:
int ddref(int** p)
pre(p && *p)
{
if (!p) throw std::logic_error("pre-condition failed");
if (!*p) throw std::logic_error("pre-condition failed");
return **p;
}
This is verbose, and introduces extra opportunities for error, so some people would like to have a guarantee that pre-conditions are always run and checked. There is also the secondary problem of C++'s one-definition rule, which requires that, when a program is linked, only one definition of a function is used across the whole program. If translation units are compiled with different contract enforcement settings, this can result in the linker silently discarding contract checks from a translation unit that was compiled with them enabled. This is one reason why compiler settings should generally be the same across an entire project, but it is still a surprising corner case of contracts' behavior that could be mitigated by specifying their semantics less flexibly.
Another recurring point of disagreement is the handling of side effects within a pre- or post-condition. As proposed, contracts would allow the compiler to elide any pre- or post-conditions that it could prove would never trigger, or to evaluate the conditions multiple times. Normally, a programmer would write a simple boolean check in a condition, but there is nothing preventing them from writing something like:
int foo(int x)
pre(std::cout << "Hello, World!" << std::endl, x != 4)
{ ... }
A
2024 proposal advocated that pre- and post-conditions should be evaluated
exactly once, so that code like the above would have predictable behavior. That
proposal also introduced the idea of distinguishing benign side effects from
destructive side effects, as a possible further refinement of the rules for
contracts. That didn't go far enough for some members of the working group, with
John Spicer
asking for contracts to be "regular C++
", and not have their own
special-case behavior.
The authors of the contracts proposal that was adopted in the draft of C++26 grappled with the difficulty of ensuring that arbitrary C++ code is free from unwanted side effects, and ended up making variables const in the context of a pre- or post-condition. That is not sufficient to rule out side effects, but is a diagnostic that is efficiently implementable by compilers, and would eliminate the simplest mistakes:
int foo(int* x)
pre((x = 4)) // Not allowed: x is const
pre((*x = 4)) // Allowed; you can still write through it
{ ... }
(Readers unfamiliar with C++ syntax should note that the doubled parentheses are because C++ compilers will warn about an assignment being used as a boolean expression if the assignment is not wrapped in an additional layer of parentheses.)
That design did not make either side happy; both those who wanted to ensure that the predicates did not have unwanted side effects and those who wanted regular C++ conditions were left unsatisfied. There were other, less prominent points of contention as well. Many concerns, including the above, were enumerated in a document authored by a group including Bjarne Stroustrup, the original creator of C++. The authors of the proposed contract mechanism put together a point-by-point rebuttal explaining why each concern was unreasonable or not possible to address. They also put together a design rationale document explaining many of the tradeoffs and choices behind the design of contracts.
Resolution
Discussion continued through 2025 and early 2026. Eventually, enough people in the working group were convinced by the design that contracts were included in the draft of C++26. The vote at the March 2026 working group meeting on finalizing the draft with contracts included had 114 people in favor, 12 opposed, and three abstaining. Herb Sutter, who published a write-up of the meeting, said:
The unusually low number of abstentions shows that virtually all our experts now feel sure about their technical opinions, either for or against contracts. After extensive scrutiny, the committee's opinion is clear: The ISO C++ committee still wants contracts, and so contracts have stayed in C++26.
Despite that, several members of the working group felt strongly enough that contracts should not be included in the language that they wrote and signed a plea to ISO's national bodies to disapprove C++26. (A separate one-page summary was also published.) The plea noted that ISO working groups are not supposed to decide everything via vote: decisions are made via consensus, requiring the discussion of and reconciliation with conflicting points of view. Voting is used for a limited number of procedural matters, such as the final approval of a language draft. The authors of the plea believed that contracts had essentially been forced through over the objection of a substantial minority of working group members.
Other working-group participants
did not agree, naturally, saying: "These claims are not true.
" The
plea and its accompanying technical papers misrepresent the specification, its
intent, how it was tested, how it moved through the working group, and a number
of related facts, they said.
In October 2026, the C++26 draft specification went before the ISO's main voting group for approval. Whether because of the advocacy against the draft or their own individual misgivings, the ISO national bodies rejected the specification. ISO distinguishes between "participating members" and other members. A specification requires a two-thirds majority of participating members to approve, and no more than one quarter of all cast votes (including non-participating members) to disapprove. The draft specification failed on both counts, with only 12 of 20 participating members supporting the draft, and nine negative votes out of 22 total votes.
At this point, the working group has a few options: revise and ask for another vote immediately, revise and circulate that draft for comments, demote C++26 to a technical specification (a document describing best practices, without being an actual standard), or give up. It will likely decide which path to take at the next working group meeting, from November 16-21 in Búzios, Brazil. Sutter published a summary of what he sees as the underlying problem: how to deal with a situation where a language's creator and its steward body disagree. His paper lists some historical examples of how other languages have handled analogous situations, and some details on possible paths forward for C++.
Some working group members have already called for another vote, in the hopes that some of the ISO's participating members who abstained or disapproved in October will have changed their minds. Others have suggested that contracts should be removed from C++26 and the draft resubmitted, so that the other improvements to the language can be officially adopted. Given the long history of the feature, and the number of remaining disagreements over the basic vision of how it fits into the language, discussion at the Brazil meeting is sure to be spirited.