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.

291 Upvotes

399 comments sorted by

View all comments

Show parent comment

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

6

u/Minimonium Oct 25 '26

Hardened implementations are already guaranteed to only have terminating semantics that fixes all certified industry concerns to me. Adding separate syntax for specific semantics is additive work that certainly needs implementation experience to see if it's actually useful first, for example today we do not have a reason to have "always-disabled" pre/post conditions as we do not have a static analyzer yet that takes advantage of it.

I disagree that an in-source configuration would help here. Source is just source, and when you do not take control of downstream builds they may do all sorts of shenanigans with it and still try to link to your binaries.

Funny enough each time I read another "brilliant" idea to add configuration in-source (like the so-called "profile framework"), I remember the days when people used to "auto-link" dlls in-source in headers, with ifdef to link to d-suffixed binary variants. What a shit thing it was and how much effort it took to tear it out back in the days and build a proper build infrastructure.

6

u/Dragdu Oct 25 '26

Not for inline functions, which is the thing discussed here. If your inline function with assert gets emitted in a NDEBUG TU, whether the resulting unified function asserts or not is linker & link order dependent.

4

u/James20k P2005R0 Oct 25 '26

You can control the state of NDEBUG in source manually though, eg if you manage it in a header you can force your asserts to be always on regardless of what the build system says

2

u/Minimonium Oct 25 '26

The build system can... just patch it?

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

1

u/13steinj Oct 31 '26

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.

Sorry, being dense here-- why does that break? What exactly is wrong with doing this. I won't have the ability to look up any internal discussions for a couple of months (my org's NB primary as far as anyone knows left the company last year, and even tracking the slightest stuff down internally has been a hassle).

1

u/peterbindels 29d ago

from the perspective of the user `foo()` is just an opaque function, with no details. If you encode that into your ABI you rely on the *implementation* of `foo()` never changing. If it does change, you get an undetectable changed contract and you again link against something with a different contract.

You'd still detect almost all contract changes so it's a good warning, and a good practice for implementers to consider, but it doesn't *solve* the problem, and in fact it can never *solve* it. It's in part why in P3267 approach 3 I didn't add it to the ABI change because it'd be a larger ABI change without a matching added guarantee to make it worthwhile. P3267's approach 3 works 100% including optimization for held contracts iff you recompile when code changes. If you are willing to accept partial recompiles it cannot guarantee it - and nobody truly can. Y'know, the source of tons of ODR violations.

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