Apply patch for [CVE-2012-2677][boost] ordered_malloc() overflow
[external/boost.git] / libs / smart_ptr / test / pointer_to_other_test.cpp
1 //
2 //  pointer_to_other_test.cpp - a test for boost/pointer_to_other.hpp
3 //
4 //  Copyright (c) 2005 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #include <boost/pointer_to_other.hpp>
12
13 #include <boost/shared_ptr.hpp>
14 #include <boost/shared_array.hpp>
15 #include <boost/scoped_ptr.hpp>
16 #include <boost/scoped_array.hpp>
17 #include <boost/intrusive_ptr.hpp>
18
19 #include <memory>
20
21 template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 )
22 {
23     pt = pu;
24 }
25
26 struct X;
27 struct Y;
28
29 int main()
30 {
31     // shared_ptr
32
33     assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, Y >::type, boost::shared_ptr<Y> >();
34     assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, void >::type, boost::shared_ptr<void> >();
35     assert_same_type< boost::pointer_to_other< boost::shared_ptr<void>, Y >::type, boost::shared_ptr<Y> >();
36
37     // shared_array
38
39     assert_same_type< boost::pointer_to_other< boost::shared_array<X>, Y >::type, boost::shared_array<Y> >();
40     assert_same_type< boost::pointer_to_other< boost::shared_array<X>, void >::type, boost::shared_array<void> >();
41     assert_same_type< boost::pointer_to_other< boost::shared_array<void>, Y >::type, boost::shared_array<Y> >();
42
43     // scoped_ptr
44
45     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, Y >::type, boost::scoped_ptr<Y> >();
46     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, void >::type, boost::scoped_ptr<void> >();
47     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<void>, Y >::type, boost::scoped_ptr<Y> >();
48
49     // scoped_array
50
51     assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, Y >::type, boost::scoped_array<Y> >();
52     assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, void >::type, boost::scoped_array<void> >();
53     assert_same_type< boost::pointer_to_other< boost::scoped_array<void>, Y >::type, boost::scoped_array<Y> >();
54
55     // intrusive_ptr
56
57     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, Y >::type, boost::intrusive_ptr<Y> >();
58     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >();
59     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >();
60
61     // auto_ptr
62
63     assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >();
64     assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >();
65     assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >();
66
67     // raw pointer
68    
69     assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >();
70     assert_same_type< boost::pointer_to_other< X *, void >::type, void * >();
71     assert_same_type< boost::pointer_to_other< void *, Y >::type, Y * >();
72
73     return 0;
74 }