logoalt Hacker News

Maxatar • today at 4:14 AM • 0 replies • view on HN

The issue is more specific, namely that in C++ most code uses header files, and contracts must be specified in the header file, so that it creates the possibility where the same function can be compiled with and without contracts on and off.

This is known as an ODR-violation, where the same function is compiled with two or more definitions, and there's no rule in C++ to pick which definition should be used. One way to resolve this would be to introduce a rule to pick between these definitions (always pick the function with the contract check disabled, or pick with it enabled), but no one could agree on which rule to use and even if they did it would not work for shared libraries.

There is no doubt that once contracts get standardized, compilers will offer a flag to disable them categorically, ie. disable all of them across all definitions. That won't be an issue because then all definitions will be consistent. But the original proposal allowed flipping contracts on or off per "source-file" with the hopes that developer discipline would ensure that people were consistent about its usage.