I've encountered a problem when transitioning from Boost.Test 1.32 to
1.33. New to 1.33 is a set_precision(..) method on the print_log_value
functor (in test_tools.hpp). The problem, as I see it, is the use of
numeric_limits<T>, which exposes the assumption T is a numeric entity at
all. I'm actually surprised it compiles as often as it does, so maybe
my blame is misdirected. Nonetheless, I was able to create the attached
test case to prove my point. I've also included the generated build log
with the really nasty compile time error.
Anm
// Weird Compile problem with Boost.Test 1.33
#include <iostream>
#include
using boost::unit_test::test_suite;
// Class heirarchy and support functions
class Abstract {
virtual void go() = 0; // If Abstract is not pure virtual, everything compiles fine
};
class Concrete : public Abstract {
virtual void go() { }
};
inline bool operator== ( const Abstract& a, const Abstract& b ) {
return &a == &b; // identity
}
template // character type, traits
inline std::basic_ostream& operator<< ( std::basic_ostream& out, const Abstract& a ) {
// Just prints a memory address.
return out << "Abstract@0x" << &a;
}
// Function that forces us to work with the abstract interface
Abstract& generalize( Concrete& c ) {
return c;
}
// Test case & suite
void test_abstract_identity() {
Concrete a, b;
// These work
BOOST_CHECK_EQUAL( a, a ); // works
BOOST_CHECK_EQUAL( a, b ); // fails correctly
// These won't compile with 1.33 & VC++7.1
BOOST_CHECK_EQUAL( generalize(a), a );
Abstract& c = a;
BOOST_CHECK_EQUAL( a, c );
}
test_suite*
init_unit_test_suite( int, char* [] ) {
test_suite* test= BOOST_TEST_SUITE( "Example failure of Boost.Test 1.33.0" );
test->add( BOOST_TEST_CASE( &test_abstract_identity ), 1 );
return test;
}
// EOF