Let's say I have a following function:
int reserve(DmaChannel& channel, const uint8_t request)
{
const auto ret = channel.reserve(request);
if (ret != 0)
return ret;
channel_ = &channel;
return 0;
}
It is clearly visible, that the function can fail (when the channel is busy, but this doesn't matter here).
In the doxygen documentation for this function, can I say that it's post-condition is "channel is reserved", assuming that it is logical that the post-condition holds only if the function completed successfully? Or maybe I should think of post-conditions as something that is true in absolutely every possible return from the function, with success value, with error value or with exception?
Generally a post-condition which is valid only if the function is successful can be easily expressed with proposed C++20 contracts like this:
int reserve(DmaChannel& channel, uint8_t request)
[[ ensures ret : channel.isReserved() == true || ret != 0 ]];
However I'm not sure whether my logic is the same as the generally accepted understanding of post-conditions.