r/cpp • u/antiquark2 #define private public • 15d ago
Exploration of a more library-oriented approach to contracts (Voutilainen, 2026)
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4324r0.html6
u/eisenwave WG21 Member 15d ago
This does seem like an interesting approach for C++29. Here are some thoughts:
I'm not entirely sure whether we want the liberty to turn constification on and off depending on every part in
assertion_static_info. Maybe that could be astatic constexpr boolmember instead of a function.In general, the paper is not self-contained when it comes to its rationale. Just to focus on constification, the paper doesn't explain why it would be important to turn off constification in the first place. The obvious issue with making this configurable at all is that the user cannot be sure whether their
pre<...>(x)gets constified. One would always have to look at what's inside<...>, and if constification is controlled by a function, perhaps even at more.It seems like this paper could be a strict superset of P2900 and P3400, where those papers simply provided hardcoded/default "assertion control objects". Is it intended to be a superset?
A lot of the compiler explorer links lead to examples that fail to compile, presumably because the implementation got updated while the code stayed the same. It would be good to have some examples available directly in the paper, especially considering that Compiler Explorer links don't last forever.
11
u/Trubydoor LLVM dev 15d ago
Would this not remove the ability to distinguish between "debug" and "release" builds of contracted functions; i.e. only enforcing the contract in "debug" builds and ignoring it in "release" builds?
Or, I suppose you could #ifdef on that but then we have the same ODR violation issue of using
assertin inline functions in headers?