Adding “invariant” clauses to C++ via GCC plugin to enable Design-by-Contract

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • icontract-hypothesis

    Combine contracts and automatic testing.

  • https://icontract.readthedocs.io/en/latest/usage.html#invari...

    For unit testing, there's icontract-hypothesis; with the Preconditions and Postconditions delineated by e.g. decorators, it's possible to generate many of the fuzz tests from the additional Design by Contract structure of the source.

    From https://github.com/mristin/icontract-hypothesis :

    > icontract-hypothesis combines design-by-contract with automatic testing.

    > It is an integration between icontract library for design-by-contract and Hypothesis library for property-based testing.

    > The result is a powerful combination that allows you to automatically test your code. Instead of writing manually the Hypothesis search strategies for a function, icontract-hypothesis infers them based on the function’s [sic] precondition

  • clang-contracts

    Experimental support for contracts programming in clang++

  • I'm the author, and even I think so. I'm more of an LLVM fan myself (though I can't not mention David Malcom's work on the GCC Static Analyzer).

    Ideally it wouldn't be a plugin at all, it'd be a language feature. We got Contracts and left out the most useful contract of them all, the stateful invariant!

    Originally, I started it as a Clang plugin, thinking that I could also implement support for the Contracts "[[pre]]" and "[[post]]" specification on top (or at least some minimal implementation of it.

    The difficulty seemed a lot greater to support pre/post attributes with expressions inside of them than [[invariant]] marker attributes.

    If people would like to use this from Clang, even without support for regular Contracts, I will publish a compatible Clang plugin.

    I think at some point there was support for Contracts in Clang, maybe longer term I'll try to get them working again? (I've no experience here)

    https://github.com/arcosuc3m/clang-contracts

    This fellow wrote a whole ~200 page thesis on this just as recently as 2018, such a shame for it to go to waste =/

    https://e-archivo.uc3m.es/bitstream/handle/10016/29231/TFG_J...

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • MIRAI

    Rust mid-level IR Abstract Interpreter

  • Do you use the Cargo "contracts" for Design-by-Contract style invariants that plugs into Facebook's MIRAI prover thing?

    I always thought it this was super neat:

    https://crates.io/crates/contracts

    https://github.com/facebookexperimental/MIRAI/blob/main/exam...

      [dependencies]

  • gcc-invariant-plugin

  • The inspiration was taken directly from D, I credit as much in the README =)

    https://github.com/GavinRay97/gcc-invariant-plugin#gcc-desig...

      > Inspired wholly by the D Programming Language's invariant feature.

  • CMake

    Mirror of CMake upstream repository

  • Note that `assert`s are disabled if you define the macro `NDEBUG`, e.g. https://godbolt.org/z/hMWo8KM7q

    CMake adds these flags to release builds: https://github.com/Kitware/CMake/blob/e1eacbe2c522a8bf9a82af...

    Would be nice to have a non-macro solution for controlling behavior at configure time, but the `NDEBUG` macro is basically already your `DEBUG` constexpr.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts