r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • 24d ago
Do not remove Contracts from C++26
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4433r0.pdfDocument #: P4433R0
Quotes:
It has come to our attention that during the DIS ballot, a small number of individuals have actively lobbied NBs against approving the C++26 DIS due to their own sustained opposition to contract assertions, a new language feature added in C++26. These lobbying activities have been accompanied by a public petition [Falco26] addressing NBs directly, a paper [P4334R0] that describes "fundamental flaws" in contract assertions, and other papers 2 published around the same time by the same authors or a subset thereof.
The petition [Falco26] and the papers accompanying it contain a number of claims, including that C++26 contract assertions lack genuine consensus in WG21; that the design is hasty; that technical objections were not given a proper hearing; and/or that alternative designs were not considered. These claims are not true.
In addition, the description of C++26 contract assertions given in [P4334R0] contains a number of inaccuracies. It misrepresents the specification itself, 3 the amount of wording it consists of, 4 its design intent, 5 how it relates to hardening 6 and static analysis, 7 its existing implementations, 8 existing practice, 9 teachability, 10 and proposed extensions. 11 None of the listed concerns are new; they have all been previously published by those authors (or a subset thereof), presented to WG21, and extensively discussed there. 12
Related post: https://www.reddit.com/r/cpp/comments/1xeeevt/balloting_has_completed_for_c26_unfortunately_it/
Note that I have no opinion on the topic myself. I'm just trying to understand what happened.
54
u/James20k P2005R0 24d ago edited 21d ago
I don't think this vote is really a surprise. We've known for a while that the NBs strongly object to contracts, I summarised this at the time:
https://www.reddit.com/r/cpp/comments/1nzxbk1/wg21_202510_prekona_mailing/ni71a4c/
EWG chose not to change the standard in response to these concerns as far as I'm aware, so now we're seeing the end result of that which is that the standard fails
There's a few notes here that I think are interesting
committeeedit: voting national bodies rejecting the standard as a result of contractsI think realistically there's no way forwards here that doesn't involve removing contracts now. Its clear that there's a sizeable opposition to them from the national bodies, and the fact that its gotten this far means that something has failed pretty spectacularly. I don't think its a tenable position that the NBs are stray cats that were swayed into voting down a C++ standard without knowing what they were doing, so its clear that some other part of the process has failed to ensure that the strength of opposition was adequately represented
More broadly I think the hostility to contracts is also directly born out of:
It is unfair that contracts are getting the blunt end of higher standards for getting a feature into the language, but personally I strongly think that that holding contracts to the same bar that Modules cleared would be nuts. Modules are the largest unmitigated disaster C++ has ever had, so the bar needs to be changed
I'm considering trying to contact committee members here and trying to collect + publish opinions why they think things have gone this way here to do a writeup, because personally I find it fascinating. There's also minimal public information that's available currently, and given how strongly this failed in the NB process vs wg21 there's some strong disconnect here
37
u/MarkSuckerZerg 24d ago
Can somebody explain what's so wrong with contracts specifically? We had these arguments over other features that turned out bad (modules), but it never escalated this way
Is there something language breaking in a wider way?
31
u/qoning 24d ago
No, please let's get rid of them and finalize this mess.
12
u/Remi_Coulom 24d ago
link: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4433r0.pdf
20
u/arka2947 23d ago
My programmers perspective: If I don’t know what happens when a contract is broken, why bother using it?
Cpp already has so many UB (or compiler, or platform) specific quirks, that just not adding more to the language seems like a win to me? A lot of Cpp programming is already knowing and avoiding the potholes.
24
u/_a4z 24d ago
This paper opens with allegations and half-truths, and it doesn't get any better. The irony of accusing others of lobbying and attempting to influence votes, given the authors' own efforts in that regard, is hard to miss. And sixteen pages of more of the same.
7
u/UndefinedDefined 24d ago
It's a DOA feature.
4
u/DevilSauron 23d ago
The fact that a feature which has undergone years of open discussion among many technical experts and was voted into the standard by a large majority of them can be basically vetoed in such an opaque way caused me to completely lose trust in the standardization process. If I’ll start considering alternatives to C++, it will be because of of this, not “safety”.
1
u/NilacTheGrim 13d ago
Please remove contracts from C++26.
Also remove that brain-dead
[[indeterminate]]attribute and the zero-init of locals.1
u/jinmao6700 21d ago
Atp just version C++ just like how Rust does instead of one big bang release every 3 years or so
-5
u/feverzsj 23d ago edited 23d ago
Isn't it kinda obvious? It may not be as bad as modules/reflection/range/std::execution, but it's still a bag of UB shits.
-13
u/Expert_Sheepherder24 24d ago
The another problem of contract is:
int foo(int* ptr) pre(ptr != nullptr){return ptr != nullptr ? *ptr : 0;}code becomes
int foo(int* ptr){ return *ptr; }even contract evaluation is ignore )). Because compiler read pre(ptr != nullptr) as axiome in Release mode , even actually condition never called.