Boost logo

Boost Users :

Subject: [Boost-users] [test] BOOST_*_EQUAL against constants
From: Alexander Lamaison (awl03_at_[hidden])
Date: 2009-07-18 20:39:27


A common scenario in my tests is comparing some unsigned value against a
constant (most often 0 or 1):

BOOST_REQUIRE_EQUAL(cbRead, 0);

However, this generates a warning on MSVC complaining about a
signed/unsigned mismatch (full message included at end):

    c:\boost\test\test_tools.hpp(536) : warning C4389: '==' :
    signed/unsigned mismatch
        c:\boost\test\test_tools.hpp(560) : see reference to function
    template instantiation 'boost::test_tools::predicate_result
    boost::test_tools::tt_detail::equal_impl(const Left &,const
    Right &)' being compiled
        with
        [
            Left=ULONG,
            Right=int
        ]

I can obviously cast the 0 constant to an unsigned it but it's getting
tedious doing this every time. Surely there must be a better way? Is
there some way to force the comparison to interpret constants as being of
whatever type they are being compared to?

Thanks.

Alex

c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(536) : warning
C4389: '==' : signed/unsigned mismatch
        c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(560) :
see reference to function template instantiation
'boost::test_tools::predicate_result
boost::test_tools::tt_detail::equal_impl(const Left &,const Right &)' being
compiled
        with
        [
            Left=ULONG,
            Right=int
        ]
        c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(575) :
see reference to function template instantiation
'boost::test_tools::predicate_result
boost::test_tools::tt_detail::equal_impl_frwd::call_impl(const Left &,const
Right &,boost::mpl::false_) const' being compiled
        with
        [
            Left=ULONG,
            Right=int
        ]
        c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(523) :
see reference to function template instantiation
'boost::test_tools::predicate_result
boost::test_tools::tt_detail::equal_impl_frwd::operator ()(const Left
&,const Right &) const' being compiled
        with
        [
            Arg0=ULONG,
            Arg1=int,
            Left=ULONG,
            Right=int
        ]
        c:\users\awl03\documents\visual studio
2005\projects\swish_feature_write\test\provider\stream_write_test.cpp(202)
: see reference to function template instantiation 'bool
boost::test_tools::tt_detail::check_frwd(Pred,const
boost::unit_test::lazy_ostream
&,boost::test_tools::const_string,size_t,boost::test_tools::tt_detail::tool_level,boost::test_tools::tt_detail::check_type,const
Arg0 &,const char *,const Arg1 &,const char *)' being compiled
        with
        [
            Pred=boost::test_tools::tt_detail::equal_impl_frwd,
            Arg0=ULONG,
            Arg1=int
        ]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net