Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++2a contract programming and compilers

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 ?

like image 330
Cyan Avatar asked Dec 11 '18 05:12

Cyan


People also ask

What are contracts programming?

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.

What is clang vs GCC?

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.

Does G ++ 9 support C++20?

C++20 features are available since GCC 8. "For G++ 9 and later" should be "For G++ 9 and earlier".

What is G ++ compiler?

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.


2 Answers

The July 2019 WG21 meeting in Cologne agreed to remove contracts from the C++20 working draft. See proposal P1823 from Nicolai Josuttis here.

like image 114
user2023370 Avatar answered Oct 17 '22 23:10

user2023370


You might want to try this experimental implementation of contracts in Clang.

like image 21
r3mus n0x Avatar answered Oct 17 '22 22:10

r3mus n0x