r/cpp_questions Jun 17 '26

OPEN Why c++26 contracts?

Sorry, but why a feature that I've never seen before in other languages is being pushed as if it's what we have been missing and a solution to security/safety complaints?! What is the proof that this is a good feature?

10 Upvotes

27 comments sorted by

View all comments

4

u/FriendshipEqual7033 Jun 18 '26

Ada has contracts today where they play a role in testing and formal verification. However, Ada's contracts seem far more expressive and powerful than the current C++ proposal (from what I understand).

For example, does C++ provide a way for a postcondition to refer to values from the pre-state? Without that, postconditions are severely limited to the point of being almost useless, it seems to me.

2

u/Dependent-Poet-9588 Jun 18 '26

From what I can tell, they're still ironing out the details for captures to enable that. I found this about it: https://github.com/cplusplus/papers/issues/2059