Make BOOST_TEST_EQ/NE work with nullptr

This commit is contained in:
Peter Dimov
2017-05-29 21:15:49 +03:00
parent f76116405d
commit 637b2ffaff
3 changed files with 35 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include <boost/core/no_exceptions_support.hpp>
#include <iostream>
#include <cstring>
#include <cstddef>
// IDE's like Visual Studio perform better if output goes to std::cout or
// some other stream, so allow user to configure output stream:
@ -113,6 +114,10 @@ inline const void* test_output_impl(unsigned char* v) { return v; }
inline const void* test_output_impl(signed char* v) { return v; }
template<class T> inline const void* test_output_impl(T volatile* v) { return const_cast<T*>(v); }
#if !defined( BOOST_NO_CXX11_NULLPTR )
inline const void* test_output_impl(std::nullptr_t v) { return v; }
#endif
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, T const & t, U const & u )
{

View File

@ -71,6 +71,8 @@ run lightweight_test_all_with_test.cpp ;
run lightweight_test_all_with_fail.cpp ;
run lightweight_test_lt_le_test.cpp ;
run lightweight_test_eq_nullptr.cpp ;
run-fail lightweight_test_fail.cpp ;
run-fail lightweight_test_fail2.cpp ;
run-fail lightweight_test_fail3.cpp ;

View File

@ -0,0 +1,28 @@
//
// Test BOOST_TEST_EQ( p, nullptr )
//
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
#if !defined( BOOST_NO_CXX11_NULLPTR )
int x = 0;
int* p1 = 0;
int* p2 = &x;
BOOST_TEST_EQ( p1, nullptr );
BOOST_TEST_NE( p2, nullptr );
#endif
return boost::report_errors();
}