Re: [boost] [type_traits] is_convertible<noncopyable,To> crashes

----- Mensaje original ----- De: John Maddock <john@johnmaddock.co.uk> 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

[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.]
Um, because I overstated the case :-) They can be the same, it just doesn't tell you anything useful: either the result is true (T is copy-constructible) or the code doesn't compile.
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.
No that should work just fine, indeed that was the test case attached to my last message. John.

JOAQUIN LOPEZ MU?Z <joaquin <at> tid.es> writes:
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.
I checked this fix (having fixed some obvious typos in it) out with the test case I posted earlier (in multi_index problem thread) - it doesn't help (sigh). The error is: D:\src\3rd-parties\boost/boost/type_traits/is_convertible.hpp(254): error: no suitable user-defined conversion from "const name_record" to "const base_record" exists BOOST_STATIC_CONSTANT(bool, value = ^ detected during: instantiation of class "boost::detail::is_convertible_basic_impl<From, To> [with From=boost::detail::is_convertible_impl<const name_record, const base_record>::ref_type, To=const base_record]" at line 286 instantiation of class "boost::detail::is_convertible_impl<From, To> [with From=const name_record, To=const base_record]" at line 362 instantiation of class "boost::detail::is_convertible_impl_dispatch<From, To> [with From=const name_record, To=const base_record]" at line 409 instantiation of class "boost::is_convertible<From, To> [with From=const name_record, To=const base_record]" at line 25 of "D:\src\3rd- parties\boost/boost/mpl/aux_/preprocessed/plain/or.hpp" instantiation of class "boost::mpl::aux::or_impl<false, T1, T2, T3, T4> [with T1=boost::is_convertible<const name_record, const base_record>, T2=boost::mpl::false_, T3=boost::mpl::false_, T4=boost::mpl::false_]" at line 50 of "D:\src\3rd-parties\boost/boost/mpl/aux_/preprocessed/plain/or.hpp"
participants (3)
-
Alexei Alexandrov
-
JOAQUIN LOPEZ MU?Z
-
John Maddock