Boost logo

Boost :

Subject: [boost] [contract] relaxing preconditions in subcontracting
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2012-06-12 07:43:50


Hi Lorenzo,
I am trying to understand how the feature of relaxing preconditions in
overridden functions work or should work. Given the situation, where I call
an overridden function via base class reference:

*struct Base
{
  virtual void fun(bool b) = 0 precondition{ b == true };
};

struct Deriv : Base
{
  void fun(bool b) override precondition{ true };
};

void test( Base & b )
{
  b.fun(false); **// broken contract or not?**
}*

Should this be treated as a broken contract or not? My reading of the
documentation says that contract is not broken (because the
"logic-or<http://contractpp.svn.sourceforge.net/viewvc/contractpp/releases/contractpp_0_4_0/doc/html/contract__/contract_programming_overview.html#logic_or_anchor>"
logic applies), but I feel that whoever implemented function *test *made a
mistake: he cannot assume what type will be implementing "interface" *Base*,
so he cannot rely on the precondition being relaxed (even if he gets away
with it this time).

Regards,
&rzej


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk