Boost logo

Boost :

Subject: Re: [boost] [TypeIndex] Peer review period for library acceptance begins, ending Thurs 21st Nov
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-11-14 01:43:44


On Thu, Nov 14, 2013 at 9:26 AM, Antony Polukhin <antoshkka_at_[hidden]> wrote:
> 2013/11/14 Steven Watanabe <watanabesj_at_[hidden]>
>
>> AMDG
>>
>> On 11/12/2013 11:34 AM, Niall Douglas wrote:
>> > Boost community feedback is requested for the formal peer review of
>> > the TypeIndex library by Antony Polukhin. Feedback requested
>> > includes:
>> >
>> > 1. Should this library be accepted into Boost?
>> >
>>
>> No. This library should not be accepted into Boost
>> in its current form.
>>
>> type_info.hpp:139:
>> return static_cast<const boost::type_info&>(typeid(type));
>>
>> This is undefined behavior, and there is no
>> way to make it correct.
>>
>
> This is a necessary evil and it is harmless:
> * all the methods of std::type_info (except destructor) are non virtual, so
> for example calls to name() will call boost::type_info::name()
> * it is *undefined* which destructor (std::type_info or boost::type_info)
> will be called *but*:
> * boost::type_info contains no members, it's size must be equal to the
> size of std::type_info, so no harm if boost::type_info destructor won't be
> called
> * destructor of std::type_info will be called anyway
>
> I can add assert to tests to ensure that sizeof(std::type_info) ==
> sizeof(boost::type_info).

I think the undefined behavior can be removed with the following trick:

1. boost::type_info should not derive from std::type_info (it would
have no base classes or data members). Its destructor should be
deleted, as well as its constructors and assignment.
2. The above cast should be replaced with reinterpret_cast:

  return reinterpret_cast<const boost::type_info&>(typeid(type));

3. All methods of boost::type_info should perform the reverse
reinterpret_cast of *this before accessing std::type_info.

The standard warrants that such two-way casting would yield the
original reference to std::type_info.

However, this turns out to be quite a lot of hackery and makes me
wonder if boost::type_info is needed at all. Why not just have
boost::type_index that will work directly with std::type_info?


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