I'm interested in studying the recently accepted contract programming for C++20 for learning and investigation purpose.
As I'm looking around for compiler support, I'm disappointed to not find any. Both gcc
and clang
are quite clear they do not support this feature within their --std=c++2a
mode.
Since the approval is pretty recent, I'm not too surprised that current compilers do not support the exact semantic proposed. What is more surprising to me though is that there is absolutely nothing, not even a compiler-specific extension which would mimic, even in a limited way, the same feature.
I was expecting the C++ committee to only consider features that have proven themselves on the field, typically through compiler or target specific extensions. Approving this feature for C++20 suggests that the feature should be accessible somewhere. But so far, I've been unable to find it.
Is there a way to experiment with C++ contract programming currently ? even using a set of compiler-specific extensions ?
Programming "by contract" is essentially a means of allowing programmers to verify execution of their methods does not corrupt the state of their data structures and so on.
Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools.
C++20 features are available since GCC 8. "For G++ 9 and later" should be "For G++ 9 and earlier".
GNU C++ Compiler ( g++ ) is a compiler in Linux which is used to compile C++ programs. It compiles both files with extension . c and . cpp as C++ files. The following is the compiler command to compile C++ program.
The July 2019 WG21 meeting in Cologne agreed to remove contracts from the C++20 working draft. See proposal P1823 from Nicolai Josuttis here.
You might want to try this experimental implementation of contracts in Clang.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With