Boost logo

Boost :

Subject: Re: [boost] [contract] toward N3351 concepts
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-09-26 17:20:41

On Wed, Sep 26, 2012 at 12:00 PM, Lorenzo Caminiti
<lorcaminiti_at_[hidden]> wrote:
> However, N3351 says that axioms should not be checked by the compiler...
> ``Axioms express the semantics of a concept’s required syntax; they
> are assumed to be true and
> must not be checked by the compiler beyond conformance to the C++
> syntax. Any additional
> checking is beyond the scope of the compiler’s translation
> requirements. The compiler must not
> generate code that evaluates axioms as preconditions, either. This
> could lead to program errors
> if the evaluated assertions have side effects. For example, asserting
> that distance(first, last) > 1
> when the type of those iterators is istream_iterator will consume the
> first element of the range,
> causing the assertion to pass, but the algorithm to have undefined behavior.''

For now, I find this argument for not generating preconditions from
axioms weak. How about you can only use constant expressions within
axioms because axioms (as contracts and specifically preconditions)
are not supposed to alter the program's stats? Then I can
automatically generate preconditions from axioms and check them at
run-time--why would this be a bad idea? Then you need to implement a
constant-correct version of distance() in order to program the axiom
but that's a good thing IMO... (it reflects the fact that axioms
should not alter the program's state).

In any case, I wanted to start a bit of a discussion about this topic
in Boost. At the moment I'm still learning N3351 so too early for any
design decision but I thing two things can potentially be done with

1. Check they syntactically compile.
2. Automatically generate preconditions form them that are checked at run-time.
(Any more??)

I'm keeping an open mind for now and considering both options.


Boost list run by bdawes at, gregod at, cpdaniel at, john at