is_convertible_test compile warnings with gcc-3.4.4 (cygwin)
When compiling the is_convertible test case, I'm getting the following
compile warnings:
------------------------------------
/usr/local/src/boost/boost_1_32_0/boost/type_traits/is_convertible.hpp:
In instantiation of `boost::detail::is_convertible_basic_impl ::value), true);
BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible I think this is caused by trying to call the convertible_from<char>
constructor (which takes a char) with a float& argument, which forces an
implicit conversion from float-to-char BEFORE the "user defined
conversion" of char-to-convertible_from<char>.
gcc issues this warning when doing a float(or double) conversion to an
integral type during template instantiation/overload resolution -- but
does not warn if "merely" truncating from a wider integral
representation down to char. I can see why gcc might warn in each case
-- but
(1) warning in one case but not the other seems counterintuitive
(2) in any case, I'd like to suppress or avoid both sorts of warnings
Does anybody have an idea how to avoid these warnings with gcc -- or can
verify that they occur with other versions of gcc (like 4.0?).
It's also possible that I'm confused :-) and gcc's behavior is correct;
but that means that boost::is_convertible is deliberately violating some
rule or other and causing these warnings -- and I doubt that is the case.
I've pasted the relevant parts of the is_convertible code below; the
lines which I *think* are the offending ones are marked with '@@'.
template <typename T> struct checker
{
static boost::type_traits::no_type _m_check(any_conversion ...);
@@ static boost::type_traits::yes_type _m_check(T, int);
};
template
I think this is caused by trying to call the convertible_from<char> constructor (which takes a char) with a float& argument, which forces an implicit conversion from float-to-char BEFORE the "user defined conversion" of char-to-convertible_from<char>.
Right: we are quite deliberately testing conversions that go via both a builtin conversion and a user defined constructor.
gcc issues this warning when doing a float(or double) conversion to an integral type during template instantiation/overload resolution -- but does not warn if "merely" truncating from a wider integral representation down to char. I can see why gcc might warn in each case -- but (1) warning in one case but not the other seems counterintuitive (2) in any case, I'd like to suppress or avoid both sorts of warnings
Does anybody have an idea how to avoid these warnings with gcc -- or can verify that they occur with other versions of gcc (like 4.0?).
It's also possible that I'm confused :-) and gcc's behavior is correct; but that means that boost::is_convertible is deliberately violating some rule or other and causing these warnings -- and I doubt that is the case.
Compilers are permitted to warn over anything they want (and often do so!), so gcc is completely within it's rights to issue a warning here. For other compilers we've gone to some lengths to disable warnings like this within is_convertible using #pragmas, unfortunately gcc doesn't have any options that help here. We also use some "special case code" to ensure that conversions from a [cv-qualified reference to] arithmetic or enum type to another arithmetic type doesn't result in warnings on gcc. Unfortunately we can't extend that to user defined types :-( Sorry this isn't more helpful, John.
participants (2)
-
Charles Wilson
-
John Maddock