forked from boostorg/smart_ptr
Add one more dynamic_cast test, fold back _test3 into test2.
This commit is contained in:
@ -188,7 +188,6 @@ import testing ;
|
|||||||
[ run sp_hash_test3.cpp ]
|
[ run sp_hash_test3.cpp ]
|
||||||
|
|
||||||
[ run pointer_cast_test2.cpp ]
|
[ run pointer_cast_test2.cpp ]
|
||||||
[ run pointer_cast_test3.cpp ]
|
|
||||||
|
|
||||||
[ compile-fail pointer_cast_st_fail.cpp ]
|
[ compile-fail pointer_cast_st_fail.cpp ]
|
||||||
[ compile-fail pointer_cast_st_fail2.cpp ]
|
[ compile-fail pointer_cast_st_fail2.cpp ]
|
||||||
|
@ -119,7 +119,21 @@ static void test_const_cast()
|
|||||||
BOOST_TEST_EQ( p2.get(), q1 );
|
BOOST_TEST_EQ( p2.get(), q1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined( BOOST_MSVC ) || BOOST_MSVC >= 1900
|
||||||
|
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<int const[]> p1( new int[ 1 ] );
|
||||||
|
int const * q1 = p1.get();
|
||||||
|
|
||||||
|
std::unique_ptr<int[]> p2 = boost::const_pointer_cast<int[]>( std::move( p1 ) );
|
||||||
|
|
||||||
|
BOOST_TEST( p1.get() == 0 );
|
||||||
|
BOOST_TEST_EQ( p2.get(), q1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
std::unique_ptr<int[]> p1( new int[ 1 ] );
|
||||||
int * q1 = p1.get();
|
int * q1 = p1.get();
|
||||||
|
|
||||||
@ -151,6 +165,16 @@ static void test_dynamic_cast()
|
|||||||
BOOST_TEST( p1.get() == 0 );
|
BOOST_TEST( p1.get() == 0 );
|
||||||
BOOST_TEST_EQ( p2.get(), q1 );
|
BOOST_TEST_EQ( p2.get(), q1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::unique_ptr<B> p1( new B );
|
||||||
|
B * q1 = p1.get();
|
||||||
|
|
||||||
|
std::unique_ptr<D> p2 = boost::dynamic_pointer_cast<D>( std::move( p1 ) );
|
||||||
|
|
||||||
|
BOOST_TEST( p2.get() == 0 );
|
||||||
|
BOOST_TEST_EQ( p1.get(), q1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_reinterpret_cast()
|
static void test_reinterpret_cast()
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
//
|
|
||||||
// pointer_cast_test3.cpp - a test for unique_ptr casts
|
|
||||||
//
|
|
||||||
// Copyright 2016 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>
|
|
||||||
|
|
||||||
#if defined( BOOST_NO_CXX11_SMART_PTR )
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <boost/pointer_cast.hpp>
|
|
||||||
#include <boost/core/lightweight_test.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
// This test fails on msvc-10.0, 11.0, 12.0 because
|
|
||||||
// their unique_ptr implementation can't compile the
|
|
||||||
// initialization of p1
|
|
||||||
|
|
||||||
static void test_const_cast()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
std::unique_ptr<int const[]> p1( new int[ 1 ] );
|
|
||||||
int const * q1 = p1.get();
|
|
||||||
|
|
||||||
std::unique_ptr<int[]> p2 = boost::const_pointer_cast<int[]>( std::move( p1 ) );
|
|
||||||
|
|
||||||
BOOST_TEST( p1.get() == 0 );
|
|
||||||
BOOST_TEST_EQ( p2.get(), q1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
test_const_cast();
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Reference in New Issue
Block a user