I'm using SAL to make sure that all code paths that create an object X
should call X::work()
before destroying it.
#include <sal.h>
class X {
bool worked = false;
public:
_Post_satisfies_(!worked)
X() : worked(false) {}
_Post_satisfies_(worked)
void work() {
worked = true;
}
_Pre_satisfies_(worked)
~X() {
}
};
int main() {
X x;
X y; // Does not call work() but still passes the test anyway
x.work();
}
When I remove x.work()
, then there goes an error as intended:
warning C28020: The expression 'this->worked' is not true at this call.
But soon as I add work()
for one object x
, the other one y
also seems to pass the test. Is there some problem in my annotation?