Boost logo

Boost :

Subject: Re: [boost] Is there interest in unit testing both passing and failing BOOST_MPL_ASSERTs?
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-09-14 04:21:59


>
> Okay, let me see if I understand now: You want a way for the compiler to
> ignore the static assertions and actually *try* to compile to errant code
> to
> ensure that you do, in fact, get a compiler error (which would normally be
> caught early on by the static assertion). Is that right?
>
> - Jeff
>
> Yes. That is exactly it. :)

One simple practical example I can give, is that in a library of mine, I
have overloaded the free function operator+ for certain types of arguments.
 I then include the following in the function body:following:

BOOST_MPL_ASSERT(sizof(T) == 0);

This blocks the user from attempting to add these pairs of types together
and it works nicely. But I need a way to write a run-time unit test which
will demonstrate that this code will fail to compile, when instantiated by
the user of the library. When instantiated by the unit-test framework, the
code instead throws an exception.

Regards,

Ben Robinson, Ph.D.


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