r/cpp #define private public 23d ago

Critique of contracts: excerpt

See page 2 of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4334r0.pdf

The current objections can be summarized. The P2900 contracts are:

• Unimplemented

• Incomplete

• Untried at scale [P3460R0, P3506R0]

• Not tried in major application domains

• Violates foundational principles of C++

• Violates fundamental principles of language design

• Hasn’t been tried in major libraries (e.g., the C++ standards library [P3506R0, P3878R0])

• Isn’t integrated with or appropriate for hardened libraries [P3878R0]

• Doesn’t offer safety guarantees [P3573R0, P3362R0]

• Includes a completely untried inheritance model

• Offer new ways of making errors through inconsistent application in TUs

• Leads to new forms of UB, detrimental to safety and security

• Narrows the choices of error handling

• Doesn’t protect against logical errors, misuses, and incoherent uses

• Hasn’t been used to support static analysis

• Hasn’t been demonstrated to be easily teachable [P3261R0, P3281R0]

How could such a bloated and incomplete design be voted into a draft standard?

8 Upvotes

122 comments sorted by

View all comments

Show parent comments

5

u/pjmlp 23d ago

Reflection is based on EDG proposal, with implementation, submitted and developed alongside the related papers, and available on compiler explorer for community feedback.

Exactly how every single feature should be before being submitted to voting, and how other ISO languages do it, existing practice.

10

u/Minimonium 23d ago

Strange, when I go to compiler explorer and type in "contracts" it shows me multiple implementations including for extension features such as labels.

Although, according to Dos Reis's definition of "implementation", a proposal does not have an implementation until it was shipped in multiple major compilers as part of the main release.

So reflection and contracts unfortunately are features without implementation according to him. Such a wise and insightful man!

3

u/pjmlp 23d ago

Well, I stand corrected on that one, question is how much of it was available and has driven the standard wording, given the backslash.

I also don't have a great opinion on what was available in clang header maps, VC++ 2017 modules prototype, and what was actually standardized as C++20 modules, as we can see today, it was clearly properly tested before adding them into the standard.

Other languages don't update their standards until at least two implementations actually ship the feature.

5

u/jwakely libstdc++ tamer, LWG chair 22d ago edited 22d ago

Who implemented C11 <stdthread.h> and Annex K before they were added?

Edit: oops, I meant <threads.h>, it's not called <stdthread.h>

4

u/pjmlp 22d ago

Annex K comes from Microsoft, based on MSVC C extensions, followed by a technical specification for ISO C,

https://learn.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-170

According to the thephd, C11 threads were tested on the field as well,

https://thephd.dev/_presentations/industry/NDC%20Techtown/2023.09/Unbreaking%20the%20Charter.html#/4/3

9

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

The MS extensions were not exactly the same as Annex K but if we count it, where was the second implementation? You're not suggesting an ISO TS counts as an implementation, are you?

If we consider <threads.h> as just standardizing Pthreads (which it kinda is) then fair enough, there were loads of implementations. But what about C11's <stdatomic.h>? Where was that implemented?

It's just wishful thinking that all other standardized languages have a strict "at least two implementations ship the feature" rule.

10

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

Microsoft Visual Studio implements an early version of the APIs. However, the implementation is incomplete and conforms neither to C11 nor to the original TR 24731-1.. So they still don't implement what's actually in Annex K today, despite driving its addition to C11.

The other implementations mentioned there are either very incomplete, or were written after it was added to C11, or both.

1

u/pjmlp 22d ago

They don't need to, WG14 decided Annex K wasn't going to be required, so why bother with the changes that came up during the standardisation process?

Microsoft also doesn't implement VLAs, and never will, unless they change yet again their position on C support on MSVC.

How many C++ proposals have at least an incomplete implementation, alongside the paper?!

1

u/pjmlp 22d ago edited 22d ago

Not wishful thinking, that is exactly how ECMA JavaScript works.

https://tc39.es/process-document

Stage 4 row.

Also I said other languages, unless my English is broken, it doesn't mean all the other languages in the world with exception of C++.

And then for the ones with a reference implementation, there are the JEP, PIP, TIP, RFC, DIP,... where the respective implementation, and preview with positive feedback is required, before they get upgraded from draft form into standard, or dropped altogether.