Boost logo

Boost :

Subject: Re: [boost] [type_erasure]bug:any(, binding<Concept>) can store wrong type
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-08-13 12:49:38


On 08/13/12 11:16, Steven Watanabe wrote:
> AMDG
>
> On 08/13/2012 09:06 AM, Larry Evans wrote:
>> The attached runs OK without any compile or runtime errors.
>> It seems to create a type_uns<1> from a type_uns<0> although
>> there's no type_uns<1> CTOR for that.
>>
>> This sounds like another instance of the bug reported here:
>>
>> http://article.gmane.org/gmane.comp.lib.boost.devel/233101
>>
>> Is it?
>>
>
> It's similar, but this is really undefined behavior,

And it's undefined behavior because it violates the Requires clause:

   the type stored in other must match the type expected by binding.

from:

http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/doc/html/boost/type_erasure/any.html#id2370230-bb

The correspondence between the example code and the doc are:

  doc -> example code
  ----- --- ------------
  other -> src_a
  binding -> dst_binding
  type stored in other -> src_concrete_t
  type expected by binding -> dst_concrete_t

And obviously, src_concrete_t does not match dst_concrete_t,
thus violating the Requires clause.

Sorry, I should have read the Requires clause closer.

> since there's no way to detect the problem at compile
> time. It's also not necessarily possible to add an
> assertion.

I guess one just has to be careful using this CTOR.

Thanks.

-Larry


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