News for hackers. Stuff that matters.
Re:Adding “invariant” clauses to C++ via GCC plugin to enabl... by kokonoko on Sunday January 01, 2023 @06:19PM (#34212188)
Creating a separate gcc plugin for this seems unnecessary if I am not misunderstanding something. Just ensure the invariant function is called at every method, in debug builds maybe. You could of course change the object properties without using a method but then you have bigger problems.
Re:Adding “invariant” clauses to C++ via GCC plugin to enabl... by Volt on Sunday January 01, 2023 @06:55PM (#34212532)
> Just ensure the invariant function is called at every method

You make this sound way easier than I would expect it to be in the general case.

Re:Adding “invariant” clauses to C++ via GCC plugin to enabl... by gavinray on Sunday January 01, 2023 @07:07PM (#34212636)
They're suggesting you write the output of the codegen shown in the image here:

https://gavinray97.github.io/static/images/ghidra-check-inva...

Yeah you totally could, and before writing this plugin it's what I was doing, haha. As there is a human involved, it is very error prone though, and boy is it tedious!

Re:Adding “invariant” clauses to C++ via GCC plugin to enabl... by loeg on Sunday January 01, 2023 @07:03PM (#34212599)
You add something like:

  DCHECK(myInvariants());
to your method bodies. Sure, it makes it possible to forget, but it's not that hard to use.
Re:Adding “invariant” clauses to C++ via GCC plugin to enabl... by int_19h on Monday January 02, 2023 @04:10AM (#34215926)
A big part of DbC is that contracts are part of the public interface, not the implementation. This becomes especially important once you mesh them with Simula-style OOP, as derived classes need a way for overridden methods to widen or narrow the inherited contract.