Stop using assert() in tests

[SVN r33181]
This commit is contained in:
Dave Abrahams
2006-02-28 22:56:33 +00:00
parent 17ca3a4493
commit 80e9edcb29
2 changed files with 10 additions and 9 deletions

View File

@@ -44,7 +44,7 @@
#define BOOST_CAST_HPP #define BOOST_CAST_HPP
# include <boost/config.hpp> # include <boost/config.hpp>
# include <cassert> # include <boost/assert.hpp>
# include <typeinfo> # include <typeinfo>
# include <boost/type.hpp> # include <boost/type.hpp>
# include <boost/limits.hpp> # include <boost/limits.hpp>
@@ -82,17 +82,19 @@ namespace boost
// polymorphic_downcast ----------------------------------------------------// // polymorphic_downcast ----------------------------------------------------//
// assert() checked polymorphic downcast. Crosscasts prohibited. // BOOST_ASSERT() checked polymorphic downcast. Crosscasts prohibited.
// WARNING: Because this cast uses assert(), it violates the One Definition // WARNING: Because this cast uses BOOST_ASSERT(), it violates
// Rule if NDEBUG is inconsistently defined across translation units. // the One Definition Rule if used in multiple translation units
// where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER
// NDEBUG are defined inconsistently.
// Contributed by Dave Abrahams // Contributed by Dave Abrahams
template <class Target, class Source> template <class Target, class Source>
inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET)
{ {
assert( dynamic_cast<Target>(x) == x ); // detect logic error BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
return static_cast<Target>(x); return static_cast<Target>(x);
} }

View File

@@ -4,9 +4,8 @@
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
#include <boost/implicit_cast.hpp> #include <boost/implicit_cast.hpp>
#include <cassert> #include <boost/detail/lightweight_test.hpp>
#include <boost/type.hpp> #include <boost/type.hpp>
using boost::implicit_cast; using boost::implicit_cast;
using boost::type; using boost::type;
@@ -25,9 +24,9 @@ typedef type<foo> foo_type;
int main() int main()
{ {
type<long> x = check_return(boost::implicit_cast<long>(1)); type<long> x = check_return(boost::implicit_cast<long>(1));
assert(boost::implicit_cast<long>(1) == 1L); BOOST_TEST(boost::implicit_cast<long>(1) == 1L);
type<foo> f = check_return(boost::implicit_cast<foo>("hello")); type<foo> f = check_return(boost::implicit_cast<foo>("hello"));
type<long> z = check_return(boost::implicit_cast<long>(foo("hello"))); type<long> z = check_return(boost::implicit_cast<long>(foo("hello")));
return 0; return boost::report_errors();
} }