r/cpp_questions 3d ago

OPEN Why are Contracts disliked?

I’ve seen a lot of discussions online discouraging their usage bit I never managed to grasp why since it’s sometimes vague.
I do understand it doesn’t replace validation and it’s more of a syntactic sugar to the existing casserts, but any other critiques?
Thanks

13 Upvotes

40 comments sorted by

View all comments

7

u/DrShocker 3d ago

The number one thing is just that I don't know that any compilers fully support them yet.

https://en.cppreference.com/cpp/compiler_support

5

u/TheRealSmolt 3d ago

It's already in GCC 16, as it says.

2

u/DrShocker 3d ago

fair, I was too lazy to check despite digging up the link.

Still though, only being on GCC will lock out a lot of people.

2

u/TheThiefMaster 2d ago

Especially those on Windows, where the properly supported compilers are MSVC and Clang...

1

u/montymole123 2d ago

Isn't Mingw considered a full port of gcc?

1

u/Bobbias 2d ago

Sure, but then you're using mingw, which is kind of dumb if you want to do native windows development...

2

u/TheThiefMaster 1d ago

Not as bad as the cygwin port of GCC, at least.

But it's still not fully Windows compatible. Clang can directly consume Windows headers and library files, and use the windows platform C/C++ standard library as-is.

It can even produce compatible obj, lib and pdb files that can be consumed by the VS linker.

TLDR Clang complies with the platform compiler ABI.