r/cpp • WG21 Member • Oct 24 '26

Balloting has completed for C++26. Unfortunately it was Disapproved

https://www.linkedin.com/posts/robertseacord_balloting-has-completed-for-c26-unfortunately-share-7519795139859517440-AOth/

Since the C++26 DIS has been disapproved, the next step is going to be taken in Buzios during the 2026-11 meeting. The committee will have to decide what changes to make (if any) and submit an FDIS (Final Draft of International Standard) for Balloting.

287 Upvotes

399 comments sorted by

View all comments

24

u/Sniffy4 Oct 24 '26

Anyone want to summarize the detailed objections to Contracts

37

u/gmueckl Oct 24 '26

I know I may be walking out on a mine field here by replying to this at all. Let's find out the hard way.

All I know comes from a recorded talk that was given a while ago that argued quite well that contracts have a few hidden surprises, mostly around the different configurable evaluation modes for contracts: ignore, observe, enforce and quick-enforce. They argued that it is hard to know which mode will be used at all and that different TUs can be compiled wirh different modes, which can lead to unexpected inconsistencies and ODR violations.

To be frank, the talk was a few years old IIRC and if the arguments have been refuted or the contract behavior changed since that talk, I don't honestly know about it. I haven't managed to get too deep into this discussion.

It also seems quite unfortunate that the discussion has turned overly emotional, so a good engineering compromise has become increasingly unlikely because of that.

I would like to say "trust the process", but the process hasn't always led to the greatest possible results, if we're honest.

17

u/James20k P2005R0 Oct 24 '26

and ODR violations

Its worth noting that they aren't formally ODR violations, as its a different mechanism, its a well defined version of the same result we got from ODR violations. This aspect at least is still part of the standard

13

u/gmueckl Oct 24 '26

As I said, I'm not deeply into the subject at all, but isn't that splitting hairs a little thin? I read your reply like this: the resulting problems are the same, but it's okay because we're not meeting another criterium that's formally in the definition of what constitutes a ODR violation. If this is vaguely what you're saying, I'm still getting the sense that there is a set of very sharp edges attached to contracts.

16

u/Minimonium Oct 24 '26

The result is not the same. Compilers are not allowed to speculate if a visible contract statement is called or how many times. It prevents miscompilations like so-called time-travel optimizations.

You may find inline functions very similar. Implementations use exactly the same mechanism to prevent issues across TUs. Yet we're not calling the use of inline functions an ODR violation.

7

u/gmueckl Oct 24 '26

What happens when the function isn't truly inlined, but emitted multiple times for different TUs? If the TUs were compiled with different contract evaluation semantics, you get multiple versions of the same function, differing by how the contract code was translated, right?

So my understanding is that unless that evaluation semantic gets embedded in the name mangling, you have colliding definitions for the same weak symbol at link time and at worst a lottery of which version the linker picks. This is then practically identical to having an #ifdef in the function body and not using the same value for the defines across TUs.

Right now I don't see how this situation isn't a footgun in practice.

The way you replied me makes me suspect that you have a specific counter to this. Is my reasoning wrong?

8

u/Minimonium Oct 24 '26

It is practically different because an #ifdef leaks through a non-inlined function back, with compiler optimizing out even checks at the call cite by relying on some information from your #ifdef.

What it means practically, if your program input is well-behaved your program is well behaved. No matter how you mix TUs with which Contract modes. If your Contract is violated - you get best effort feedback until the program naturally crashes. With #ifdef - your program will misbehave even with well-behaved input.

8

u/gmueckl Oct 24 '26

Isn't "best effort" doing a lot of heavy lifting here?

Developer A writes a library that has an inline function containing a contract in a header. He distributes the header and a prebuilt binary with contract evaluation semantics set to enforce.

Developer B is a user of that library and has inherited a codebase where some unknown predecessor has set contract evaluation semantics to ignore and as a result, contracts have deteriorated for a while and can't easily be reenabled.

Developer B is now having an issue with a crash deep in A's library and asks for help. A looks at the crash and finds a an invalid state that should have been caught by contracts way before the crash happened. Now, A has to figure out the execution flow that created that invalid state and needs to discover that the particular inline function in the header was the culprit because its contract was neutered by developer B's compiler settings. He can't determine that for certain without knowing B's compiler settings for B's project.

7

u/Minimonium Oct 24 '26

I used "best effort" not as a coy way to walk around a sharp issue, but as a reflection of a range of behaviours we require for the feature to have even before going into the "mixed mode" topic.

What is "best effort" when we use NDEBUG with macro or ignore with Contracts?

A looks at the crash and finds a an invalid state that should have been caught by contracts way before the crash happened.

Seems like a false premise. Replace "contracts" with "asserts" here, with the same scenario. Keep in mind that what Developer A does in your case is a required behavior for cases where instrumented runs are simply impossible.

5

u/James20k P2005R0 Oct 25 '26

What is "best effort" when we use NDEBUG with macro or ignore with Contracts?

With asserts at least, you can in-source force your asserts to either be always-enabled or always-disabled, and fully disable external configurability of them if you have code which you think is going to be misused, or if you have asserts that must always be run. There's no equivalent to this for contracts unfortunately

This is one of the major reasons why there's objections to the current enforcement mode configurability of contracts (and why mandatory contracts would fix some problems for me at least), because unlike with asserts, there's no way to avoid the linking problems by enforcing a uniform configuration in-source

→ More replies

4

u/James20k P2005R0 Oct 25 '26

So my understanding is that unless that evaluation semantic gets embedded in the name mangling, you have colliding definitions for the same weak symbol at link time and at worst a lottery of which version the linker picks

I just want to pop in here to say that adding a contract or switching contract enforcement mode is explicitly not an ABI break, so there's no mangling change or anything else. I do think a lot of problems could have been avoided if this were not true, but apparently being able to add contracts to closed-source 3rd party code seems to have been desirable at some point by someone for some reason. So we end up with this as a result of ABI compatibility

5

u/peterbindels Oct 26 '26

> I do think a lot of problems could have been avoided if this were not true

Mangling contracts has been looked into in depth multiple times, and there's no safety / security to be gained. In particular an opaque contract can have its implementation changed, making any mangling done useless to detect such a change.

If an ABI wants to mangle in the whole contract that'll catch many accidental mistakes. Don't mistake catching accidents for safety or guarantees.

3

u/James20k P2005R0 Oct 26 '26

Mangling contracts has been looked into in depth multiple times, and there's no safety / security to be gained

Do you happen to have a link to a paper/discussion on this? I'd love to see what was already considered here, as as far as I'm aware ABI compatibility has been a baked in requirement for contracts for ages

4

u/peterbindels Oct 26 '26

I wrote https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3267r1.html a while ago - last updated may 2024, but I should update it again - and it goes into implementation strategies. In 2.3 I have an approach that works if you make an ABI change, with minimal breakage even on incremental upgrades. Part of the feedback on that was that it does not catch any contract changes on half rebuilds ... which IMO isn't a problem, but some people do ship their code that way. In offline discussion beyond that point we tried to see if encoding the contracts themselves would work but the counterexample of pre(foo(x)) just breaks any such proposal. The discussion on this paper in SG15 from iirc Wroclaw should have some detail on it, but lots of it was in offline meetings and discussions with Joshua.

→ More replies

3

u/kalmoc Oct 25 '26

Don't you also need this, if you want to have different contract behavior between different TUs in an open source project?

2

u/James20k P2005R0 Oct 25 '26

This could (should?) have been achieved by producing symbols with two different names. If you do this currently, you'll end up with only one contract enforcement mode when the linker deduplicates your functions

Eg this https://github.com/20k/contracts-odr

7

u/kalmoc Oct 25 '26

This could (should?) have been achieved by producing symbols with two different names.

If the TU implementing the function produces a different mangled name, than the TU trying to call it, how is that supposed to work?

9

u/spin0r committee member, wording enthusiast Oct 25 '26

Actual ODR violations can result in linker errors, programs crashing, and undefined behavior because the compiler optimizes in one TU based on what it can see while the version of the function that ends up in the binary came from a different TU and is different. Mixing contract modes is not an ODR violation, you simply get one of the modes.

2

u/peterbindels Oct 26 '26

+1, for all in-contract calls the behavior is identical, and they are interchangeable. In addition they have the bytewise exact same source.

1

u/James20k P2005R0 Oct 26 '26

Just FYI your comments are being eaten by automoderator for having a new account, I'm manually approving them when I spot them in modmail 👍

4

u/peterbindels Oct 26 '26

I know, thanks. Deleted my original acct (/u/dascandy) a decade ago but got annoyed with how much misinfo was around here.

6

u/James20k P2005R0 Oct 24 '26

I agree with you personally, I think its not a great addition here, and its one of the reasons why people claim that contracts are unsafe

15

u/James20k P2005R0 Oct 24 '26

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3851r0.pdf

Is a good summary of the issues. In the 2025 mailing I went through and summarised many of the national body objections to contracts at the time as well

3

u/JVApen Clever is an insult, not a compliment. - T. Winters Oct 25 '26

The previous list: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3846r1.pdf We'll learn later if anything new popped up, though https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4433r0.pdf seems to suggest not.

→ More replies (1)