Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-04-15 12:27:39


----- Mensaje original -----
De: John Maddock <john_at_[hidden]>
Fecha: Viernes, Abril 14, 2006 12:19 pm
Asunto: Re: [boost] [type_traits] is_convertible<noncopyable,To>
crashes

> > In a post from yesterday (see http://tinyurl.com/hzk5w),
> > Alexei Alexandrov found a rather serious problem with
> > is_convertible in at least MSVC 7.1 and Intel 9.0, namely
> > that is_convertible<From,To> fails to compile when
> >> From is non-copyable, emitting an error message like this:
>
> Wait a second, I've just looked at the original error messages,
> and the test
> case is very specific, it fails for:
>
> is_convertible<const noncopyable, const noncopyable>
>
> That is known not to work, *and will never work*, there is no way
> we can
> define a trait that detects whether a type is copy-constructable
> or not. In
> other words the From and To parameters must be different types.

OK, I've carefully read the standard and I understand now that
convertiblity between X and itself is tantamount to
X being copy constructible (my naive understanding was that
X is always convertible to X by definition.) For the purposes
of my code, I can then replace the calls of the form

  is_convertible<X,Y>

with calls to

  template<typename From,typename From>
  struct is_same_or_convertible:
    mpl::or_<
      is_same<From,To>
      is_convertible<From,To>
>
  {};

and thus avoid executing is_convertible<From,To> whith
From=To.

[On a side note, if From must be different to To, why is
this is not stated in the docs? There's even a case
whith From=To in is_convertible_test.cpp:

  BOOST_CHECK_INTEGRAL_CONSTANT(
    (::tt::is_convertible<Base,Base>::value), true);

end of side note.]

So, if we exclude the case where From=To, is is_convertible
supposed to work for the call pattern

  is_convertible<const X,Y>

where X is non-copyable and Y!=X? From Alexei tests seems like
this could be failing too, and does not fall under the
forbidden From=To case. I don't have any compiler handy right
now, will try to check out by myself in a few days.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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