[Boost.Test] BOOST_CHECK_EQUAL and std::type_info
I can't seem to get BOOST_CHECK_EQUAL with std::type_info instances to compile with g++, version (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33) Here's a simple test case: ------------------ #include <iostream> #include <typeinfo> #define BOOST_TEST_MAIN #include <boost/test/included/unit_test.hpp> std::ostream & operator<<(std::ostream &out, const std::type_info &info) { return out << info.name(); } BOOST_AUTO_TEST_CASE(Foo) { std::cout << "Typeid of int is " << typeid(int) << "\n"; BOOST_CHECK_EQUAL(typeid(int), typeid(float)); } ------------------ g++ complains that there isn't an operator<< for type_info in the BOOST_CHECK_EQUAL, even though it is used just fine on the previous line. Output: g++ -o ti ti.cpp /usr/include/boost/test/test_tools.hpp: In member function ‘void boost::test_tools::tt_detail::print_log_value<T>::operator()(std::ostream&, const T&) [with T = std::type_info]’: /usr/include/boost/test/test_tools.hpp:404: instantiated from ‘std::ostream& boost::test_tools::tt_detail::operator<<(std::ostream&, const boost::test_tools::tt_detail::print_helper_t<T>&) [with T = std::type_info]’ /usr/include/boost/test/utils/wrap_stringstream.hpp:66: instantiated from ‘boost::basic_wrap_stringstream<CharT>& boost::operator<<(boost::basic_wrap_stringstream<CharT>&, const T&) [with CharT = char, T = boost::test_tools::tt_detail::print_helper_t<std::type_info>]’ /usr/include/boost/test/test_tools.hpp:460: instantiated from ‘void boost::test_tools::tt_detail::check_frwd(Pred, boost::wrap_stringstream&, 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*) [with Pred = boost::test_tools::tt_detail::equal_impl_frwd, Arg0 = std::type_info, Arg1 = std::type_info]’ ti.cpp:14: instantiated from here /usr/include/boost/test/test_tools.hpp:298: error: no match for ‘operator<<’ in ‘ostr << t’ <List of candidates removed, but type_info isn't one of them> Anyone know why this is? -- Paul S. Strauss pss@acm.org
AMDG Paul S. Strauss wrote:
I can't seem to get BOOST_CHECK_EQUAL with std::type_info instances to compile with g++, version (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33) <snip> g++ complains that there isn't an operator<< for type_info in the BOOST_CHECK_EQUAL, even though it is used just fine on the previous line.
Your operator<< cannot be found by ADL. There are a couple of ways around this. * you can put operator<< in namespace std. (Technically illegal) * you can declare it before including any Boost.Test headers. In Christ, Steven Watanabe
On Tue, 10 Jun 2008 06:47:59 -0700, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Paul S. Strauss wrote:
I can't seem to get BOOST_CHECK_EQUAL with std::type_info instances to compile with g++, version (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33) <snip> g++ complains that there isn't an operator<< for type_info in the BOOST_CHECK_EQUAL, even though it is used just fine on the previous line.
Your operator<< cannot be found by ADL. There are a couple of ways around this. * you can put operator<< in namespace std. (Technically illegal) * you can declare it before including any Boost.Test headers.
Thanks for the advice. FYI: Adding it to namespace std worked, but yuck. Moving it before the Test headers did not. -- Paul S. Strauss pss@acm.org
Paul S. Strauss <pss <at> acm.org> writes:
Your operator<< cannot be found by ADL. There are a couple of ways around this. * you can put operator<< in namespace std. (Technically illegal) * you can declare it before including any Boost.Test headers.
Thanks for the advice. FYI: Adding it to namespace std worked, but yuck. Moving it before the Test headers did not.
Unfortunately there is no way around it. The only other thing is to disable type_info output completely Gennadiy
participants (3)
-
Gennadiy Rozental
-
Paul S. Strauss
-
Steven Watanabe