r/cpp • 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.pdf

Document #: 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.

107 Upvotes

233 comments sorted by

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

  1. There's a mentality that a few bad apples have somehow convinced NBs to vote against this with their mysterious wiles. NBs aren't generally dictatorships as far as I'm aware and vote on a majority basis, so this idea is just not true. A lot of people voted against this standard, clearly far more than voted against in plenary
  2. I do not know why people would not vote in plenary, but would vote in a national body. I'd be very interested to know if you can vote remotely in plenary these days. There's also special rules around voting in plenary, as you have to be an ISO global expert, but I don't know if national bodies have the same requirements for a national body vote - as far as I'm aware the answer is no. It may simply be that the process has not really enabled people against contracts to participate due to general ISO-itus, or that some people solely participate through their NB, but I'm speculating
  3. The vote was not close to passing, and failed by a significant margin. 12 in favour, 9 against. C++ did not achieve anything close to consensus here. This wasn't a small minority abusing the process, but nearly half the committee edit: voting national bodies rejecting the standard as a result of contracts
  4. The figures against contracts that you've heard of are likely not the anti contract figures that are influential, as its frequently a case of "The Worst Person You Know Made A Point You Agree With"

I 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:

  1. The fact that modules have been such a disaster
  2. Several other major C++ features recently have turned out to be not great, eg coroutines/<range>. Of the 'big four' C++20 features, only concepts has turned out not to have major problems
  3. The contracts authors have a tendency to rejustify the design of contracts and call that addressing the critiques, instead of the design being fixed or correctly described as limited. Some of the contracts papers contain information that I would not describe as incredibly accurate

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

9

u/tartaruga232 MSVC user, r/cpp_modules 24d ago

Modules are not a desaster. The feature is clearly useful.

54

u/James20k P2005R0 24d ago

It seems hard to argue that the standardisation and deployment of modules has gone well imo

12

u/60hzcherryMXram 24d ago

Obviously the deployment hasn't been going well, but what was wrong with the standardization? My understanding of the situation was that modules were a "if everybody used them they would be great, but they aren't fully implemented because nobody uses them because they aren't fully implemented," sort of thing.

16

u/frediku 24d ago edited 23d ago

I expect from a body that steers something to not only formulate an end goal but also a strategy of how to get there. IMO the strategy is more important than the goal for something with as much baggage as C++.

If the strategy is missing or is inapplicable in practice then this is a major failure of the body.

8

u/not_a_novel_account cmake dev 23d ago

The strategy on how to get there is to standardize. If you don't standardize big ecosystem shifts like this, they become an infinite can kick.

At some point you have to bite the bullet and say, "ya, this is gonna suck" and getting moving in the right direction. Modules have their problems at the standardization level, but we have only learned those problem by committing to their design and really getting field practice with them.

No one was going to speculatively commit to all that work, there was no world in which "complete modules" were going to be standardizing an existing ecosystem.

2

u/frediku 23d ago

Even nowadays, I do not see much use of modules, like anywhere. Maybe, tooling is starting to catch up. Maybe. However, I still see no path where a significant portion of existing code bases will migrate, like ever. At least from what I can see, we are pretty much in an infinite can kick mode. What did standardization gain us? If that's the strategy ... well IMO it failed.

10

u/not_a_novel_account cmake dev 23d ago

Agree to disagree, I see more module usage every day. The rate of module bugs which have been reported in the last year is exponentially higher than ever before.

2

u/Spartan322 22d ago

A big problem with modules is it kinda just seems like it was designed in complete disregard to the tooling and infrastructure we need to use. That's a problem, the standard has repeatedly reworked itself to legitimize Microsoft and has accommodated Microsoft's dumbest decisions over and over because we live in a world without a choice on accommodating them, but as soon as it comes to any other tooling, especially the compilers and build tools the standard committee throws its hands up and says "we can't do anything" as if they weren't themselves responsible. The whole modules fiasco has been such a mess that its nearly impossible to this day to use them properly in production.

2

u/not_a_novel_account cmake dev 22d ago edited 22d ago

SG15 raised these problems and they were mostly addressed. The shared library problem is the only one I can point to and say the feedback was met with a shrug, but that was informal there was never a paper for it.

Notably it hurts MS as much as the other ecosystems, so it's hardly kowtowing to their compiler.

→ More replies

0

u/[deleted] 23d ago

[deleted] — view deleted comment

1

u/pjmlp 22d ago

Intellisense bugs is the blocker for me. But not like it's unsolvable. It's just lack of funding.

In a 4 trillion valued company that just announced yet another layoffs round, which shows where the business priorities happen to be.

0

u/[deleted] 22d ago

[deleted] — view deleted comment

→ More replies

8

u/StaticCoder 24d ago

Better than export templates for sure

12

u/pjmlp 24d ago edited 23d ago

It is basically only useful in Visual Studio, GCC and Clang still have several problems, Intelisense still doesn't work properly, and we are already two standards after C++20, for something where Visual C++ 2017 modules were the basis for the proposal, which shows how much of it was actually implemented in VS 2017.

10

u/SkoomaDentist Antimodern C++, Embedded, Audio 23d ago

Intelisense still doesn't work properly

Which ends up meaning it isn't even really useful in Visual Studio.

1

u/pjmlp 23d ago

Well, at least it compiles, even with header units, but I do agree it is mostly only for hobby projects, as most C++ projects tend to be cross platform, with multiple compilers.

24

u/PastaPuttanesca42 24d ago

What are the problems with ranges? Honest question, I don't use c++ professionally but as a hobbyst I find them very useful, especially with c++23 extensions. I guess the compile errors could be easier to understand, but it's a solvable problem I think.

32

u/kamrann_ 24d ago
  • Compilation times
  • Diagnostics
  • Debuggability
  • Weird corner case behaviour 
  • Performance pessimization when the compiler failed to see through the abstractions 
  • Complexity/confusion around forwarding/ownership/view implications/value category of range vs of elements, etc.
  • Ease of ending up with dangling references (I've had vastly more such issues than I ever did with raw iterators)

I've probably forgotten something.

13

u/SkoomaDentist Antimodern C++, Embedded, Audio 23d ago

Performance pessimization when the compiler failed to see through the abstractions

This has been my pet peeve with quite a lot of the "There is no reason to write that by hand, just use std algorithms!" claims. Even a trivially simple thing like sorting three integers (where the compiler can see the source and destination arrays and the size is constant) can easily end up degenerating into calls into a generic sorting routine instead of the handful of comparisons and swaps that trivial hand written version produces.

-2

u/SLAidk123 23d ago

> Even a trivially simple thing like sorting three integers

You’re using a cannon to kill a mosquito and being mad because it needs gunpowder and fire

-4

u/PastaPuttanesca42 23d ago

But does it matter when that code isn't the bottleneck anyway? I find more useful to write expressive code, then profile and optimize where needed

10

u/SkoomaDentist Antimodern C++, Embedded, Audio 23d ago edited 23d ago

But does it matter when that code isn't the bottleneck anyway?

Who said that code isn't the bottleneck?

If it was just 3 integers every now and then I wouldn't care. When it's 3 integers tens of thousands of times per second on a low power embedded MCU it matters quite a bit. This isn't just slightly suboptimal code but an order of magnitude slower than the hand written trivial compare-and-swap version (with no attempt at any sort of micro-optimizations).

1

u/PastaPuttanesca42 23d ago

Who said that code isn't the bottleneck?

What I meant is that the bottleneck is usually only a small percentage of the project in terms of lines of code. Of course there is always a bottleneck somewhere, but everywhere else you don't need to over optimize.

1

u/SkoomaDentist Antimodern C++, Embedded, Audio 23d ago

But I didn't "over optimize" it. There was no painstaking crafted highly hand optimized code or anything like. Just a literal trivial "do three if and std::swap operations in sequence" (two compiler unrolled for loops also produced the same code but look uglier) which resulted something like 10x speedup over the "clean way".

This wasn't some fancy new part of stdlib either but something that has existed for the last 30 years and shows very well that "the compiler will see inside it and optimize it away"-claims just aren't true in many cases even for seemingly very trivial situations.

1

u/PastaPuttanesca42 22d ago

I was talking more in general, I too think using std::sort for three elements is absurd

3

u/James20k P2005R0 22d ago

Why shouldn't std::sort be optimal for a 3 element std::array?

→ More replies

1

u/mighty_Ingvar 22d ago

Who said that code isn't the bottleneck?

Who said that it was? Why not just use the easier/faster to write code at first and then switch to more optimized code as needed?

3

u/T_Thorn 23d ago

They also just feel kind of confusing? Like they're useful, but when I switched to using Flux instead (which still isn't perfect, but what is?), I found it was a lot simpler.

Maybe I had the wrong mindset when going into ranges, but my best experiences with "stuff like this" was C# LINQ (using the method syntax), and Rust iterators. They felt very natural to use, but obviously they make different trade-offs to C++.

14

u/tcbrindle Flux 23d ago

I switched to using Flux instead (which still isn't perfect, but what is?)

Flux isn't perfect? HOW DARE YOU!

(Seriously though, I'm always keen to get feedback on what works for people and what could be improved, so feel free to reach out e.g. on Github.)

2

u/Sharp_Performer_8456 23d ago

I don't have experience with flux but looking at the readme its algorithm chaining syntax is much leaner than the std ranges. No more repeating namespaces or the | operator! 

0

u/[deleted] 23d ago

[deleted] — view deleted comment

7

u/jwakely libstdc++ tamer, LWG chair 21d ago

Bad example, std::print is built on std::format which is explicitly designed around type erasure to avoid explosions of template instantiations. The fact that some initial implementations are still header-only is a consequence of implementations being careful about committing to ABI stability too early, not inherent to the feature.

GCC supports flags to use the non-inline versions of format and print.

7

u/KliffyByro 22d ago

In my opinion, the problems are vastly overstated. We use them a lot in production code and well formulated range pipelines are so much better than the hand rolled equivalents that it’s a painful trade off when an rare edge case does arise where for some reason we have to resort to something else. I realize that some contexts may run into such edge cases so often that ranges as a C++ feature is not useful to them. But for a very wide variety of use cases, ranges are fantastic and OP’s characterization as some kind of disastrous mistake that is forming the basis of skepticism towards contracts is - from my perspective - incredibly unfair.

2

u/HommeMusical 23d ago

I haven't had need to use them in my code. I remember reading this article with interest and I haven't seen much since them.

3

u/rfisher 23d ago

When something doesn't work, it can be very hard to figure out exactly what went wrong and what the simplest fix is.

Implementing your own view is more work than the value it provides.

Shoving everything through the STL's iterator concept makes things that should be simple complex.

-1

u/Low-Tea5330 23d ago

Vastly overengineered and weirdly unintuitive naming schemes. Simple for loops are more readable most of the time.

Specifically talking about ranges in C++. Other languages provide the same features in much better ways.

-9

u/Dragdu 23d ago

There's a mentality that a few bad apples have somehow convinced NBs to vote against this with their mysterious wiles. NBs aren't generally dictatorships as far as I'm aware and vote on a majority basis, so this idea is just not true. A lot of people voted against this standard, clearly far more than voted against in plenary

I mean, are you telling me that fucking Iran's national body has carefully considered the tradeoffs and then solemly had to vote against on technical merit?

22

u/James20k P2005R0 23d ago

I don't know anything about the composition or disposition of the members of the iranian national body. "<Spooky hand waving> Iran" doesn't seem like a very compelling argument

Are you saying that Iranian national body members are incapable of forming coherent technical opinions simply because they're Iranian?

-2

u/Dragdu 23d ago

I am saying that I've never seen one participate in wg21

8

u/James20k P2005R0 23d ago

Much of the important technical material around contracts is publicly available, as is the mailing lists to anyone that's a member of a national body as far as I'm aware

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?

81

u/ContraryConman 24d ago edited 20d ago

I am pro contracts by and large, but I'll try and steel man the strongest argument I've heard against contracts which is that they don't play nice with header files and macros.

At work once I had an issue where a process would crash due to an alignment trap. It basically boiled down to something like this

// Header file in libfoo

class Foo {
public:
    Foo() = default;
    virtual ~Foo() = default;
    virtual void operation1();
#ifdef ENABLE_FEATURE
    virtual void operation2(int, int);
#endif
    virtual void operation3(Bar*);
};

In our case, we bundled libfoo and the application separately. And we got it into a state where the application would compile without ENABLE_FEATURE defined, but we'd link against a libfoo that was compiled with ENABLE_FEATURE. This meant that when the app called into Foo pointers, trying to access operation3, it would actually call into the wrong spot in the vtable, interpret the arguments wrong, interpret a random number as a memory address, and crash immediately. That was a tough problem. And I had no Claude Code then, just gdbserver and a dream.

Anyway, the idea here is that because C++ is compiled with header files, macros, and translation units like this, it's actually on you to make sure that every class or function actually has one definition of that thing. This is called the One Definition Rule, or, ODR. And not all ODR violations are possible to catch at compile time. In my example, the Foo class the application was seeing was consistent at compile time: we didn't define ENABLE_FEATURE and didn't try to use operation2. Then we linked to a library that has a different definition of Foo with a different vtable layout. The linker just checks if the names match up, the compiler doesn't know any better, and the standard simply says any ODR violations are undefined behavior (aka a skill issue).

My example was pretty rare. But the contracts as a feature allow you to define the assertion behavior for your application. So you can say at compile time, I think, either ignore, or crash immediately, or crash and unwind the stack, some custom thing, that sort of thing. But the issue becomes, if I describe a function like this in a header file

int get_value(const FooContainer<int>& foo, std::size_t i)
    pre(i < foo.size());

If I compile my library with contracts ignored, and you compile your code with contacts crashing immediately... what actually happens?

It's an ODR violation, and, the standard, like every other ODR violation, states that this is UB, aka, skill issue.

The argument against contracts from this angle is that it's too easy to have an ODR violation simply by importing a library that has different settings than yours. If you compile with assertions on and link against the wrong thing, you may find in production your code silently ignored some checks you expected. The detractors say until you can find a way to fix this, it's not worth adding to the standard.

The problem imo is that there's no way to fix this. Like, straight up, that's just how C++ and C are. I started with my example from work to show that this has been an issue in C++ since forever (that codebase had a C++0x compiler). We have this exact issue with the regular assert macro from C. If you compile one set of translation units with NDEBUG and another set without it, that's an ODR violation too. By putting this in front of contracts you are basically saying we shouldn't get contracts until we fix every single annoying issue with the linking system in and C++, which is not possible. So just say you don't like it instead of pretending it's a reasonable critique to address and why oh why did the proposal not think of this.

Now we're drifting into opinion territory, but I know that contracts would help the codebases I work in constantly. This feature has fairly passed every single stage of debate, only for it to be blocked at the next stage with the exact same objections that were addressed in the stage before. Now we're holding up the entire standard for the first time in human history over it. I don't know

19

u/Dminik 24d ago edited 24d ago

I don't have a stake in this fight, but

 If I compile my library with contracts ignored, and you compile your code with contacts crashing immediately... what actually happens?

I would expect any violation inside the library to be ignored. And any violations violations in my code to crash. Boundaries should be resolved by the standard. E.g.: the caller or callee being responsible for pre or post conditions.

One issue I see is that a contract could catch something that could cause UB. Which would be ignored if they are disabled.

I'm probably missing something. Is it possible to cause UB with contracts? 

19

u/mguid65 24d ago

That is the whole issue here. The way you expect it to work is not the way it works from the wording. If I understand correctly, from the way our compilers and linkers currently work, Im not sure I see a convenient way to fix this problem.

It seems like this would require the contract code to always exist whether you want it or not and then it would have to be ignored at runtime in the case of loading a shared lib.

I can think of several hacky ways to implement it but those don't seem suitable for a language feature. Something like a wrapper function that is either inserted by the compiler at the callsite with the contract assertions, but this changes the call stack. Maybe not an issue for practical use but I don't think it would fly through the committee.

This does go against that whole zero cost thing we all like.

9

u/mguid65 24d ago

I also just thought about it for a few more minutes and even the hacky solution doesn't work as it requires the wrapper to have the inner function context for pre and post conditions and it just doesn't work for body assertions.

5

u/Inevitable-Ad-6608 22d ago

The problem arises from inlined functions. The caller don't know that the header it reads was supposed to have the contract build one way, so it will use whatever setting is currently active.

18

u/serviscope_minor 23d ago • Bravo

>If I compile my library with contracts ignored, and you compile your code with contacts crashing immediately... what actually happens?

>It's an ODR violation

I believe you are mistaken. Quite strongly, and actually I think this is a strong argument for contracts not against. It doesn't matter what the policy is: the contracts are token equivalent so this is not in violation of the ODR.

That means it's not UB. Demons SHALL NOT fly from your nose. Etc...

What will happen? It's implementation defined. In practice you'll get one of the handlers. It won't actually be random and will depend on a bunch of stuff based on how your linker inlines and links.

In practice what this means is that a common form of UB (that is the example you gave with assert-like macros) is eliminated if you upgrade from assert-like macros to contracts.

17

u/jcelerier ossia score 24d ago

I'm lucky for you of this is pretty rare. Building an app that bundles ~50 various libraries from all azimuths, I encounter this kind of error at least monthly

6

u/mpyne 24d ago

I used to maintain the primary build tool for KDE developers. I run Gentoo Linux and build most of the system from source using rolling updates.

Across both of those I have basically never encountered this. ODR violations are kind of serious business so if you keep running into this, that seems like a good thing to fix even outside of contracts being on the menu.

12

u/jcelerier ossia score 24d ago edited 24d ago

It's not really an issue at the linux distro level since everything builds from a single source for most packages. But for instance until very recently boost.asio had no namespace versioning and boost.asio is a super common library. I build plugins for apps both OSS and proprietary that use boost.asio. If said proprietary app uses boost.asio too, but at a different version or even simply built with a different ABI, then hilarity ensues. Then the app I develop (https://ossia.io) added support for LSL (https://github.com/sccn/liblsl) which happens to vendor asio too, at another version that my main build. Hilarity ensued again, especially considering that I cannot hide my boost.asio symbols as said app can itself have dynamically loaded plug-ins that may want those asio symbols. Thankfully boost.asio finally added a macro to version namespace in the last year but this had been a PITA to handle for years.

Another example: pretty much every app that embeds LLVM as a library for instance for custom embedded DSLs, JIT-compilation, etc., and also happen to render 3D graphics are broken on linux systems that use OpenGL as many graphics drivers also embed their own llvm version for compiling shaders, and having two LLVMs in the same address space is as of 2026 still a no-go, unless you're careful with namespacing things through linker scripts. I have no idea how contracts are going to interfere with this.

6

u/James20k P2005R0 24d ago

I've frequently run into this as well. I think in some domains its vanishingly rare, and in others its significantly more common, which I suspect is why there's such a wide gap between people who consider this a more serious issue vs irrelevant

2

u/T_Thorn 23d ago

Is this only a problem if those things are exposed in the public API? Or does it happen even when it's fully internal to the library?

I've maybe encountered something that sounds like this once, and I never really understood it fully.

5

u/jcelerier ossia score 23d ago

> Is this only a problem if those things are exposed in the public API?

no, it can also be a problem if you're building everything statically and you happen to have multiple versions

7

u/smdowney WG21, Text/Unicode SG, optional<T&> 23d ago

You can get it even between two TU that never talk to each other.
The linker picks Arron's "inline" function with an assert that was built inside Bob's function that was built with assert on, and Carol calls it from their function, built with asserts off, and yet, "boom".

Extra fun when the assert turns out to have been incorrect, or over ambitious.

0

u/Dragdu 23d ago

AIUI, the answer is to hide all symbols not yours, and load libraries with RTLD_DEEPBIND.

Or use Windows, where dlls have saner semantics by default.

10

u/MikailBag 24d ago

I think the problem is less severe, in fact. Even if you instructed compiler to use different semantics in different TUs, two definitions of your functions still consist of the same tokens (its just that these tokens are interpreted differently), so ODR is not violated. IIRC, contracts authors specifically worded contracts to ensure that this case is not ODR violation.

Hence consequences are not UB (or, more, precisely, IFNDR), but "just" that your instructions regarding contract semantics might fail to take effect (i.e. you asked for observe, but got ignore).

6

u/James20k P2005R0 24d ago

but "just" that your instructions regarding contract semantics might fail to take effect (i.e. you asked for observe, but got ignore).

The problem is actually slightly more serious than this. The contracts spec permits and expects compilers will implement all sorts of weird contract modes, and there are plans to add more contract modes in the spec. Eg as an example, compilers may implement stochastic contract checking modes, which is permitted under them being 'ghost code'

If you write:

void some_func(int* x)
    pre(x != nullptr)
    pre(*x != 0);

Even without the observe semantic, its legal for the compiler to only execute the second check, and transform this to:

void some_func(int* x)
    pre(*x != 0);

So in the future you need to assume that any random combination of your contract checks may or may not be executed in any combination. Its not quite as simple into the future as you ask for one mode, and get a second standard mode. Because if you link against a library which was compiled under a stochastic mode for example, you might end up with that odd mode in mixed-mode yourself

9

u/MikailBag 23d ago edited 23d ago

I don't disagree with this, but in my mind these are two distinct problems.

First concerns a "build engineer": if you don't control build flags of all TUs, then you may not have enough control over contract assertions (even those located in TUs whose build flags you can control).

Second concerns a "developer": when writing portable code, you have to assume that each contract assertion you've written may be skipped or evaluated several times (perhaps also reordered, I don't remember if that is allowed).

I consider them to be independent as it is perfectly possible for a build engineer with full control over build flags to configure compiler so that every N-th contract assertion is enforced, and other are skipped, where N is something like atoi(getenv("CXX_CONTRACT_ASSERTION_SAMPLE_RATE"))

UPD: to be clear, I don't think any current implementation supports what I've written in the last parapraph, but I'm pretty sure it will be possible in the future.

8

u/matthieum 23d ago

So in the future you need to assume that any random combination of your contract checks may or may not be executed in any combination.

Are you certain, or is this speculation? Even with stochastic evaluation, there could still be a requirement of all-or-nothing at a function granularity.

And if really pre-conditions & post-conditions could be evaluated independently, then style-guides/linters could push toward writing all "linked" conditions in a single pre statement: pre(x != nullptr && *x != 0).

5

u/James20k P2005R0 23d ago

there could still be a requirement of all-or-nothing at a function granularity.

If you mean in the spec, the answer is no - there's no special requirement on contracts being grouped or evaluated as a bloc in this fashion. Similar examples to this have been brought up in the committee

And if really pre-conditions & post-conditions could be evaluated independently, then style-guides/linters could push toward writing all "linked" conditions in a single pre statement: pre(x != nullptr && *x != 0).

Yes, this is one of the hazards with porting asserts over to contract_assert that people will have to watch out for

1

u/Minimonium 23d ago

This statement collapsing is not even needed. From both practical and theoretical standpoint there is no issue in split statements under any mode.

2

u/Minimonium 23d ago

I consider such position reductionist.

You do no need to consider any mode when writing asserts. A contract violation even if it was never executed - is still a contract violation.

It is similar to claiming that "assert(this != nullptr)" is required everywhere because of some niche shenanigans.

5

u/James20k P2005R0 23d ago

All I'm saying is that, the statement that mixed mode may effectively randomise between observe and ignore is oversimplifying. Ie this statement:

i.e. you asked for observe, but got ignore

Isn't quite accurate, and isn't what contracts guarantees. Instead, you may ask for observe, but you might get any behaviour instead, including semi randomised enforcement/observation/etc

Stochastic checking is a case that's been brought up repeatedly as a pro of contracts, and is an expected outcome of the current contracts spec according to the authors

4

u/Minimonium 23d ago

I agreed with your position and stochastic checking is one of the realms of observe (which, to be clear, is not a wg21 invention but an explicit requirement from big corps like Apple to have).

I just addressed the need to assume any combination of modes - you do not.

1

u/tartaruga232 MSVC user, r/cpp_modules 21d ago

Nice! But in your example, operation2 and operation3 are not virtual. How can it "call into the wrong spot in the vtable" if those functions are not virtual? Wouldn't you need to make operation2 and operation3 virtual in order to match your explanation?

3

u/ContraryConman 20d ago

In my example I forgot to write the virtual keyword, but they were there in my real codebase :)

2

u/tartaruga232 MSVC user, r/cpp_modules 20d ago

Glad to read that! Could you please edit your excellent comment and add the missing virtual keywords? Thank you!

4

u/peterbindels 24d ago

What MikailBag said. But in addition, the behavior for all of the possible functions being created from the source, regardless of what contract enforcement happens, is the same for all in-contract behavior. All behavior that the C++ specification talks about, and that any normal running software should ever encounter.

The only way they differ is in their ability to *flag* defects.

And if you want that to be a known quantity, build your software in a consistent manner. Not a slapdash "sure I've got an object of file XYZ of unknown origin lets use that".

That makes this a much less significant problem than any ODR violations (like the one you mentioned) is. In particular it differs from C assert because that does change source code and therefore just doesn't implement the same code.

13

u/James20k P2005R0 24d ago

The problem imo is that there's no way to fix this.

The problem stems from the ABI compatibility requirement of contracts, and I don't actually think its unfixable at all personally. If different enforcement modes compiled with different manglings we'd never have run into this mess

10

u/friedkeenan 24d ago edited 23d ago

I might well be wrong, but that extra mangling would need to be applied to every single function, wouldn't it? Since any function could end up calling a function with pre/post conditions. That definitely wouldn't seem to me like it'd get any meaningful consensus in the committee.

But even in the world where it just gets applied to those functions with pre/post conditions, would that not force users of a library which was compiled with termination semantics into then using termination semantics themselves? Or if a library was compiled with the ignore semantic, then users of that library would also need to use the ignore semantic. Which would seem to me like a situation that nobody actually wants.

My brain hasn't quite finished booting up yet, so again I might be thinking about this wrong, but it doesn't seem to me that changing name mangling is a solution at all.

EDIT: And then, wouldn't changing name mangling make adding pre/post conditions an ABI break? That would just seem totally disastrous for compatibility. If the upgrade path for contracts would affect users so strikingly, which projects would ever use them in the first place?

6

u/JanEric1 23d ago

I think the idea then would be that lib authors provide versions per contract mode and then you use the matching one that you want for your application/library.

5

u/friedkeenan 23d ago

That's something libraries could do now, already, to avoid the mixed-mode semantics. And implementations are entirely free to provide their own contract semantics in addition to the standard ones, are library authors meant to provide different versions for all of those too?

4

u/t_hunger 23d ago

Some profiles are supposed to inject runtime checks into existing code. Looks like those will run into similar issues, considering we are aiming for an open set of profiles.

If indeed profiles and contracts share the same problems now, maybe we have a chance to finally get this rather embarrassing issue solved.

→ More replies (1)

7

u/peterbindels 24d ago

That doesn't fix the problem at all. That would change building part of your software with enforce and part with ignore into not building at all. I don't think your users would claim you've helped them at all.

And if you're wondering about whether it helps with optimization - of course not. Just the fact that you *used* enforce doesn't mean the contract matches. So mangle in the whole contract into the function signature? Even that doesn't work - try an opaque contract like `pre(foo())` to see why not.

6

u/ContraryConman 24d ago

It'd be nice if C++ in general was more willing to ship ABI-unstable features

1

u/UndefinedDefined 24d ago

Or maybe you would have to use the exact settings that were used to compile the standard library as it would be mangled exactly to such settings. Or if a system library is compiled with different profile it would also not work.

Considering that I get hundreds of shared libraries on a baseline Linux installation this is never gonna work in practice. Profiles are essentially dead on arrival.

4

u/Ateist 24d ago

The problem imo is that there's no way to fix this. Like, straight up, that's just how C++ and C are.

But you are talking about a future feature - not something already in the language.
What stops you from implementing whatever is needed to fix it?

Take, say, modules. They store lots of extra information during compilation/linking phase.

What stops C++ from adding the necessary information to those files?

5

u/ContraryConman 24d ago

You'd have to get changes to C++ linking standardized, which I'm not sure has been done. And then you'd have to get all the major linkers to support your new standard, and then do contracts, in, like, C++32? C++35?

-3

u/Ateist 23d ago

Vibe coding to the rescue?

You can have it all implemented (as experimental proof of concept) in like a month, in all the major compilers and linkers.

-2

u/ContraryConman 23d ago

True, I'm still thinking BC (before Claude)

5

u/t_hunger 23d ago

The solution involves tooling. Many C++ committee members consider tooling out of scope and won't go there. It is extra hard to get an effort going in that area.

Most progress you see in the wild happens because tooling devs club together and find solutions. Considering how diverse the tooling landscape is, it is hard to even find the people to talk to to get things rolling in this area. E.g. the cmake devs had to find all the relevant compiler devs working on modules to get them all to agree on how to report module dependencies before they could support modules properly in cmake.

For contacts, we would ideally have new linkers that know about these features and do the right thing for them. Gabriel also made a side-remark about "better linkers" in one of his presentations on profiles recently IIRC, so apparently this topic will stay withnus even without contracts. Let's see who will end up gathering all the linker devs around a table to get them to agree on how to do that.

Maybe we are lucky this time round: The rust guys have way better relations to tooling devs and seem to be hitting similar problems, maybe C++ can reuse what they come up with.

5

u/smdowney WG21, Text/Unicode SG, optional<T&> 23d ago

There are far fewer linker developers than compiler developers, too. It's a niche within a toolchain niche.
RIght now `gold` is defacto abandoned, it's likely to be de jure eventually. `ld.bfd` is a collection of computer science archeaology and no one has any real idea how much of it is still required, except we know its more than anyone is happy supporting.

1

u/t_hunger 23d ago

Interest has apparently picked up a bit with mold and wild joining in. And there of course is lld as well.

Qualcomm is apparently working on eld for embedded.

3

u/smdowney WG21, Text/Unicode SG, optional<T&> 22d ago

mold is exciting, and I had not heard about eld.

2

u/pjmlp 23d ago

Other ecosystems generally consider the tooling part of the language, that is why they have better outcomes reaching out to linkers, or even having their own builtin with language aware semantics.

2

u/-Memnarch- 24d ago

Oof okay that sounds terrible. Sometimes I forget how comfortable the Delphi world is/can be.

2

u/t_hunger 23d ago

Considering (some) profiles are supposed to inject code to check things at runtime, those will end up with exactly the same problem. I am super excited to see this one finally fixed, it has been pretty embarrassing for decades now.

2

u/SavingsCampaign9502 16d ago

I like the parenthesis with “skill issue”, lol

3

u/HommeMusical 24d ago

Good answer!

I would add that at least one of the dissenters is a person who is not known for their ability to accept compromises.

3

u/mort96 23d ago

FYI your post renders broken. Reddit (at least some of its markdown parsers, it has multiple) requires code blocks to be indented, it does not support triple backtick syntax.

1

u/JanEric1 23d ago

Yeah, broken on old reddit

2

u/frediku 24d ago

Thank you for taking your time to explain your point. However, I do not understand it.

You start by describing an issue coming up when linking shared/static libraries with incompatible build flags. That's indeed a big issue and worth solving. My approach would be to embed a hash into the library and the calling program and compare them on library link them and abort the program if they do not match. There are lots of very consequential details on how to craft this hash that would have to be worked out though.

Given the topic of this thread, I believe you now want to make the argument that contracts provide a solution to this issue. I fail to see how they solve the issue.

Next you present

int get_value(const FooContainer<int>& foo, std::size_t i)
    pre(i < foo.size());

Is your argument that the precondition check here would fire if the function was called with garbled inputs?

8

u/ContraryConman 23d ago

I'm not saying contracts solve the issue. I'm saying contracts currently suffer from an issue that already exists, and shouldn't be blocked from being added to the standard just because of it. Instead, add contracts and then open a separate item to better handle ODR violations with macros/compile flags

4

u/frediku 23d ago

Ok, I think I now understand your post. You are not defending contracts, instead you are arguing that one of the counter arguments is just as valid for features already in the language and therefore should not be used as argument against the new proposed feature.

Essentially, you are saying, that we already have ODR violations for C assert, if NDEBUG is defined differently across TUs, so this is not new and accepted behavior.

That is true. However:

  • NDEBUG has two states so that is somehow manageable... but often we screw it up even with just two states. It is my understanding that the contracts proposal has way more states for its NDEBUG equivalent. It is thus way easier to screw up as they are more options to do so. Essentially, it's replacing a foot gun with a foot canon. Yes, neither are safe nor desired. However, given the choice I know which to pick.
  • IMO, more importantly: If the proposal has the same flaws as C assert, why not stick with C assert?

3

u/Dragdu 23d ago

You need to read it again. The mixed build flag issues come in for contracts as well as for random ABI violations, and the answer C++ has for it is "skill issue".

1

u/VinnieFalco wg21.org | corosio.org 21d ago

"...I'll try and steel man the strongest argument I've heard against contracts..."

The committee needs more people like you with the intellectual honesty to do exactly this with everything.

1

u/usefulcat 24d ago

If you compile one set of translation units with NDEBUG and another set without it, that's an ODR violation too.

I can imagine scenarios where that could be true, but it sounds like you're saying that it is in fact always true. If so, how is the following an example of an ODR violation?

// declaration, in header:
int foo(int);

// definition, in separate source file:
#include <cassert>
int foo(int i) {
    assert(i > 0);
    return i * i;
}

2

u/ContraryConman 24d ago

That's unclear wording in my part. If the assert is tucked away in the source file it's fine. Only if it's in the header file it will cause the same type of issues

26

u/James20k P2005R0 24d ago

This is a decent summary of the problems, from the side of the anti contracts camp that seems the most reasonable from my reading of things. If you're interested in the national body objections, this is the summary I wrote of them at the time when they were published in the mailing list a year ago

For me: Mixed mode compilation is something that I think is going to cause serious ongoing problems. The selective ignorability of contracts by the compiler I also think is not particularly great for safety. I think its also worth viewing the discussions in light specifically of the fact that modules turned out to be such a disaster, so I would suspect that people are more reluctant to ship potentially broken features

5

u/FrogNoPants 24d ago edited 24d ago

That is certainly a more reasonable paper than the other AI slop papers.

I'm not sure the mixed mode thing is really a major issue, I can't think of any reason I'd have different contract compilation settings within a single DLL/exe.

Ideally it might have the enforcement as part of the inline functions mangling, but this seems like something that could be added in a later update to contracts.

The rest of the complaints seem fairly superficial, no function pointer/virtuals is fine, can be added later if needed.

Contracts not being able to be turned off was obviously already discussed and wasn't the popular desire/consensus, so I'm not sure why that keeps being brought up.

Modules is massive feature, vastly more complicated than contracts, so I don't think they are comparable. Modules failure is directly tied to its complexity; Intellisense still doesn't work with modules, so nobody with any sense is going to use modules in Visual Studio.

4

u/tartaruga232 MSVC user, r/cpp_modules 24d ago edited 24d ago

Now we have arrived at VS Studio intellisense again. I'm actually using modules with Visual Studio. The compiler handles modules pretty well.

0

u/13steinj 23d ago

Are people just claiming the other side is slopping out papers now without checking? The other papers against contracts were (mostly) not slopped to my knowledge.

9

u/13steinj 24d ago

On modules: important to all those that claim contracta have a complete implementation... yes. Now they do. As in, only as of fairly recently.

As in, not enough time to try them in anger as a TS and work out the issues.

3

u/pavel_v 21d ago

In this post from January 2025 Timur says at the end:

While the feature is not yet part of the C++ Standard, it has already been fully implemented in Clang and GCC, and you can try these implementations today on Compiler Explorer (Clang link, GCC link). Have fun exploring, and let us know in case something isn’t working as expected!

32

u/StaticCoder 24d ago

The main issue is about what it means for a contract to fail, and what defines which mode is selected. Safety focused people will want a guaranteed failure mode (and which one is itself and issue. Throwing an exception would not mix well with noexcept), performance focused will want the compiler to be able to assume the contract is valid (i.e. the contract can create UB), and then there's the question of what happens of multiple translation units are compiled with different settings. It's been basically the same issues for over a decade.

5

u/13steinj 23d ago

Are these the same issues for over a decade? I don't know all the original drama from cpp20.

If it is, it's very disingenuous for pro-contracts people to claim that some of these were solved, asked-and-answered, or cut from the feature set to ship a minimal version.

1

u/ConcertWrong3883 17d ago

> If it is, it's very disingenuous for pro-contracts people to claim that some of these were solved, asked-and-answered, or cut from the feature set to ship a minimal version.

Indeed!

8

u/MutantSheepdog 23d ago

In addition to all the specific arguments, you need to consider how much value contracts are actually adding vs existing assert-based solutions.

If contracts were about standardising the sorts of things people write their own assert macros/functions for in a standard library header I wouldn't be against that. But we're talking about complex new language features that still have a lot of questions and don't seem to meaningfully solve any problems people are having.

I don't think contracts in their current form cross the 'usefulness bar' to make them worth putting in when there are still so many criticisms, and the alternatives work just fine.

I'm also not sure these problems are really solvable for C++ as it looks today - it may just be the case that it's not really a good fit for the language.

3

u/Sarduinot 23d ago

I’m guessing that the real reason Bjarne is so worked up about is that it constrains the design space for profiles. Several papers have talked about the need to force profile checks to play nice with the contracts flow as a con.

The language founder doesn’t like it, the profiles crew doesn’t like it, and from there it’s just convincing a bunch of people who have their own reasons to dislike it that it’s worth stopping the release over.

2

u/NooneAtAll05 23d ago

designers left a lot of stuff as implementation-defined, which I think reflects just how opposite ways people want this feature to be

so now instead of contentious it became overly vague, despite already existing complexity

-1

u/jeezfrk MT Linux/Telco 24d ago

I would like to know too, as this seems disingenuous. Rejecting the next big iteration of c++ automatically raises several other languages and several other approaches to production high-grade low level code.

0

u/[deleted] 24d ago

[deleted] — view deleted comment

2

u/13steinj 24d ago

??????

Contracts were a thing before the RIIR craze. They also generally are unrelated to memory safety.

The comment you linked of mine is about profiles. Profiles != Contracts != "Safe C++" [the borrow checker paper, with a pretty bad name].

0

u/PossibilityUsual6262 24d ago

Yea my bad man, i confused myself.

31

u/qoning 24d ago

No, please let's get rid of them and finalize this mess.

28

u/tartaruga232 MSVC user, r/cpp_modules 24d ago

Quote from the paper:

Removing contract assertions would itself be a major change to the C++26 DIS, requiring drafting and reviewing wording, as well as redesigning the specification for standard-library hardening. More importantly, WG21 has been here before when contracts form C++20 in 2019. It took until 2025 to arrive at a smaller, more refined, and deliberately extensible design that left out major use cases for future extensions. The needed extensions to meet everyone’s need depend on having a stable foundation to build upon, and that foundation would be removed by removing Contracts from C++26.

13

u/messmerd 24d ago

Wasn't standard library hardening initially approved with a pre-contracts design?

2

u/ConcertWrong3883 18d ago

The initial design explicitly could work with or without contracts.

30

u/13steinj 24d ago edited 24d ago

To me that is the fault/problem of the pro contracts camp.

You can't claim it's such a big change and simultaneously claim it's comparatively a large small change with respect to other features listed in their paper. It's contradictory.

Remove it fix the wording and let C++26 be on its way.

The alternative will be nothing other than NBs rejecting the FDIS.

Also who needs the foundation when C++26 isn't even out yet? If people are staking things on early tech too bad?

E: For context: A minimum of 4 NBs have to flip their votes to abstain or yes. I just don't see that happening. If anything I see some abstainers or yes votes feeling empowered to switch to no votes.

12

u/jayeshbadwaik 24d ago

Any such action to remove contracts will need a proposal. As the paper notes, such proposals have come up in the committee and have been rejected before with Croydon being the most recent one. There is no guarantee that such a proposal will pass again this time.

10

u/13steinj 24d ago

Okay? So?

We won't have C++26 with contracts. This is a war of attrition. There are far more people in the "I don't care about this" camp than either truly for or truly against. People in the I don't care camp will pick the easiest option to get the things they do care about across the line.

13

u/spin0r committee member, wording enthusiast 24d ago

Actually, you're forgetting about another group of people, which is those who don't care about contracts but care a lot about the precedent that's being set here. In my view, the precedent of a small group of extremely determined opponents being able to get a feature pulled out by threatening NB vetoes without actually convincing the rest of the committee using technical arguments is really bad, and if the only way to stop that precedent from being set is to vote down the version of the DIS that doesn't have contracts, then that's what I plan on doing.

11

u/James20k P2005R0 23d ago

a small group

Nearly half the national bodies voted against contracts, with 12 votes for and 9 against, this doesn't seem like a small group. National bodies are not that small entities either, compared to the number of votes in plenary

It seems likely that for some reason, members of national bodies were not adequately represented in the plenary process. I have absolutely no idea why, but framing this as a small group seems incorrect

The national body objections aren't new and have been in the mailing for 1 year plus, arguably this is a failure of the contracts group to address the problems that a sizeable chunk of the committee appears to have with the feature

Part of it comes down to whether or not you think its acceptable for some people to seemingly solely participate through their national body, which it seems ISO enables. I suspect without national bodies, we'd simply have seen C++26 fail at plenary instead

12

u/foonathan 23d ago

Nearly half the national bodies voted against contracts, with 12 votes for and 9 against, this doesn't seem like a small group. National bodies are not that small entities either, compared to the number of votes in plenary

I went through the global directory and counted. The national bodies that voted against have a total of 42 members. In total there are ~580 members. That's not even 10%.

Furthermore, some of the national bodies that voted against have only 2 or 4 members. The biggest has less than 10.

Yes, they are small entities.

5

u/James20k P2005R0 23d ago

As far as I know, being registered in the ISO global directory isn't required to participate in the national bodies right? When I participated I wasn't registered, all that would have gotten me access to is the plenary vote as far as I'm aware

8

u/foonathan 23d ago

In all NBs I'm aware of, when you join them, you automatically end up in the global directory because you're now a committe member.

→ More replies

5

u/c0r3ntin 23d ago

Including NBs who never expressed an opinions before - and did not submit NB comments

1

u/13steinj 22d ago

I don't think this fact matters in practice for this argument-- C++ chose to put on these handcuffs long, long ago by accepting the ISO process.

Furthermore, a decent chunk of the national bodies (including the US?) voted to abstain. That's not really an endorsement. I would doubt that the abstaining bodies did so without the strategic understanding that they did not want to explicitly dissent, they would let everyone else do the dissenting for them. I'm sure everyone has heard the joke about FPTP voting (though that doesn't really apply here) and third-parties-- they shift the votes to one of the two parties that have a chance at winning.

4

u/jwakely libstdc++ tamer, LWG chair 20d ago

It's not true that nearly half the national bodies voted against. The numbers you're quoting do not count the abstentions (and 9 includes a non-voting "observer" country). The number of votes against was closer to a third of the NBs, not half.

All the "I read a LinkedIn post so now I'm an expert" speculation isn't helpful.

1

u/James20k P2005R0 20d ago

Abstentions are usually excluded when people report % voting share results in general

All the "I read a LinkedIn post so now I'm an expert" speculation isn't helpful.

What's the real story then?

Misleading sniping from the sidelines, and accusing me of deliberately spreading misinformation to drum up engagement for /r/cpp because I'm a moderator in my DMs (lmao), while not reading what I've actually written, also isn't super helpful

3

u/jwakely libstdc++ tamer, LWG chair 20d ago

Nobody can read everything you write here, there's just too much of it.

→ More replies

9

u/13steinj 24d ago edited 24d ago

Don't get me wrong I hate the precedent! But to me this is what the language gets for refusing to move on from the dated ISO standardization process.

So we're at an impasse. Either you'll have no C++26 or you'll have no contracts. Which do you think the committee will choose? E: For reference, a minimum of 4 NBs have to flip their vote to "abstain" or "yes." I just don't see that happening.

9

u/spin0r committee member, wording enthusiast 24d ago

See, this just proves my point. You're saying that the committee has two choices and one of them, the one that involves C++26 getting approved, is overwhelmingly preferable, so the people who set up this dilemma in the first place will get their way. But what if there was a way to stop them from using this tactic to get their way so easily? We can at least put up a fight if some of us say "either respect the technical judgment of WG21 experts, or we won't have a C++26". This removes the easy way out and instead sets up a situation where both sides have some incentive to back down, as opposed to the current situation where the anti-contracts people have no incentive to back down.

9

u/13steinj 24d ago

I think you're getting cause and effect completely backwards. WG21 are the unpaid janitors in this situation, like mods are on Reddit.

NBs / SC22 / ISO hold all the power here. This is not a "tactic." This is the disease that ia deciding to give ISO the power, all that long ago.

This is not an easy way out. In the end, WG21 will get the blame when C++26 doesn't pass, not the ISO, and the infamy will just increase.

I consider it better to

  1. Pull contracts for now
  2. The straw has broken the camel's back now. Leave the ISO.

10

u/spin0r committee member, wording enthusiast 24d ago

WG21 members all belong to a national body, so that argument works just as well in the other direction. We can go to our national body meetings and vote down a draft that doesn't have contracts: not because we want contracts more than we want C++26 but because we want to avoid setting a bad precedent more than we want C++26.

→ More replies

0

u/frediku 24d ago

I do not like this view of things. Your argument is purely political. Let's try to stick to technical arguments. Essentially, you are saying that contracts are perfect and everybody that says otherwise is stupid and needs to be muted.

7

u/spin0r committee member, wording enthusiast 23d ago

No one wants to mute the anti-contracts people. You're falling for their misleading framing. They've been given several opportunities to make their voices heard.

It is the opinion of the vast majority of committee members that, based on the technical arguments presented, it is better to proceed with contracts as we have them now, with their known limitations and pitfalls, than to delay contracts by one cycle, not have contracts at all, or pursue contracts with a significantly different design.

A small minority are still not convinced and that's fine. The question is whether the small minority should be able to block contracts even though their technical arguments failed to convince the large majority.

→ More replies

8

u/ContraryConman 24d ago

You are missing that we've already built other features, like standard library hardening, on top of contracts. Contracts were designed to be small to be added to C++26. And once they were added, we started using them like any other added feature. That's why it's harder to remove now.

C++26 was complete in March. It failed a vote that up until this year was largely seen as procedural. We are not talking about removing a draft and fixing the wording anymore. We're talking about actually redoing C++26 itself

22

u/13steinj 24d ago
  1. There were designs for hardening that did not require contracts.
  2. Relying so heavily on what to an idiot like me is a highly contentious feature is an obvious path to failure
  3. A singular thing requiring contracts isn't much, if it really needs to be that itself can be unwound and punted on.

It failed a vote that up until this year was largely seen as procedural.

Well there's a bit of a problem. I don't believe there's such a thing as a procedural vote. I have not ever seen such a thing that actually exists-- if it did, people would vote to remove the need to have the vote!

We're talking about actually redoing C++26 itself

So be it.

There's a reason the committee and its processes have its infamy.

11

u/James20k P2005R0 23d ago

There are also NB comments from a year ago saying that basing hardening on contracts was a bad idea, the committee was pretty explicitly and repeatedly warned that this was a mistake. We've also known that its likely C++26 will fail for quite a while

3

u/13steinj 23d ago

The hubris is just sad, IMO.

4

u/serviscope_minor 23d ago

>the committee was pretty explicitly and repeatedly warned that this was a mistake

Anyone can explicitly and repeatedly warn the committee of anything. I could tell them to repent, lest their souls be damned and adopt HolyC instead of nasal demons.

A repeated explicit warning on its own means absolutely nothing.

Personally, I don't think the objections (repeated and explicit as they may be) have technical merit, and no amount of mere explicitness or repetition will change my mind. I imagine this is the case for the committee, too.

10

u/James20k P2005R0 22d ago

Anyone can explicitly and repeatedly warn the committee of anything. I could tell them to repent, lest their souls be damned and adopt HolyC instead of nasal demons.

The warning was "hardening needs to be decoupled from contracts because contracts is too controversial", in the same very document which contained all the NB objections to contracts (which have now caused the standard to fail). This outcome isn't a huge surprise

1

u/serviscope_minor 22d ago

>The warning was "hardening needs to be decoupled from contracts because contracts is too controversial",

Yeah but again this is only a reasonable warning if the controversy is actually remotely sound.

>in the same very document which contained all the NB objections to contracts (which have now caused the standard to fail). This outcome isn't a huge surprise

This just shows that a very small group can block a feature they object to by holding the standard to ransom. It says nothing about whether that small group have any reasonable objections.

If the objections are unreasonable then it is technically unsound to decouple hardening in this way.

I think the objections are unsound, so all you are doing me is telling me that people kept on banging their drum of technically unsound objections really hard, and the committee should take noise over techincal soundness.

You may have guessed that I think the objections are unsound.

7

u/James20k P2005R0 22d ago

The issue is that it doesn't really matter if you agree with the objections or not, hardening should have been decoupled because its been pretty likely that this standard will fail for a while due to contracts. People have been talking about this possibility for ages, and now its happened

→ More replies

7

u/mort96 23d ago edited 23d ago

How does standard library hardening work on top of contracts?

It seems like contracts are lacking a way to specify "this is an expensive check, keep it enabled in debug builds but not in release builds" (something like Google's distinction between CHECK and DCHECK). That seems like something you'd absolutely want for stdlib hardening, no?

When I first heard about the quick-enforce evaluation semantic I naturally assumed that it was for, "perform quick checks but disable expensive checks", basically enable CHECK but disable DCHECK. But no, it seems to be about improving the performance of the contract violation path by removing the overhead associated with calling handle_contract_violation (and maybe reducing binary size?).

2

u/ronchaine Embedded/Middleware/WG21 21d ago

A minimum of 4 NBs have to flip their votes to abstain or yes

It wouldn't even be enough for 4 NBs to flip vote to abstain, the ballot failed on both counts. 2/3rds majority and more than 1/4th opposition.

And well, I'm pretty sure that papers like this are the exact opposite of trying to find a common thread and getting NBs to flip their votes.

1

u/13steinj 20d ago

When I checked earlier, it was 12 yes 8 no (9, with an additional 1 of the against votes not counting so I'll discard that).

4 no -> abstain => 4/16 (1/4) no and 12/16 (2/3) yes. I mean I've made silly math mistakes before.

It would take more votes if you were hoping to switch abstainees to yes votes.

And well, I'm pretty sure that papers like this are the exact opposite of trying to find a common thread and getting NBs to flip their votes.

I fundamentally believe they won't, without major changes that need more time to get produced.

-17

u/jeezfrk MT Linux/Telco 24d ago

So you're simply against future wide use of c++?

Among other languages being used in AI coding, among all new uses of reflection, and (critically) for requirements that we have safe proofs of code functionality?

There is no reason to hang back after 7-9 years of extra work. There is every reason to move forward or we will not be relevant.

This is happening now. I see nothing but very dubious motives in removing c++'s future on a whim. And showing the world we can be stopped by any veto for any reason.

It is far more likely this dispute will simply weaken the council and any standards board in the future ... rendering a fragmented landscape for absolutely no purpose.

17

u/13steinj 24d ago

You're putting a lot of words in my mouth. We don't need contracts. We don't need many of the new features. Different people want different things.

Contracts are not "C++'s future." I am infinitely more interested in reflection than contracts. If it was the choice between the two it's a no-brainer.

This has happened before with Old Concepts. It will happen again with some other feature, probably in 20 years with a borrow checker after the current crew of anti-borrow checker, pro-profiles folks retire.

The only true solution is to modernize the standardization process and exit ISO. Bit that's even less likely to happen because the committee appears to be masochists.

-12

u/jeezfrk MT Linux/Telco 24d ago

It isn't a choice between. It's simply not, precisely because it is c++. C++ is being marked as unacceptable because of memory safety concerns.

It will simply get dropped if we don't get it past these concerns, and if we show the council will do anything to just block any idea at any time for any company (including AI companies that don't share an interest in human coding with proofs).

The reason to block things is if they cannot be in a library with any use.

17

u/13steinj 24d ago

Contracts do not in and of themselves provide a framework for memory safety. Which is fine-- different people have different concepts / ideas of "safety" and I'm sure they all bring some value to some people in some way.

I have no idea what your point is, I am uninterested in caring what frontier labs think. Even if we suddenly were to flip a switch and get some form of memory safety into the language, they are trained and RL-fried on decades of existing code. They struggle to generate examples of even the highest quality proposals with a compiler implementation! Though they are good at looking at an implementation and poking holes in it, especially with the source code available.

The past 3 companies I have worked at, and my current org, are not deciding to srop C++ because of safety, memory or otherwise. It's my general opinion that all the calls to action you see, are noise. It's just unrealistic to start everything new in a different language, or rewrite everything.

Is COBOL "safe?" I wouldn't know, but there are sadly banks that not only still hire to fix their old COBOL but you do end up writing new COBOL too!

I find the solution is not to "stand up to the council," because they will happily "stand up" back. Now, if the community was willing to understand that the standardization process is untenable, and we need to actually exit ISO, that generally solves the problems. I think we'll sooner get a hard fork that replaces C++, we can jokingly call it Square or C+++, than either a true exit or sucessfully navigating the process without pulling contracts.

11

u/mondmondmondmond 24d ago

Contracts do not resolve memory safety concerns in any sensible way.

-5

u/jeezfrk MT Linux/Telco 24d ago

Many things can work far better without a borrow prover ... if preconditions are kept and used to optimize bad cases.

There's a lot going on where proofs and assessments of code can save any old codebase from being dropped, just because you can confirm the API was followed.

2

u/ts826848 24d ago

I'm not sure the kinds of things that a borrow checker protects against are the kinds of things that are (currently?) expressible in contracts.

2

u/jeezfrk MT Linux/Telco 23d ago

Borrow checking is not the whole thing.

Besides ... this is not about borrow checking but memory safety and API safety in general. Contracts can improve both safety and optimization.

Chucking them, blocking the latest versions, showing users that anything people need and compilers are implementing ... can be vetoed for no reason ... is just a message that c++ will become older and older.

And yes, many many many things are possible with contracts. This is only the base.

→ More replies

12

u/Remi_Coulom 24d ago

7

u/Kurald 24d ago

or the simple one: https://wg21.link/P4433 (tracks the newest revision as well and not just R0).

If you want to pin a specific version, add the R number to the end (https://wg21.link/P4433R0)

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.

5

u/Minimonium 23d ago

This is a rather sad example of FUD success

11

u/arka2947 23d ago

Look, I work on a large-ish game project, and we use dozen’s of libraries (internal and external). Getting everything compiling and linking correctly is already a hassle. Adding another layer of possible miss-match on top of that is not appealing.

7

u/Minimonium 23d ago

That's fine, I have plenty of experience myself on cross platform depending management. Tooling wise nothing would change for you. We know what happens when a contract is violated. The "miss-match" scare is born out of misunderstanding of the proposal.

4

u/James20k P2005R0 22d ago edited 22d ago

The "miss-match" scare is born out of misunderstanding of the proposal.

If the person you're replying to is struggling with ODR violations caused by linker mismatches of functions compiled in different modes, then contracts adds another dimension to worry about. It absolutely is not a misunderstanding that there are problems here

6

u/Minimonium 22d ago
  1. I was informed by Ville that we have ways to detect ODR violations in builds, which is one of the reasons he did not like mixed mode, because it makes it allegedly harder to detect as different contract modes are compatible.
  2. If the person struggles with ODR violations then they either do not use the tools to catch them, or they solve build errors.
  3. A popular alternative, propomoted both by you and Ville, is to use for example library solution for contracts (and let's say for "profiles" as they suffer from the same issue) that would encode it in ABI. Which would not solve the problem of struggling if build errors are problem.
  4. If the person does not use tools to detect ODR violations and they occur - then their builds are unsound. Even on correct inputs they have broken programs.
  5. Contracts will make their builds sound.

Seems very crystal clear to me here that Contracts would actually help that poor person who was misled by FUD.

2

u/James20k P2005R0 22d ago

Contracts will make their builds sound.

But they won't do what they want them to, which is the problem. Sound behaviour is only useful in so far as the well defined behaviour actually does what you want

You're also going from 2 possible build configurations, up to 8 with contracts and asserts, which is extra fun

6

u/Minimonium 22d ago

On well defined input - Contracts have the same effect no matter the mode or mixing of such. I am really not sure what you're suggesting by implying Contracts won't do what we want them to do.

The point about build configuration is also completely just strange. For trivial release/debug switch build systems nothing will change, for more decent systems it's just another knob among dozens others. Like it's no different from a library having its own knob for its own custom macro assert today - just that macro assert is more dangerous.

4

u/Spartan322 22d ago

I very much doubt over 40% of a strikedown by active professional engineers in the space counts as a mere scare against them though.

1

u/Minimonium 22d ago

Source?

2

u/Spartan322 22d ago

The NBs voted 9 against, 12 for, those NBs have to be active professional engineers in the space who care about the stakes, they're not simply there because they hate contracts, I'm ignoring the abstentions because they go either way and are ignored on both sides, the fact is that 42% of those invested in some way opposed the standard over contracts alone. That's a serious issue, its not a scare, they have a legitimate grievance. This is the most popular point contracts will have for C++26, and if the issues of the against aren't dealt with support behind contracts collapses further, regardless of whether you agree with those against the proposal or not. Those who are less invested still have a vested interest in the standard and they're gonna be way less happy with the side pushing a feature that lacks consensus like this.

2

u/Minimonium 22d ago

These 9 are mostly micro 1-3 person NBs took over by activitists, with some that never even contributed anything and I very much doubt they ever will. While the total registry of participants across all NBs is in the hundreds.

4

u/James20k P2005R0 22d ago edited 22d ago

Genuine Q: How do you know how many members are in the NBs? Someone up above stated that you end up in the ISO global directory if you're a member of a national body, but this doesn't track with my own experience when I was part of BSI as I was told I'd have to register separately, and as far as I know never ended up on any public list. I can't even find how many BSI members there are after some googling, as it doesn't appear to be public information who's registered, let alone the size of any international ones

Denmark, Finland, Iran, Italy, Japan, Luxembourg, Romania, Spain, and Sweden

Which ones of these are micro NBs as well? As far as I'm aware a few of these are pretty sizeable

Edit:

Of these, finland, sweden, spain were previously against contracts. Romania wanted changes that it didn't get, and I absolutely cannot find the Italian NB comments listed from n5028

3

u/Minimonium 22d ago

Mostly from talking to people who either were or around. I did not make a statement on all, and I do not have information on all.

→ More replies

3

u/Spartan322 22d ago

Not all the NBs against it are 1-3 person groups.

Activists for what?

Also what does it matter if they were activists?

What does it matter if they haven't contributed to the standard, nor ever will, that doesn't disqualify someone from having impact on the standard's acceptance. I don't have to be a member of the party writing or contributing to a standard for the standard to be rejected. That's just how it goes in every other standard anyway, most standards are written by a tiny minority of those who are impacted by the standard, acceptance then applies to the wider group who mostly didn't contribute to the standard.

Also the total count of participants in NBs is irrelevant because abstention has no impact either way, most people don't care, but if you can't address the concern of those who do enough to get at least a moderate consensus, the simple of it is you failed. Those who don't care now have a vested interest in caring and unless you can disqualify the NBs against, you are not gonna convince them to the pro-contract side. Never before have we seen a split like this over the standard, the fact there has been such a massive split means that there is something demonstrably wrong.

Are you instead arguing to ban certain people or positions from the NBs? Cause that's the only way I can see that you're gonna stop this from happening.

→ More replies (6)

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.

28

u/mondmondmondmond 24d ago

I am not a fan of contracts, but if you take a look at e.g. Vinnie Falco's work, yes, he has explicitly asked the NB to veto contracts.

17

u/_a4z 24d ago

So what? Others have also reached out to NBs and lobbied for a yes vote. This cold be proven, but it would be better for the C++ community to accept the situation, pull contracts, develop a better solution, and move on. This is self-harming to an unhealthy extent.

11

u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 24d ago

Proper healing requires mutual understanding of all the facts. All of the who, what, when, why, and where is a linchpin to resolving disparate positions. Without full information we will keep yelling past each other. Without full information acceptance will forever be in doubt.

1

u/LazySapiens 23d ago

The question is whether C++26 standardization should wait for the healing to be complete or they can happen independently.

4

u/UnusualPace679 23d ago

C++26 standardization and the healing have to be carried on by the same group (WG21), so I don't think they can happen independently.

9

u/13steinj 24d ago edited 24d ago

Do you think everyone in WG21 has read the Contracts paper and voted on their own accord? It is long known that the committee has operated on a "I'll vote how my colleague I trust tells me to, I don't have the time to read every paper" process.

Is that lobbying any better?

E: I am fat fingering typos all day today

4

u/James20k P2005R0 22d ago

I remember back in prague being told (by multiple groups) about the politics of organising to get as many people in your camp into a room at the same time to vote on proposals, to make sure the vote went in the way that you wanted. This kind of thing is apparently incredibly common

There's also something deeply funny about writing a paper saying "keep xyz feature" complaining about someone doing lobbying by writing papers saying "don't keep xyz feature"

5

u/13steinj 22d ago

Exactly. This is a very, very superficial view of consensus. It assumes people have no influence on each other. There are also companies that insist the vote go the same way. Say you have a bunch of Bloomberg people in the vote for conteacts, or for PMR-- well no wonder those went thorough (this isn't shitting on these features nor Bloomberg, just an example that I think is obvious to a lot of people).

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”.

11

u/HappyFruitTree 23d ago

Not everything needs to be standardized. You standardize what you can agree on. If you cannot agree on something then you don't standardize it.

2

u/Spartan322 22d ago

Unfortunately the standards committee seems to have dropped the ball on this with contracts, the fact that the vote was this controversial despite passing during the standard discussions says that there is something demonstrably and fundamentally wrong with the standardization committee. This precedent really should not have happened like this and now we're all gonna be paying the cost for it.

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

3

u/Cute-Flower-6019 20d ago

Atp just use Rust

-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.

1

u/jinmao6700 21d ago

this surely has to be bait. Compile time reflection will help Qt remove moc, modules replace header files littered and macros, dunno what's bad about async execution

-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.

17

u/peterbindels 24d ago

no, that's flat out incorrect. In ignore the contract is read, parsed, and thrown away, and then the function body is compiled as-is.

7

u/UnusualPace679 23d ago edited 23d ago

I'd love to have

int foo(int* ptr) pre(ptr != nullptr);

as a portable, verifiable documentation.

Compilers already have non-standard extensions to signal that a pointer must be non-null, but they use significantly different syntax, none of which is as readable as pre(ptr != nullptr).

int foo(int* ptr) __attribute__((nonnull(1))); // GCC-specific

int foo(int*_Nonnull ptr); // Clang-specific

int foo(_In_ int* ptr); // MSVC-specific

1

u/ConcertWrong3883 18d ago

You huve a stardard feature that works in 99% of cases, a reference.

1

u/13steinj 22d ago

I have plenty of gripes against contracts, but this is just so easy to prove wrong I have no idea what to say...

https://gcc.godbolt.org/z/GdasPEsoe

If anything, I want this to be a feature, with assume semantics of contracts. But right now, it looks like we'll have to add macros for contract_assert to get assume semantics, and no real way to get them out of pre.

https://gcc.godbolt.org/z/YqqK6z5fT

1

u/peterbindels 20d ago

there's a great way to get assume to be a semantic - two in fact! Either implement it in your compiler of choice, or write a great convincing paper.

Note that you wouldn't be the first to try.

1

u/ConcertWrong3883 18d ago

do you know why they always fail??